1+ param (
2+ [Parameter (Mandatory = $false )][string ]$srcRoot = " ." ,
3+ [Parameter (Mandatory = $true )][string ]$keyFile ,
4+ [Parameter (Mandatory = $true )][string ]$publicKey ,
5+ [Parameter (Mandatory = $false )][string ]$publicToken
6+ )
7+
8+ $snSignAssembly = " true"
9+ $delaySignAssembly = " true"
10+
11+ Function GetXmlFile
12+ {
13+ param (
14+ [Parameter (Mandatory = $true )][string ]$inputFile
15+ )
16+
17+ return [xml ](Get-Content $inputFile )
18+ }
19+
20+ Function MakeNodeWithInnerText
21+ {
22+ param (
23+ [Parameter (Mandatory = $true )][xml ]$inputXml ,
24+ [Parameter (Mandatory = $true )][string ]$newPropertyName ,
25+ [Parameter (Mandatory = $true )][string ]$newPropertyValue ,
26+ [Parameter (Mandatory = $false )][string ]$xmlns = " "
27+ )
28+
29+ $newNode = $inputXml.CreateElement ($newPropertyName , $xmlns )
30+ $newNode.set_InnerXML ($newPropertyValue )
31+
32+ return $newNode
33+ }
34+
35+ Function EnableSNAndDelaySign
36+ {
37+ param (
38+ [Parameter (Mandatory = $true )][xml ]$projectXML
39+ )
40+
41+ $xmlNameSpace = $projectXML.Project.xmlns
42+ $newPropertyGroup = $projectXML.CreateElement (" PropertyGroup" , $xmlNameSpace );
43+
44+ $newKeyFileNode = MakeNodeWithInnerText $projectXML " AssemblyOriginatorKeyFile" $keyFile $xmlNameSpace
45+ $newSignAssemblyNode = MakeNodeWithInnerText $projectXML " SignAssembly" $snSignAssembly $xmlNameSpace
46+ $newDelaySignNode = MakeNodeWithInnerText $projectXML " DelaySign" $delaySignAssembly $xmlNameSpace
47+
48+ $newPropertyGroup.AppendChild ($newKeyFileNode )
49+ $newPropertyGroup.AppendChild ($newSignAssemblyNode )
50+ $newPropertyGroup.AppendChild ($newDelaySignNode )
51+
52+ $projectXml.Project.AppendChild ($newPropertyGroup )
53+ }
54+
55+ Function InjectPublicKeyIntoAssemblyInfo
56+ {
57+ param ([string ]$assemblyInfoFilePath )
58+
59+ $assemblyInfo = Get-Content $assemblyInfoFilePath
60+
61+ $injectedAssemblyInfo = $assemblyInfo -replace ' (?<=\[assembly: InternalsVisibleTo\(")(.*)?(?="\)\])' , " `$ {1},PublicKey=$publicKey "
62+
63+ Set-Content $assemblyInfoFilePath $injectedAssemblyInfo
64+ Write-Host " Set public key in $assemblyInfoFilePath "
65+ }
66+
67+ $xmls = " src\NuGet.Server\NuGet.Server.csproj" ,
68+ " src\NuGet.Server.V2\NuGet.Server.V2.csproj" ,
69+ " src\NuGet.Server.Core\NuGet.Server.Core.csproj" ,
70+ " test\NuGet.Server.Tests\NuGet.Server.Tests.csproj" ,
71+ " test\NuGet.Server.V2.Tests\NuGet.Server.V2.Tests.csproj" ,
72+ " test\NuGet.Server.Core.Tests\NuGet.Server.Core.Tests.csproj"
73+
74+ $assemblyInfos = " src\NuGet.Server\Properties\AssemblyInfo.cs" ,
75+ " src\NuGet.Server.V2\Properties\AssemblyInfo.cs" ,
76+ " src\NuGet.Server.Core\Properties\AssemblyInfo.cs"
77+
78+ foreach ($relXmlPath in $xmls )
79+ {
80+ $xmlFile = Join-Path - Path $srcRoot - ChildPath $relXmlPath - Resolve
81+
82+ if (Test-Path $xmlFile )
83+ {
84+ $xml = GetXmlFile $xmlFile
85+ EnableSNAndDelaySign $xml
86+
87+ echo $xmlFile
88+
89+ $xml.Save ($xmlFile )
90+ }
91+ }
92+
93+ foreach ($assemblyInfoFile in $assemblyInfos )
94+ {
95+ if (Test-Path $assemblyInfoFile )
96+ {
97+ InjectPublicKeyIntoAssemblyInfo $assemblyInfoFile
98+ }
99+ }
100+
101+ if (-Not $publicToken ) {
102+ exit 0
103+ }
104+
105+ # Find latest version of Windows SDK installed
106+ $sdkRegistry = Get-ItemProperty " hklm:\SOFTWARE\Microsoft\Microsoft SDKs\Windows"
107+ $sdkInstallPath = $sdkRegistry.CurrentInstallFolder
108+ $toolsPath = (Get-ChildItem " $sdkInstallPath \bin" | Select-Object - Last 1 ).FullName
109+
110+ # Run sn.exe with the public token
111+ & " $toolsPath \sn.exe" " -Vr" " *,$publicToken "
112+ & " $toolsPath \x64\sn.exe" " -Vr" " *,$publicToken "
0 commit comments