-
Notifications
You must be signed in to change notification settings - Fork 7
/
Show-NugetDisagreement.ps1
84 lines (61 loc) · 2.73 KB
/
Show-NugetDisagreement.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
76
77
78
79
80
81
82
83
84
<#
.SYNOPSIS Finds where a packages.config does not match nuspec dependency versions
#>
function Show-NugetDisagreement
{
[CmdletBinding()]
Param(
[string]$ProjectFolder
)
Write-Verbose "Searching for packages.config and a nuspec file in $ProjectFolder"
$projectFolderName = Split-Path -Path $ProjectFolder -Leaf
$pathToPackageConfig = "$ProjectFolder\packages.config"
$pathToNuspec = Get-ChildItem -Path $ProjectFolder -Filter *.nuspec | Select-Object -First 1 -ExpandProperty FullName
if ($null -eq $pathToNuspec)
{
Write-Verbose "No nuspec found for project folder $ProjectFolder"
return
}
Write-Verbose "Testing path $pathToPackageConfig"
if (-Not (Test-Path $pathToPackageConfig))
{
Write-Verbose "No packages.config found for project folder $ProjectFolder"
return
}
Write-Verbose "Testing path $pathToNuspec"
if (-Not (Test-Path $pathToNuspec))
{
Write-Verbose "No nuspec found for project folder $ProjectFolder"
return
}
$packageConfig = [xml](Get-Content $pathToPackageConfig)
$nuspec = [xml](Get-Content $pathToNuspec)
foreach ($referencedPackage in $packageConfig.packages.ChildNodes)
{
$doesNuspecHaveReferencedPackage = $false
Write-Verbose "evaluating referenced package $($referencedPackage.id) / $($referencedPackage.version)"
if ($referencedPackage.developmentDependency -eq $true) {continue}
foreach ($nuspecDependencyPackage in $nuspec.package.metadata.dependencies.ChildNodes)
{
Write-Verbose "comparing nuspec dependency $($nuspecDependencyPackage.id) / $($nuspecDependencyPackage.version)"
if ($nuspecDependencyPackage.id -ieq $referencedPackage.id)
{
$doesNuspecHaveReferencedPackage = $true
Write-Verbose "matching package id found, checking version"
if ($nuspecDependencyPackage.version -ieq $referencedPackage.version)
{
Write-Verbose "version also matches"
}
else
{
Write-Host "Project folder $projectFolderName - $($referencedPackage.id) version mismatch. Referenced version $($referencedPackage.version). Nuspec dependency version $($nuspecDependencyPackage.version)" -ForegroundColor Red
}
break
}
}
if ($doesNuspecHaveReferencedPackage -eq $false)
{
Write-Host "Project folder $projectFolderName - nuspec file '$pathToNuspec' does not have package $($referencedPackage.id) / $($referencedPackage.version) in the dependencies list" -ForegroundColor Red
}
}
}