This repository was archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathNew-NuspecFile.ps1
More file actions
128 lines (94 loc) · 3.9 KB
/
New-NuspecFile.ps1
File metadata and controls
128 lines (94 loc) · 3.9 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
function New-NuspecFile {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$OutputPath,
[Parameter(Mandatory = $true)]
[string]$Id,
[Parameter(Mandatory = $true)]
[version]$Version,
[Parameter(Mandatory = $true)]
[string]$Description,
[Parameter(Mandatory = $true)]
[string[]]$Authors,
[Parameter()]
[string[]]$Owners,
[Parameter()]
[string]$ReleaseNotes,
[Parameter()]
[bool]$RequireLicenseAcceptance,
[Parameter()]
[string]$Copyright,
[Parameter()]
[string[]]$Tags,
[Parameter()]
[string]$LicenseUrl,
[Parameter()]
[string]$ProjectUrl,
[Parameter()]
[string]$IconUrl,
[Parameter()]
[PSObject[]]$Dependencies,
[Parameter()]
[PSObject[]]$Files
)
Set-StrictMode -Off
$nameSpaceUri = "http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"
[xml]$xml = New-Object System.Xml.XmlDocument
$xmlDeclaration = $xml.CreateXmlDeclaration("1.0", "utf-8", $null)
$xml.AppendChild($xmlDeclaration) | Out-Null
#create top-level elements
$packageElement = $xml.CreateElement("package", $nameSpaceUri)
$metaDataElement = $xml.CreateElement("metadata", $nameSpaceUri)
# warn we're over 4000 characters for standard nuget servers
$tagsString = $Tags -Join " "
if ($tagsString.Length -gt 4000) {
Write-Warning -Message "Tag list exceeded 4000 characters and may not be accepted by some Nuget feeds."
}
$metaDataElementsHash = [ordered]@{
id = $Id
version = $Version
description = $Description
authors = $Authors -Join ","
owners = $Owners -Join ","
releaseNotes = $ReleaseNotes
requireLicenseAcceptance = $RequireLicenseAcceptance.ToString().ToLower()
copyright = $Copyright
tags = $tagsString
}
if ($LicenseUrl) { $metaDataElementsHash.Add("licenseUrl", $LicenseUrl) }
if ($ProjectUrl) { $metaDataElementsHash.Add("projectUrl", $ProjectUrl) }
if ($IconUrl) { $metaDataElementsHash.Add("iconUrl", $IconUrl) }
foreach ($key in $metaDataElementsHash.Keys) {
$element = $xml.CreateElement($key, $nameSpaceUri)
$elementInnerText = $metaDataElementsHash.item($key)
$element.InnerText = $elementInnerText
$metaDataElement.AppendChild($element) | Out-Null
}
if ($Dependencies) {
$dependenciesElement = $xml.CreateElement("dependencies", $nameSpaceUri)
foreach ($dependency in $Dependencies) {
$element = $xml.CreateElement("dependency", $nameSpaceUri)
$element.SetAttribute("id", $dependency.id)
if ($dependency.version) { $element.SetAttribute("version", $dependency.version) }
$dependenciesElement.AppendChild($element) | Out-Null
}
$metaDataElement.AppendChild($dependenciesElement) | Out-Null
}
if ($Files) {
$filesElement = $xml.CreateElement("files", $nameSpaceUri)
foreach ($file in $Files) {
$element = $xml.CreateElement("file", $nameSpaceUri)
$element.SetAttribute("src", $file.src)
if ($file.target) { $element.SetAttribute("target", $file.target) }
if ($file.exclude) { $element.SetAttribute("exclude", $file.exclude) }
$filesElement.AppendChild($element) | Out-Null
}
}
$packageElement.AppendChild($metaDataElement) | Out-Null
if ($filesElement) { $packageElement.AppendChild($filesElement) | Out-Null }
$xml.AppendChild($packageElement) | Out-Null
$nuspecFullName = Join-Path -Path $OutputPath -ChildPath "$Id.nuspec"
$xml.save($nuspecFullName)
Write-Output $nuspecFullName
}