-
Notifications
You must be signed in to change notification settings - Fork 7
/
ConvertTo-Nuspec.ps1
41 lines (33 loc) · 1.26 KB
/
ConvertTo-Nuspec.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
param($Version)
$packages = @(
'Lombiq.Analyzers',
'Lombiq.Analyzers.NetFx',
'Lombiq.Analyzers.OrchardCore',
'Lombiq.Analyzers.Orchard1',
'Lombiq.Analyzers.VisualStudioExtension'
)
# Iterate through the packages to replace
foreach ($package in $packages)
{
$projectPath = Join-Path $PWD $package
function Read-Xml([string]$File) { [xml](Get-Content $File) }
$nuspec = Read-Xml (Join-Path $projectPath "$package.nuspec.template")
$dependencies = $nuspec.package.metadata.dependencies
$nuspec.package.metadata.GetElementsByTagName('version')[0].InnerXml = $Version
# AnalyzerPackages.props is optional.
$analyzerPackagesPropsFile = Join-Path $projectPath 'AnalyzerPackages.props'
if (Test-Path $analyzerPackagesPropsFile)
{
foreach ($dependency in (Read-Xml $analyzerPackagesPropsFile).Project.ItemGroup.AnalyzerPackage)
{
$id = $dependency.Include
if (-not $id) { continue }
$node = $nuspec.CreateElement('dependency')
$node.SetAttribute('id', $id)
$node.SetAttribute('version', $dependency.Version)
$dependencies.AppendChild($node)
}
}
$outputPath = Join-Path $projectPath "$package.nuspec"
$nuspec.Save($outputPath)
}