/
CreateNugetPackage.ps1
44 lines (30 loc) · 1.29 KB
/
CreateNugetPackage.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Param(
[string] $projectPath,
[string] $projectFileExt,
[string] $targetPath,
[string] $targetName,
[string] $configurationName
)
$nuspecFilePath = "$projectPath.nuspec"
$nuget = "C:\Utilities\Nuget\NuGet.exe"
[xml]$nuspecContent = switch ([System.IO.File]::Exists($nuspecFilePath))
{
$false {
Write-Host "nuspec file not found at: $projectPath. Creating"
& $nuget spec $projectPath | Write-Host
[xml]$file = Get-Content $nuspecFilePath
$metaData = $file.package.metadata
$metaData.id = $targetName
$metaData.RemoveChild($metaData.SelectSingleNode("licenseUrl")) | Out-Null
$metaData.RemoveChild($metaData.SelectSingleNode("projectUrl")) | Out-Null
$metaData.RemoveChild($metaData.SelectSingleNode("iconUrl")) | Out-Null
$file
}
$true {Get-Content $nuspecFilePath}
}
$assembly = [System.Reflection.Assembly]::LoadFile($targetPath)
$assemblyVersion = $assembly.GetName().Version.ToString()
Write-Host "Setting assembly version to: $assemblyVersion"
$nuspecContent.package.metadata.version = $assemblyVersion
$nuspecContent.Save($nuspecFilePath)
& $nuget pack $projectPath -IncludeReferencedProjects -Properties Configuration=$configurationName