Compare-Packages.psm1
function GetName($item){ $val = $item.Attributes["id"].Value if($null -ne $val){ return $val } return $item.Attributes["Include"].Value } function GetVersion($item){ $val = $item.Attributes["allowedVersions"].Value if($null -ne $val) { return $val } $val = $item.Attributes["version"].Value if($null -ne $val) { return $val } return $item.Attributes["Version"].Value } function FindItem($elements, $name, $version) { foreach($e in $elements){ $n = GetName $e $v = GetVersion $e if( ($n -eq $name) -and ($v -eq $version) ) { return $false } } return $true; } <# .Synopsis Automatic Publish Tool (APT) .DESCRIPTION Compare packages for project .EXAMPLE Compare-Packages D:\Projects\src .NOTES Author: Imrich Szolik #> function Compare-Packages { [CmdletBinding()] [Alias()] Param( # Solution directory [string] [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$false, HelpMessage="Project src file.")] $Solution ) Begin{ } Process{ $projects = Get-ChildItem -Recurse -Path $Solution -Filter *.csproj foreach($project in $projects){ $name = $project.Name $prj = $project.FullName $nuget = $prj -replace "csproj", "nuspec" $package = Join-Path $project.Directory 'packages.config' $referenceItems = $null if( Test-Path -Path $nuget -PathType Leaf) { $type = $false #net48 if(Test-Path -Path $package -PathType Leaf ){ $referenceItems = Select-Xml -Path $package -XPath //packages/package | ForEach-Object { $_.Node } $type = $false } #net core or .net48 with PackageReference else{ $type=$true $content = (Get-Content $prj) -as [Xml] if($content.Project.NamespaceURI -ne ''){ $namespace = @{ "ns" = "http://schemas.microsoft.com/developer/msbuild/2003" } $referenceItems = Select-Xml -Xml $content -XPath //ns:Project/ns:ItemGroup/ns:PackageReference -Namespace $namespace | ForEach-Object { $_.Node } } else{ $referenceItems = Select-Xml -Xml $content -XPath //Project/ItemGroup/PackageReference | ForEach-Object { $_.Node } } } #nuget items $nugetReference = Select-Xml -Path $nuget -XPath //package/metadata/dependencies/group/dependency | ForEach-Object { $_.Node } $referenceItemsResult = @() #processing foreach($pr in $referenceItems){ $n = GetName $pr $v = GetVersion $pr if (FindItem $nugetReference $n $v){ $referenceItemsResult += [PSCustomObject] @{ Name = $n; Version = $v } } } #output if( $referenceItemsResult.Count -gt 0 ){ Write-Warning "===== $name (update dependencies/group/) ======" $referenceItemsResult = $referenceItemsResult | Sort-Object -Property Name foreach($r in $referenceItemsResult){ Write-Warning "<dependency id=""$($r.Name)"" version=""$($r.Version)"" exclude=""Build,Analyzers"" />" } } $nugetReferenceResult = @() foreach($pr in $nugetReference){ $n = GetName $pr $v = GetVersion $pr if (FindItem $referenceItems $n $v){ $nugetReferenceResult += [PSCustomObject] @{ Name = $n; Version = $v } } } #output if( $nugetReferenceResult.Count -gt 0 ){ Write-Verbose "===== $name (update package-refrence) ======" $nugetReferenceResult = $nugetReferenceResult | Sort-Object -Property Name foreach($r in $nugetReferenceResult){ if($type){ Write-Verbose "<PackageReference Include=""$($r.Name)"" Version=""$($r.Version)"" />" } else{ Write-Verbose "<package id=""$($r.Name)"" version=""$($r.Version)"" targetFramework=""net48"" />" } } } } } } End{ } } Export-ModuleMember -Function Compare-Packages # SIG # Begin signature block # MIIIEwYJKoZIhvcNAQcCoIIIBDCCCAACAQExDzANBglghkgBZQMEAgEFADB5Bgor # BgEEAYI3AgEEoGswaTA0BgorBgEEAYI3AgEeMCYCAwEAAAQQH8w7YFlLCE63JNLG # KX7zUQIBAAIBAAIBAAIBAAIBADAxMA0GCWCGSAFlAwQCAQUABCBKGnpw/SBSQAh4 # PifXbtC9dytz3O2HwIvebykE/xJV2KCCBQ8wggULMIIC86ADAgECAgIApTANBgkq # hkiG9w0BAQsFADCBoDELMAkGA1UEBhMCU0sxETAPBgNVBAgTCFNsb3Zha2lhMRMw # EQYDVQQHEwpCcmF0aXNsYXZhMRMwEQYDVQQKEwpMb210ZWMuY29tMSswKQYDVQQD # EyJMb210ZWMuY29tIENlcnRpZmljYXRpb24gQXV0aG9yaXR5MScwJQYJKoZIhvcN # AQkBFhhJbXJpY2guU3pvbGlrQGxvbXRlYy5jb20wHhcNMTkwMzI2MTUwNDQzWhcN # MzAwMTAxMDAwMDAwWjCBkzELMAkGA1UEBh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zjhpBXg0h6RMTLlcpoZ # rl1dhXspVZi88hUM7f41CybjIryOSOeCv2FxQYDz7JoPenMkStPF0chaB7iYyVrK # umjbIrcbNg== # SIG # End signature block |