Skip to content

Commit 1264a00

Browse files
daxian-dbwadityapatwardhan
authored andcommitted
Update packaging script to build reference assembly targeting netcoreapp2.1 and use actual .csproj files (PowerShell#8729)
1 parent 28042f3 commit 1264a00

6 files changed

Lines changed: 64 additions & 60 deletions

File tree

‎tools/packaging/packaging.psm1‎

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,7 @@ function CreateNugetPlatformFolder
14321432
[string] $PlatformBinPath
14331433
)
14341434

1435-
$destPath = New-Item -ItemType Directory -Path (Join-Path $PackageRuntimesFolder "$Platform/lib/netstandard2.0")
1435+
$destPath = New-Item -ItemType Directory -Path (Join-Path $PackageRuntimesFolder "$Platform/lib/netcoreapp2.1")
14361436
$fullPath = Join-Path $PlatformBinPath $file
14371437

14381438
if (-not(Test-Path $fullPath)) {
@@ -1563,7 +1563,7 @@ function New-UnifiedNugetPackage
15631563
$packageRuntimesFolder = New-Item (Join-Path $filePackageFolder.FullName 'runtimes') -ItemType Directory
15641564

15651565
#region ref
1566-
$refFolder = New-Item (Join-Path $filePackageFolder.FullName 'ref/netstandard2.0') -ItemType Directory -Force
1566+
$refFolder = New-Item (Join-Path $filePackageFolder.FullName 'ref/netcoreapp2.1') -ItemType Directory -Force
15671567
CopyReferenceAssemblies -assemblyName $fileBaseName -refBinPath $refBinPath -refNugetPath $refFolder -assemblyFileList $fileList
15681568
#endregion ref
15691569

@@ -1694,7 +1694,7 @@ function New-UnifiedNugetPackage
16941694
}
16951695

16961696
<#
1697-
Copy the generated reference assemblies to the 'ref/netstandard2.0' folder properly.
1697+
Copy the generated reference assemblies to the 'ref/netcoreapp2.1' folder properly.
16981698
This is a helper function used by 'New-UnifiedNugetPackage'
16991699
#>
17001700
function CopyReferenceAssemblies
@@ -1897,6 +1897,7 @@ function New-ReferenceAssembly
18971897

18981898
foreach ($assemblyName in $assemblyNames) {
18991899

1900+
Write-Log "Building reference assembly for '$assemblyName'"
19001901
$projectFolder = New-Item -Path "$genAPIFolder/$assemblyName" -ItemType Directory -Force
19011902
$generatedSource = Join-Path $projectFolder "$assemblyName.cs"
19021903
$filteredSource = Join-Path $projectFolder "${assemblyName}_Filtered.cs"
@@ -1918,15 +1919,19 @@ function New-ReferenceAssembly
19181919
{
19191920
Push-Location $projectFolder
19201921

1921-
$csProj = GenerateCSProjectContent -AssemblyName $assemblyName -RefAssemblyVersion $RefAssemblyVersion -SnkFilePath $SnkFilePath -SMAReferencePath $SMAReferenceAssembly
1922-
$csProj | Out-File -FilePath "$projectFolder/$assemblyName.csproj" -Force
1922+
$sourceProjectRoot = Join-Path $PSScriptRoot 'projects/reference'
1923+
$sourceProjectFile = Join-Path $sourceProjectRoot "$assemblyName.csproj"
1924+
Copy-Item -Path $sourceProjectFile -Destination "$projectFolder/$assemblyName.csproj" -Force
19231925

19241926
Write-Host "##vso[artifact.upload containerfolder=artifact;artifactname=artifact]$projectFolder/$assemblyName.csproj"
19251927
Write-Host "##vso[artifact.upload containerfolder=artifact;artifactname=artifact]$generatedSource"
19261928

1927-
Start-NativeExecution { dotnet build -c Release }
1929+
$arguments = GenerateBuildArguments -AssemblyName $assemblyName -RefAssemblyVersion $RefAssemblyVersion -SnkFilePath $SnkFilePath -SMAReferencePath $SMAReferenceAssembly
19281930

1929-
$refBinPath = Join-Path $projectFolder "bin/Release/netstandard2.0/$assemblyName.dll"
1931+
Write-Log "Running: dotnet $arguments"
1932+
Start-NativeExecution -sb {dotnet $arguments}
1933+
1934+
$refBinPath = Join-Path $projectFolder "bin/Release/netcoreapp2.1/$assemblyName.dll"
19301935
if ($null -eq $refBinPath) {
19311936
throw "Reference assembly was not built."
19321937
}
@@ -1950,6 +1955,10 @@ function New-ReferenceAssembly
19501955
}
19511956
}
19521957

1958+
<#
1959+
Helper function for New-ReferenceAssembly to further clean up the
1960+
C# source code generated from GenApi.exe.
1961+
#>
19531962
function CleanupGeneratedSourceCode
19541963
{
19551964
param(
@@ -2033,7 +2042,11 @@ function CleanupGeneratedSourceCode
20332042
Write-Log "Code cleanup complete for reference assembly '$assemblyName'."
20342043
}
20352044

2036-
function GenerateCSProjectContent
2045+
<#
2046+
Helper function for New-ReferenceAssembly to get the arguments
2047+
for building reference assemblies.
2048+
#>
2049+
function GenerateBuildArguments
20372050
{
20382051
param(
20392052
[string] $AssemblyName,
@@ -2042,21 +2055,18 @@ function GenerateCSProjectContent
20422055
[string] $SMAReferencePath
20432056
)
20442057

2045-
switch ($assemblyName) {
2046-
"System.Management.Automation" {
2047-
$csProj = $packagingStrings.'System.Management.Automation' -f $RefAssemblyVersion, $SnkFilePath
2048-
}
2058+
$arguments = @('build')
2059+
$arguments += @('-c','Release')
2060+
$arguments += "/p:RefAsmVersion=$RefAssemblyVersion"
2061+
$arguments += "/p:SnkFile=$SnkFilePath"
20492062

2063+
switch ($AssemblyName) {
20502064
"Microsoft.PowerShell.Commands.Utility" {
2051-
$csProj = $packagingStrings.'Microsoft.PowerShell.Commands.Utility' -f $RefAssemblyVersion, $SnkFilePath, $SMAReferencePath
2052-
}
2053-
2054-
default {
2055-
throw "It's not yet supported to generate reference assembly for '$assemblyName'"
2065+
$arguments += "/p:SmaRefFile=$SMAReferencePath"
20562066
}
20572067
}
20582068

2059-
return $csProj
2069+
return $arguments
20602070
}
20612071

20622072
<#
@@ -2205,7 +2215,7 @@ function New-NugetContentPackage
22052215
New-StagingFolder -StagingPath $contentFolder
22062216
}
22072217

2208-
$projectFolder = Join-Path $PSScriptRoot -ChildPath 'project'
2218+
$projectFolder = Join-Path $PSScriptRoot 'projects/nuget'
22092219

22102220
$arguments = @('pack')
22112221
$arguments += @('--output',$nugetFolder)

‎tools/packaging/packaging.strings.psd1‎

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -136,46 +136,6 @@ open {0}
136136
</dependencies>
137137
</metadata>
138138
</package>
139-
'@
140-
141-
'System.Management.Automation' = @'
142-
<Project Sdk="Microsoft.NET.Sdk">
143-
<PropertyGroup>
144-
<TargetFramework>netstandard2.0</TargetFramework>
145-
<Version>{0}</Version>
146-
<DelaySign>true</DelaySign>
147-
<AssemblyOriginatorKeyFile>{1}</AssemblyOriginatorKeyFile>
148-
<SignAssembly>true</SignAssembly>
149-
<LangVersion>Latest</LangVersion>
150-
</PropertyGroup>
151-
<ItemGroup>
152-
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
153-
<PackageReference Include="System.Security.AccessControl" Version="4.4.1" />
154-
<PackageReference Include="System.Security.Principal.Windows" Version="4.4.1" />
155-
</ItemGroup>
156-
</Project>
157-
'@
158-
159-
'Microsoft.PowerShell.Commands.Utility' = @'
160-
<Project Sdk="Microsoft.NET.Sdk">
161-
<PropertyGroup>
162-
<TargetFramework>netstandard2.0</TargetFramework>
163-
<Version>{0}</Version>
164-
<DelaySign>true</DelaySign>
165-
<AssemblyOriginatorKeyFile>{1}</AssemblyOriginatorKeyFile>
166-
<SignAssembly>true</SignAssembly>
167-
<LangVersion>Latest</LangVersion>
168-
</PropertyGroup>
169-
<ItemGroup>
170-
<Reference Include="System.Management.Automation">
171-
<HintPath>{2}</HintPath>
172-
</Reference>
173-
</ItemGroup>
174-
<ItemGroup>
175-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
176-
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
177-
</ItemGroup>
178-
</Project>
179139
'@
180140

181141
NuGetConfigFile = @'
File renamed without changes.

tools/packaging/project/powershell.nuspec renamed to tools/packaging/projects/nuget/powershell.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<authors>PowerShell</authors>
88
<owners>PowerShell</owners>
99
<requireLicenseAcceptance>false</requireLicenseAcceptance>
10-
<licenseUrl>https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt</licenseUrl>
10+
<license type="expression">MIT</license>
1111
<projectUrl>https://github.com/powershell/powershell</projectUrl>
1212
<iconUrl>https://github.com/PowerShell/PowerShell/blob/master/assets/Powershell_64.png</iconUrl>
1313
<description>This package contains the PowerShell Core for $runtime$.</description>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<Version>$(RefAsmVersion)</Version>
5+
<DelaySign>true</DelaySign>
6+
<AssemblyOriginatorKeyFile>$(SnkFile)</AssemblyOriginatorKeyFile>
7+
<SignAssembly>true</SignAssembly>
8+
<LangVersion>Latest</LangVersion>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<Reference Include="System.Management.Automation">
12+
<HintPath>$(SmaRefFile)</HintPath>
13+
</Reference>
14+
</ItemGroup>
15+
<ItemGroup>
16+
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
17+
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
18+
</ItemGroup>
19+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<Version>$(RefAsmVersion)</Version>
5+
<DelaySign>true</DelaySign>
6+
<AssemblyOriginatorKeyFile>$(SnkFile)</AssemblyOriginatorKeyFile>
7+
<SignAssembly>true</SignAssembly>
8+
<LangVersion>Latest</LangVersion>
9+
</PropertyGroup>
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
12+
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
13+
<PackageReference Include="System.Security.Principal.Windows" Version="4.5.1" />
14+
</ItemGroup>
15+
</Project>

0 commit comments

Comments
 (0)