From 1264a00a760fff885e2ed588387cfb8e634b2311 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Fri, 25 Jan 2019 11:10:47 -0800 Subject: [PATCH] Update packaging script to build reference assembly targeting `netcoreapp2.1` and use actual `.csproj` files (#8729) --- tools/packaging/packaging.psm1 | 48 +++++++++++-------- tools/packaging/packaging.strings.psd1 | 40 ---------------- .../nuget}/package.csproj | 0 .../nuget}/powershell.nuspec | 2 +- ...crosoft.PowerShell.Commands.Utility.csproj | 19 ++++++++ .../System.Management.Automation.csproj | 15 ++++++ 6 files changed, 64 insertions(+), 60 deletions(-) rename tools/packaging/{project => projects/nuget}/package.csproj (100%) rename tools/packaging/{project => projects/nuget}/powershell.nuspec (90%) create mode 100644 tools/packaging/projects/reference/Microsoft.PowerShell.Commands.Utility.csproj create mode 100644 tools/packaging/projects/reference/System.Management.Automation.csproj diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1 index a7520945fb..ccd5cc9b88 100644 --- a/tools/packaging/packaging.psm1 +++ b/tools/packaging/packaging.psm1 @@ -1432,7 +1432,7 @@ function CreateNugetPlatformFolder [string] $PlatformBinPath ) - $destPath = New-Item -ItemType Directory -Path (Join-Path $PackageRuntimesFolder "$Platform/lib/netstandard2.0") + $destPath = New-Item -ItemType Directory -Path (Join-Path $PackageRuntimesFolder "$Platform/lib/netcoreapp2.1") $fullPath = Join-Path $PlatformBinPath $file if (-not(Test-Path $fullPath)) { @@ -1563,7 +1563,7 @@ function New-UnifiedNugetPackage $packageRuntimesFolder = New-Item (Join-Path $filePackageFolder.FullName 'runtimes') -ItemType Directory #region ref - $refFolder = New-Item (Join-Path $filePackageFolder.FullName 'ref/netstandard2.0') -ItemType Directory -Force + $refFolder = New-Item (Join-Path $filePackageFolder.FullName 'ref/netcoreapp2.1') -ItemType Directory -Force CopyReferenceAssemblies -assemblyName $fileBaseName -refBinPath $refBinPath -refNugetPath $refFolder -assemblyFileList $fileList #endregion ref @@ -1694,7 +1694,7 @@ function New-UnifiedNugetPackage } <# - Copy the generated reference assemblies to the 'ref/netstandard2.0' folder properly. + Copy the generated reference assemblies to the 'ref/netcoreapp2.1' folder properly. This is a helper function used by 'New-UnifiedNugetPackage' #> function CopyReferenceAssemblies @@ -1897,6 +1897,7 @@ function New-ReferenceAssembly foreach ($assemblyName in $assemblyNames) { + Write-Log "Building reference assembly for '$assemblyName'" $projectFolder = New-Item -Path "$genAPIFolder/$assemblyName" -ItemType Directory -Force $generatedSource = Join-Path $projectFolder "$assemblyName.cs" $filteredSource = Join-Path $projectFolder "${assemblyName}_Filtered.cs" @@ -1918,15 +1919,19 @@ function New-ReferenceAssembly { Push-Location $projectFolder - $csProj = GenerateCSProjectContent -AssemblyName $assemblyName -RefAssemblyVersion $RefAssemblyVersion -SnkFilePath $SnkFilePath -SMAReferencePath $SMAReferenceAssembly - $csProj | Out-File -FilePath "$projectFolder/$assemblyName.csproj" -Force + $sourceProjectRoot = Join-Path $PSScriptRoot 'projects/reference' + $sourceProjectFile = Join-Path $sourceProjectRoot "$assemblyName.csproj" + Copy-Item -Path $sourceProjectFile -Destination "$projectFolder/$assemblyName.csproj" -Force Write-Host "##vso[artifact.upload containerfolder=artifact;artifactname=artifact]$projectFolder/$assemblyName.csproj" Write-Host "##vso[artifact.upload containerfolder=artifact;artifactname=artifact]$generatedSource" - Start-NativeExecution { dotnet build -c Release } + $arguments = GenerateBuildArguments -AssemblyName $assemblyName -RefAssemblyVersion $RefAssemblyVersion -SnkFilePath $SnkFilePath -SMAReferencePath $SMAReferenceAssembly - $refBinPath = Join-Path $projectFolder "bin/Release/netstandard2.0/$assemblyName.dll" + Write-Log "Running: dotnet $arguments" + Start-NativeExecution -sb {dotnet $arguments} + + $refBinPath = Join-Path $projectFolder "bin/Release/netcoreapp2.1/$assemblyName.dll" if ($null -eq $refBinPath) { throw "Reference assembly was not built." } @@ -1950,6 +1955,10 @@ function New-ReferenceAssembly } } +<# + Helper function for New-ReferenceAssembly to further clean up the + C# source code generated from GenApi.exe. +#> function CleanupGeneratedSourceCode { param( @@ -2033,7 +2042,11 @@ function CleanupGeneratedSourceCode Write-Log "Code cleanup complete for reference assembly '$assemblyName'." } -function GenerateCSProjectContent +<# + Helper function for New-ReferenceAssembly to get the arguments + for building reference assemblies. +#> +function GenerateBuildArguments { param( [string] $AssemblyName, @@ -2042,21 +2055,18 @@ function GenerateCSProjectContent [string] $SMAReferencePath ) - switch ($assemblyName) { - "System.Management.Automation" { - $csProj = $packagingStrings.'System.Management.Automation' -f $RefAssemblyVersion, $SnkFilePath - } + $arguments = @('build') + $arguments += @('-c','Release') + $arguments += "/p:RefAsmVersion=$RefAssemblyVersion" + $arguments += "/p:SnkFile=$SnkFilePath" + switch ($AssemblyName) { "Microsoft.PowerShell.Commands.Utility" { - $csProj = $packagingStrings.'Microsoft.PowerShell.Commands.Utility' -f $RefAssemblyVersion, $SnkFilePath, $SMAReferencePath - } - - default { - throw "It's not yet supported to generate reference assembly for '$assemblyName'" + $arguments += "/p:SmaRefFile=$SMAReferencePath" } } - return $csProj + return $arguments } <# @@ -2205,7 +2215,7 @@ function New-NugetContentPackage New-StagingFolder -StagingPath $contentFolder } - $projectFolder = Join-Path $PSScriptRoot -ChildPath 'project' + $projectFolder = Join-Path $PSScriptRoot 'projects/nuget' $arguments = @('pack') $arguments += @('--output',$nugetFolder) diff --git a/tools/packaging/packaging.strings.psd1 b/tools/packaging/packaging.strings.psd1 index 0b9209ec4c..f1110d8901 100644 --- a/tools/packaging/packaging.strings.psd1 +++ b/tools/packaging/packaging.strings.psd1 @@ -136,46 +136,6 @@ open {0} -'@ - - 'System.Management.Automation' = @' - - - netstandard2.0 - {0} - true - {1} - true - Latest - - - - - - - -'@ - - 'Microsoft.PowerShell.Commands.Utility' = @' - - - netstandard2.0 - {0} - true - {1} - true - Latest - - - - {2} - - - - - - - '@ NuGetConfigFile = @' diff --git a/tools/packaging/project/package.csproj b/tools/packaging/projects/nuget/package.csproj similarity index 100% rename from tools/packaging/project/package.csproj rename to tools/packaging/projects/nuget/package.csproj diff --git a/tools/packaging/project/powershell.nuspec b/tools/packaging/projects/nuget/powershell.nuspec similarity index 90% rename from tools/packaging/project/powershell.nuspec rename to tools/packaging/projects/nuget/powershell.nuspec index 4207a096f7..da67106f43 100644 --- a/tools/packaging/project/powershell.nuspec +++ b/tools/packaging/projects/nuget/powershell.nuspec @@ -7,7 +7,7 @@ PowerShell PowerShell false - https://github.com/PowerShell/PowerShell/blob/master/LICENSE.txt + MIT https://github.com/powershell/powershell https://github.com/PowerShell/PowerShell/blob/master/assets/Powershell_64.png This package contains the PowerShell Core for $runtime$. diff --git a/tools/packaging/projects/reference/Microsoft.PowerShell.Commands.Utility.csproj b/tools/packaging/projects/reference/Microsoft.PowerShell.Commands.Utility.csproj new file mode 100644 index 0000000000..ea180ca686 --- /dev/null +++ b/tools/packaging/projects/reference/Microsoft.PowerShell.Commands.Utility.csproj @@ -0,0 +1,19 @@ + + + netcoreapp2.1 + $(RefAsmVersion) + true + $(SnkFile) + true + Latest + + + + $(SmaRefFile) + + + + + + + diff --git a/tools/packaging/projects/reference/System.Management.Automation.csproj b/tools/packaging/projects/reference/System.Management.Automation.csproj new file mode 100644 index 0000000000..77b99b0dba --- /dev/null +++ b/tools/packaging/projects/reference/System.Management.Automation.csproj @@ -0,0 +1,15 @@ + + + netcoreapp2.1 + $(RefAsmVersion) + true + $(SnkFile) + true + Latest + + + + + + +