-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathSyncNuspec.ps1
30 lines (22 loc) · 1005 Bytes
/
SyncNuspec.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
$directory = Get-Location
$csprojFiles = Get-ChildItem -Path $directory -Filter *.csproj -Recurse
foreach ($csprojPath in $csprojFiles) {
$nuspecPath = $csprojPath.FullName -replace '\.csproj$', '.nuspec'
if (-not (Test-Path -Path $nuspecPath)) {
Write-Host "No nuspec file found for $csprojPath, skipping..."
continue
}
Write-Host "Updating nuspec file for: $csprojPath"
[xml]$csprojFile = Get-Content -Path $csprojPath.FullName
[xml]$nuspecFile = Get-Content -Path $nuspecPath
$packageReferences = $csprojFile.Project.ItemGroup.PackageReference
foreach ($packageReference in $packageReferences) {
$id = $packageReference.Include
$version = $packageReference.Version
$nuspecDependency = $nuspecFile.package.metadata.dependencies.group.dependency | Where-Object { $_.id -eq $id }
if ($null -ne $nuspecDependency) {
$nuspecDependency.version = $version
}
}
$nuspecFile.Save($nuspecPath)
}