forked from kine/NVRAppDevOps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-ALNuSpec.ps1
75 lines (75 loc) · 2.57 KB
/
New-ALNuSpec.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
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
function New-ALNuSpec
{
Param(
[Parameter(ValueFromPipelineByPropertyName=$True)]
$AppFile,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$AppName,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$Publisher,
[Parameter(ValueFromPipelineByPropertyName=$True)]
$AppVersion,
$NuspecFileName,
$id,
$authors='',
$owners='',
$licenseUrl='',
$projectUrl='',
$iconUrl='',
$releaseNotes='',
$description='',
$copyright='',
$tags='',
$AppDependencies,
$IdPrefix, #Will be used before AppName and all Dependency names
$DependencyFormat='$($Dep.publisher)_$($Dep.name)'
)
$nuspec =@()
$xmltext = @"
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>$IdPrefix$(Format-AppNameForNuget $id)</id>
<version>$AppVersion</version>
<authors>$authors</authors>
<owners>$owners</owners>
"@
if ($licenseUrl) {
$xmltext +=" <licenseUrl>$licenseUrl</licenseUrl>"
}
if ($projectUrl) {
$xmltext +=" <projectUrl>$projectUrl</projectUrl>"
}
if ($iconUrl) {
$Xmltext +=" <iconUrl>$iconUrl</iconUrl>"
}
$xmltext +=@"
<releaseNotes>$releaseNotes</releaseNotes>
<description>$description</description>
<copyright>$copyright</copyright>
<tags>$tags</tags>
<dependencies></dependencies>
</metadata>
<files>
<file src="$(Split-Path -Leaf $AppFile)" target="" />
</files>
</package>
"@
$nuspec =[System.Xml.XmlDocument]$xmltext
foreach($Dep in $AppDependencies) {
if ($Dep.publisher -ne 'Microsoft') {
$depXml = $nuspec.CreateElement('dependency','http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd')
$attr = $nuspec.CreateAttribute("id")
$attr.Value = "$IdPrefix$(Format-AppNameForNuget $ExecutionContext.InvokeCommand.ExpandString($DependencyFormat))"
$depXml.Attributes.Append($attr) | out-null
$attr = $nuspec.CreateAttribute("version")
$attr.Value = $Dep.version
if ($Dep.MinVersion) {
$attr.Value = $Dep.MinVersion
}
$depXml.Attributes.Append($attr) | out-null
$nuspec.package.metadata.SelectSingleNode("./*[name()='dependencies']").AppendChild($depXml)
}
}
$nuspec.Save($NuspecFileName)
}