├── .gitignore
├── MSBuild.psm1
├── NuGetMSBuild.psm1
├── NuGetPowerTools.nuspec
├── NuGetPowerTools.psd1
├── NuGetPowerTools.psm1
├── README.md
├── VS.psm1
└── init.ps1
/.gitignore:
--------------------------------------------------------------------------------
1 | *.nupkg
--------------------------------------------------------------------------------
/MSBuild.psm1:
--------------------------------------------------------------------------------
1 | function Resolve-ProjectName {
2 | param(
3 | [parameter(ValueFromPipelineByPropertyName = $true)]
4 | [string[]]$ProjectName
5 | )
6 |
7 | if($ProjectName) {
8 | $projects = Get-Project $ProjectName
9 | }
10 | else {
11 | # All projects by default
12 | $projects = Get-Project
13 | }
14 |
15 | $projects
16 | }
17 |
18 | function Get-MSBuildProject {
19 | param(
20 | [parameter(ValueFromPipelineByPropertyName = $true)]
21 | [string[]]$ProjectName
22 | )
23 | Process {
24 | (Resolve-ProjectName $ProjectName) | % {
25 | $path = $_.FullName
26 | @([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($path))[0]
27 | }
28 | }
29 | }
30 |
31 | function Add-Import {
32 | param(
33 | [parameter(Position = 0, Mandatory = $true)]
34 | [string]$Path,
35 | [parameter(Position = 1, ValueFromPipelineByPropertyName = $true)]
36 | [string[]]$ProjectName
37 | )
38 | Process {
39 | (Resolve-ProjectName $ProjectName) | %{
40 | $buildProject = $_ | Get-MSBuildProject
41 | $buildProject.Xml.AddImport($Path)
42 | $_.Save()
43 | }
44 | }
45 | }
46 |
47 | function Set-MSBuildProperty {
48 | param(
49 | [parameter(Position = 0, Mandatory = $true)]
50 | $PropertyName,
51 | [parameter(Position = 1, Mandatory = $true)]
52 | $PropertyValue,
53 | [parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
54 | [string[]]$ProjectName
55 | )
56 | Process {
57 | (Resolve-ProjectName $ProjectName) | %{
58 | $buildProject = $_ | Get-MSBuildProject
59 | $buildProject.SetProperty($PropertyName, $PropertyValue) | Out-Null
60 | $_.Save()
61 | }
62 | }
63 | }
64 |
65 | function Get-MSBuildProperty {
66 | param(
67 | [parameter(Position = 0, Mandatory = $true)]
68 | $PropertyName,
69 | [parameter(Position = 2, ValueFromPipelineByPropertyName = $true)]
70 | [string]$ProjectName
71 | )
72 |
73 | $buildProject = Get-MSBuildProject $ProjectName
74 | $buildProject.GetProperty($PropertyName)
75 | }
76 |
77 | function Add-SolutionDirProperty {
78 | param(
79 | [parameter(ValueFromPipelineByPropertyName = $true)]
80 | [string[]]$ProjectName
81 | )
82 |
83 | (Resolve-ProjectName $ProjectName) | %{
84 | $buildProject = $_ | Get-MSBuildProject
85 |
86 | if(!($buildProject.Xml.Properties | ?{ $_.Name -eq 'SolutionDir' })) {
87 | # Get the relative path to the solution
88 | $relativeSolutionPath = [NuGet.PathUtility]::GetRelativePath($_.FullName, $dte.Solution.Properties.Item("Path").Value)
89 | $relativeSolutionPath = [IO.Path]::GetDirectoryName($relativeSolutionPath)
90 | $relativeSolutionPath = [NuGet.PathUtility]::EnsureTrailingSlash($relativeSolutionPath)
91 |
92 | $solutionDirProperty = $buildProject.Xml.AddProperty("SolutionDir", $relativeSolutionPath)
93 | $solutionDirProperty.Condition = '$(SolutionDir) == '''' Or $(SolutionDir) == ''*Undefined*'''
94 | $_.Save()
95 | }
96 | }
97 | }
98 |
99 |
100 | 'Set-MSBuildProperty', 'Add-SolutionDirProperty', 'Add-Import','Add-SolutionDirProperty' | %{
101 | Register-TabExpansion $_ @{
102 | ProjectName = { Get-Project -All | Select -ExpandProperty Name }
103 | }
104 | }
105 |
106 | Register-TabExpansion 'Get-MSBuildProperty' @{
107 | ProjectName = { Get-Project -All | Select -ExpandProperty Name }
108 | PropertyName = {param($context)
109 | if($context.ProjectName) {
110 | $buildProject = Get-MSBuildProject $context.ProjectName
111 | }
112 |
113 | if(!$buildProject) {
114 | $buildProject = Get-MSBuildProject
115 | }
116 |
117 | $buildProject.Xml.Properties | Sort Name | Select -ExpandProperty Name -Unique
118 | }
119 | }
120 |
121 | Export-ModuleMember Get-MSBuildProject, Add-SolutionDirProperty, Add-Import, Get-MSBuildProperty, Set-MSBuildProperty
--------------------------------------------------------------------------------
/NuGetMSBuild.psm1:
--------------------------------------------------------------------------------
1 | function Resolve-ProjectName {
2 | param(
3 | [parameter(ValueFromPipelineByPropertyName = $true)]
4 | [string[]]$ProjectName
5 | )
6 |
7 | if($ProjectName) {
8 | $projects = Get-Project $ProjectName
9 | }
10 | else {
11 | # All projects by default
12 | $projects = Get-Project -All
13 | }
14 |
15 | $projects
16 | }
17 |
18 | function Get-InstallPath {
19 | param(
20 | $package
21 | )
22 | # Get the repository path
23 | $componentModel = Get-VSComponentModel
24 | $repositorySettings = $componentModel.GetService([NuGet.VisualStudio.IRepositorySettings])
25 | $pathResolver = New-Object NuGet.DefaultPackagePathResolver($repositorySettings.RepositoryPath)
26 | $pathResolver.GetInstallPath($package)
27 | }
28 |
29 | function Ensure-NuGetBuild {
30 | # Install the nuget command line if it doesn't exist
31 | $solutionDir = Get-SolutionDir
32 | $nugetToolsPath = (Join-Path $solutionDir .nuget)
33 |
34 | if(!(Test-Path $nugetToolsPath) -or !(Get-ChildItem $nugetToolsPath)) {
35 | Install-Package NuGet.Build -Source 'https://go.microsoft.com/fwlink/?LinkID=206669'
36 |
37 | $nugetBuildPackage = @(Get-Package NuGet.Build)[0]
38 | $nugetExePackage = @(Get-Package NuGet.CommandLine)[0]
39 |
40 | if(!$nugetBuildPackage -and !$nugetExePackage) {
41 | return $false
42 | }
43 |
44 | # Get the package path
45 | $nugetBuildPath = Get-InstallPath $nugetBuildPackage
46 | $nugetExePath = Get-InstallPath $nugetExePackage
47 |
48 | if(!(Test-Path $nugetToolsPath)) {
49 | mkdir $nugetToolsPath | Out-Null
50 | }
51 |
52 | Write-Host "Copying nuget.exe and msbuild scripts to $nugetToolsPath"
53 |
54 | Copy-Item "$nugetBuildPath\tools\*.*" $nugetToolsPath -Force | Out-Null
55 | Copy-Item "$nugetExePath\tools\*.*" $nugetToolsPath -Force | Out-Null
56 | Uninstall-Package NuGet.Build -RemoveDependencies
57 |
58 | Write-Host "Don't forget to commit the .nuget folder"
59 | }
60 |
61 | return $true
62 | }
63 |
64 | function Add-NuGetTargets {
65 | param(
66 | [parameter(ValueFromPipelineByPropertyName = $true)]
67 | [string[]]$ProjectName
68 | )
69 | Process {
70 | if($ProjectName) {
71 | $projects = Get-Project $ProjectName
72 | }
73 | else {
74 | # All projects by default
75 | $projects = Get-Project -All
76 | }
77 |
78 | if(!$projects) {
79 | Write-Error "Unable to locate project. Make sure it isn't unloaded."
80 | return
81 | }
82 |
83 | $targetsPath = '$(SolutionDir)\.nuget\NuGet.targets'
84 |
85 | $projects | %{
86 | $project = $_
87 | try {
88 | if($project.Type -eq 'Web Site') {
89 | Write-Warning "Skipping '$($project.Name)', Website projects are not supported"
90 | return
91 | }
92 |
93 | if(!$initialized) {
94 | # Make sure the nuget tools exists
95 | $initialized = Ensure-NuGetBuild
96 | }
97 |
98 | $project | Add-SolutionDirProperty
99 |
100 | $buildProject = $project | Get-MSBuildProject
101 | if(!($buildProject.Xml.Imports | ?{ $_.Project -eq $targetsPath } )) {
102 | $buildProject.Xml.AddImport($targetsPath) | Out-Null
103 | $project.Save()
104 | $buildProject.ReevaluateIfNecessary()
105 |
106 | "Updated '$($project.Name)' to use 'NuGet.targets'"
107 | }
108 | }
109 | catch {
110 | Write-Warning "Failed to add import 'NuGet.targets' to $($project.Name)"
111 | }
112 | }
113 | }
114 | }
115 |
116 | function Enable-PackageRestore {
117 | param(
118 | [parameter(ValueFromPipelineByPropertyName = $true)]
119 | [string[]]$ProjectName
120 | )
121 |
122 | # Add the nuget targets on demand
123 | Add-NuGetTargets $ProjectName
124 |
125 | (Resolve-ProjectName $ProjectName) | %{
126 | $_ | Set-MSBuildProperty RestorePackages true
127 | "Enabled package restore for $($_.Name)"
128 | }
129 | }
130 |
131 | function Disable-PackageRestore {
132 | param(
133 | [parameter(ValueFromPipelineByPropertyName = $true)]
134 | [string[]]$ProjectName
135 | )
136 | (Resolve-ProjectName $ProjectName) | %{
137 | $_ | Set-MSBuildProperty RestorePackages false
138 | "Disabled package restore for $($_.Name)"
139 | }
140 | }
141 |
142 | function Enable-PackageBuild {
143 | param(
144 | [parameter(ValueFromPipelineByPropertyName = $true)]
145 | [string[]]$ProjectName
146 | )
147 |
148 | # Add the nuget targets on demand
149 | Add-NuGetTargets $ProjectName
150 |
151 | (Resolve-ProjectName $ProjectName) | %{
152 | $_ | Set-MSBuildProperty BuildPackage true
153 | "Enabled package build for $($_.Name)"
154 | }
155 | }
156 |
157 | function Disable-PackageBuild {
158 | param(
159 | [parameter(ValueFromPipelineByPropertyName = $true)]
160 | [string[]]$ProjectName
161 | )
162 | (Resolve-ProjectName $ProjectName) | %{
163 | $_ | Set-MSBuildProperty BuildPackage false
164 | "Disabled package build for $($_.Name)"
165 | }
166 | }
167 |
168 | # Statement completion for project names
169 | 'Enable-PackageRestore', 'Disable-PackageRestore', 'Enable-PackageBuild', 'Disable-PackageBuild' | %{
170 | Register-TabExpansion $_ @{
171 | ProjectName = { Get-Project -All | Select -ExpandProperty Name }
172 | }
173 | }
174 |
175 | Export-ModuleMember Enable-PackageRestore, Disable-PackageRestore, Enable-PackageBuild, Disable-PackageBuild
--------------------------------------------------------------------------------
/NuGetPowerTools.nuspec:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | NuGetPowerTools
5 | 0.29
6 | David Fowler
7 | false
8 | Powershell goodies that make working with nuget even easier!
9 | https://github.com/davidfowl/NuGetPowerTools
10 | http://nuget.codeplex.com/license
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/NuGetPowerTools.psd1:
--------------------------------------------------------------------------------
1 | @{
2 |
3 | # Script module or binary module file associated with this manifest
4 | ModuleToProcess = 'NuGetPowerTools.psm1'
5 |
6 | # Version number of this module.
7 | ModuleVersion = '0.1'
8 |
9 | # ID used to uniquely identify this module
10 | GUID = '0093ae2d-89e4-494c-81a6-35881fafb6f2'
11 |
12 | # Author of this module
13 | Author = 'David Fowler'
14 |
15 | # Company or vendor of this module
16 | CompanyName = 'Outercurve Foundation'
17 |
18 | # Copyright statement for this module
19 | Copyright = '(c) 2011 Outercurve Foundation. All rights reserved.'
20 |
21 | # Description of the functionality provided by this module
22 | Description = 'This module provide some powershell goodies that makes working with nuget even easier'
23 |
24 | # Minimum version of the Windows PowerShell engine required by this module
25 | PowerShellVersion = '2.0'
26 |
27 | # Name of the Windows PowerShell host required by this module
28 | PowerShellHostName = 'Package Manager Host'
29 |
30 | # Minimum version of the Windows PowerShell host required by this module
31 | PowerShellHostVersion = '1.2'
32 |
33 | # Minimum version of the .NET Framework required by this module
34 | DotNetFrameworkVersion = '4.0'
35 |
36 | # Minimum version of the common language runtime (CLR) required by this module
37 | CLRVersion = ''
38 |
39 | # Processor architecture (None, X86, Amd64, IA64) required by this module
40 | ProcessorArchitecture = ''
41 |
42 | # Modules that must be imported into the global environment prior to importing this module
43 | RequiredModules = @()
44 |
45 | # Assemblies that must be loaded prior to importing this module
46 | RequiredAssemblies = @()
47 |
48 | # Script files (.ps1) that are run in the caller's environment prior to importing this module
49 | ScriptsToProcess = @()
50 |
51 | # Type files (.ps1xml) to be loaded when importing this module
52 | TypesToProcess = @()
53 |
54 | # Format files (.ps1xml) to be loaded when importing this module
55 | FormatsToProcess = @()
56 |
57 | # Modules to import as nested modules of the module specified in ModuleToProcess
58 | NestedModules = @('VS.psm1', 'MSBuild.psm1', 'NuGetMSBuild.psm1')
59 |
60 | # Functions to export from this module
61 | FunctionsToExport = '*'
62 |
63 | # Cmdlets to export from this module
64 | CmdletsToExport = ''
65 |
66 | # Variables to export from this module
67 | VariablesToExport = ''
68 |
69 | # Aliases to export from this module
70 | AliasesToExport = ''
71 |
72 | # List of all files packaged with this module
73 | FileList = @()
74 |
75 | # Private data to pass to the module specified in ModuleToProcess
76 | PrivateData = ''
77 |
78 | }
--------------------------------------------------------------------------------
/NuGetPowerTools.psm1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/davidfowl/NuGetPowerTools/6b5ffacee433eaa696ad4caefd2996d451a61680/NuGetPowerTools.psm1
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # License
2 | Same as NuGet http://nuget.codeplex.com/license
3 |
4 | # Overview
5 | NuGetPowerTools is a collection of powershell modules that add useful functions for working with nuget inside Visual Studio.
6 |
7 | # Installing
8 | Using the [package](http://nuget.org/List/Packages/NuGetPowerTools) is good if you want to share these commands with all developers working on a particular project. Just do:
9 |
10 | Install-Package NuGetPowerTools
11 |
12 | ## NuGet profile
13 | You can also manually import this module into your profile script, so that the functionality is always there.
14 | Read more [here](http://docs.nuget.org/docs/start-here/using-the-package-manager-console#Setting_up_a_NuGet_Powershell_Profile)
15 |
16 | # Using the package
17 | ## Package Restore and Build
18 | NuGetPowerTools make it super easy to enable package restore and building a package from your project.
19 |
20 | For restore, just type:
21 |
22 | Enable-PackageRestore
23 |
24 | This command will add true in your project file(s).
25 |
26 | For build:
27 |
28 | Enable-PackageBuild
29 |
30 | This command will add true in your project file(s).
31 |
32 | ## How it works
33 | Both restore and build will download nuget.exe and some custom build targets and will automatically hook your project up to use them.
34 | It will store these in a .nuget folder (remember to check this in).
35 |
--------------------------------------------------------------------------------
/VS.psm1:
--------------------------------------------------------------------------------
1 | function Get-SolutionDir {
2 | if($dte.Solution -and $dte.Solution.IsOpen) {
3 | return Split-Path $dte.Solution.Properties.Item("Path").Value
4 | }
5 | else {
6 | throw "Solution not avaliable"
7 | }
8 | }
9 |
10 | function Get-ProjectPropertyValue {
11 | param(
12 | [parameter(Mandatory = $true)]
13 | [string]$ProjectName,
14 | [parameter(Mandatory = $true)]
15 | [string]$PropertyName
16 | )
17 | try {
18 | $property = (Get-Project $ProjectName).Properties.Item($PropertyName)
19 | if($property) {
20 | return $property.Value
21 | }
22 | }
23 | catch {
24 | }
25 | return $null
26 | }
27 |
28 | Export-ModuleMember *
--------------------------------------------------------------------------------
/init.ps1:
--------------------------------------------------------------------------------
1 | param($installPath, $toolsPath, $package, $project)
2 | Import-Module (Join-Path $toolsPath NuGetPowerTools.psd1)
3 |
4 | Write-Host ""
5 | Write-Host "*************************************************************************************"
6 | Write-Host " INSTRUCTIONS"
7 | Write-Host "*************************************************************************************"
8 | Write-Host " - To enable building a package from a project use the Enable-PackageBuild command"
9 | Write-Host " - To enable restoring packages on build use the Enable-PackageRestore command."
10 | Write-Host " - When using one of the above commands, a .nuget folder will been added to your"
11 | Write-Host " solution root. Make sure you check it in!"
12 | Write-Host " - For for information, see https://github.com/davidfowl/NuGetPowerTools"
13 | Write-Host "*************************************************************************************"
14 | Write-Host ""
--------------------------------------------------------------------------------