I've been creating some NuGet packages recenly and to automate the process I created the following script that:
- reads the package id from the script name
- reads the package version from the nuspec file
can rebuild the solution, create a package and upload it by specifying the
jkl
parameters where:- j - 0/1 - disables/enables project rebuild
- k - 0/1 - disables/enables package creation
- l - 0/1 - disables/enables package upload to the server
Usage:
./MyPackage.ps1 110
This would create a package called MyPackage
with rebuilding the solution but not uploading it to the server yet
param([String]$cmd)
$build = $cmd.Substring(0,1) -eq "1"
$pack = $cmd.Substring(1,1) -eq "1"
$push = $cmd.Substring(2,1) -eq "1"
$packageId=[System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Definition)
[xml]$nuspec = Get-Content $PSScriptRoot\$packageId.nuspec
$version = $nuspec.SelectSingleNode("//package/metadata/version").InnerText
if ($build)
{
msbuild `
/t:Rebuild `
/nologo `
/p:Configuration=Release `
/p:TargetFrameworkVersion=v4.5.2 `
/p:Platform="Any CPU" `
/p:OutDir="$PSScriptRoot\lib\net452" `
`"$PSScriptRoot\..\Foo.sln`"
}
if ($pack)
{
nuget pack `
$PSScriptRoot\$packageId.nuspec `
-properties configuration=release `
-outputdirectory C:\NuGet\packages\
}
if ($push)
{
nuget push `
C:\NuGet\packages\$packageId.$version.nupkg `
-configfile $PSScriptRoot\NuGet.config
}