Skip to content

Commit

Permalink
Use reference assemblies generated by dotnet (PowerShell#19302)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapatwardhan authored and daxian-dbw committed Apr 7, 2023
1 parent 1d3bad9 commit ac5cfc6
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 40 deletions.
55 changes: 26 additions & 29 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2032,8 +2032,11 @@ Path to source folder containing Windows framework dependent assemblies.
.PARAMETER LinuxFxdBinPath
Path to source folder containing Linux framework dependent assemblies.
.PARAMETER GenAPIToolPath
Path to the GenAPI.exe tool.
.PARAMETER RefAssemblyPath
Path to the reference assemblies.
.PARAMETER CGManifestPath
Path to the CGManifest.json file.
#>
function New-ILNugetPackageSource
{
Expand All @@ -2055,10 +2058,11 @@ function New-ILNugetPackageSource
[string] $LinuxFxdBinPath,

[Parameter(Mandatory = $true)]
[string] $GenAPIToolPath,
[string] $RefAssemblyPath,

[Parameter(Mandatory = $true)]
[string] $CGManifestPath

)

if (! $Environment.IsWindows)
Expand Down Expand Up @@ -2091,11 +2095,8 @@ function New-ILNugetPackageSource
"Microsoft.WSMan.Management.dll",
"Microsoft.WSMan.Runtime.dll")

$refBinPath = New-TempFolder
$SnkFilePath = "$RepoRoot\src\signing\visualstudiopublic.snk"

New-ReferenceAssembly -linux64BinPath $LinuxFxdBinPath -RefAssemblyDestinationPath $refBinPath -RefAssemblyVersion $PackageVersion -SnkFilePath $SnkFilePath -GenAPIToolPath $GenAPIToolPath

if (! (Test-Path $PackagePath)) {
$null = New-Item -Path $PackagePath -ItemType Directory
}
Expand All @@ -2109,7 +2110,7 @@ function New-ILNugetPackageSource

#region ref
$refFolder = New-Item (Join-Path $filePackageFolder.FullName "ref/$script:netCoreRuntime") -ItemType Directory -Force
CopyReferenceAssemblies -assemblyName $fileBaseName -refBinPath $refBinPath -refNugetPath $refFolder -assemblyFileList $fileList -winBinPath $WinFxdBinPath
CopyReferenceAssemblies -assemblyName $fileBaseName -refBinPath $RefAssemblyPath -refNugetPath $refFolder -assemblyFileList $fileList -winBinPath $WinFxdBinPath
#endregion ref

$packageRuntimesFolderPath = $packageRuntimesFolder.FullName
Expand Down Expand Up @@ -2174,10 +2175,6 @@ function New-ILNugetPackageSource
}
$deps = New-FileDependencies -FileBaseName $fileBaseName -PackageVersion $PackageVersion
New-CGManifest -FilePath (Join-Path -Path $CGManifestPath -ChildPath "CGManifest.json") -Dependencies $deps

if (Test-Path $refBinPath) {
Remove-Item $refBinPath -Recurse -Force -ErrorAction SilentlyContinue
}
}

<#
Expand Down Expand Up @@ -2264,33 +2261,33 @@ function CopyReferenceAssemblies

$supportedRefList = @(
"Microsoft.PowerShell.Commands.Utility",
"Microsoft.PowerShell.ConsoleHost")
"Microsoft.PowerShell.ConsoleHost",
"Microsoft.PowerShell.Commands.Management",
"Microsoft.PowerShell.Commands.Security",
"System.Management.Automation"
)

switch ($assemblyName) {
{ $_ -in $supportedRefList } {
$refDll = Join-Path -Path $refBinPath -ChildPath "$assemblyName.dll"
$refDoc = Join-Path -Path $refBinPath -ChildPath "$assemblyName.xml"
Copy-Item $refDll, $refDoc -Destination $refNugetPath -Force
Write-Log "Copied file '$refDll' and '$refDoc' to '$refNugetPath'"
}

"Microsoft.PowerShell.SDK" {
foreach ($asmFileName in $assemblyFileList) {
$refFile = Join-Path -Path $refBinPath -ChildPath $asmFileName
if (Test-Path -Path $refFile) {
$refDoc = Join-Path -Path $refBinPath -ChildPath ([System.IO.Path]::ChangeExtension($asmFileName, "xml"))
Copy-Item $refFile, $refDoc -Destination $refNugetPath -Force
Write-Log "Copied file '$refFile' and '$refDoc' to '$refNugetPath'"
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($asmFileName)

if ($fileName -in $supportedRefList) {
$refFile = Join-Path -Path $refBinPath -ChildPath $asmFileName
if (Test-Path -Path $refFile) {
$refDoc = Join-Path -Path $refBinPath -ChildPath ([System.IO.Path]::ChangeExtension($asmFileName, "xml"))
Copy-Item $refFile, $refDoc -Destination $refNugetPath -Force
Write-Log "Copied file '$refFile' and '$refDoc' to '$refNugetPath'"
}
}
}
}

default {
$ref_SMA = Join-Path -Path $refBinPath -ChildPath System.Management.Automation.dll
$ref_doc = Join-Path -Path $refBinPath -ChildPath System.Management.Automation.xml
$self_ref_doc = Join-Path -Path $winBinPath -ChildPath "$assemblyName.xml"
Copy-Item $ref_SMA, $ref_doc, $self_ref_doc -Destination $refNugetPath -Force
Write-Log "Copied file '$ref_SMA' and '$ref_doc' to '$refNugetPath'"
$refDll = Join-Path -Path $refBinPath -ChildPath "$assemblyName.dll"
$refDoc = Join-Path -Path $refBinPath -ChildPath "$assemblyName.xml"
Copy-Item $refDll, $refDoc -Destination $refNugetPath -Force
Write-Log "Copied file '$refDll' and '$refDoc' to '$refNugetPath'"
}
}
}
Expand Down
66 changes: 64 additions & 2 deletions tools/releaseBuild/azureDevOps/templates/nuget-pkg-sbom.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ parameters:
- name: PackagePath
- name: WinFxdPath
- name: LinuxFxdPath
- name: GenAPIToolPath
- name: ListOfFiles
type: object
default:
Expand All @@ -20,6 +19,69 @@ parameters:
- System.Management.Automation.dll

steps:

- pwsh: |
Import-Module "$env:REPOROOT/build.psm1" -Force
Start-PSBootstrap
$sharedModules = @('Microsoft.PowerShell.Commands.Management',
'Microsoft.PowerShell.Commands.Utility',
'Microsoft.PowerShell.ConsoleHost',
'Microsoft.PowerShell.Security',
'System.Management.Automation'
)
$winOnlyModules = @('Microsoft.Management.Infrastructure.CimCmdlets',
'Microsoft.PowerShell.Commands.Diagnostics',
'Microsoft.PowerShell.CoreCLR.Eventing',
'Microsoft.WSMan.Management',
'Microsoft.WSMan.Runtime'
)
$refAssemblyFolder = Join-Path '$(System.ArtifactsDirectory)' 'RefAssembly'
$null = New-Item -Path $refAssemblyFolder -Force -Verbose -Type Directory
Start-PSBuild -Clean -Runtime linux-x64 -Configuration Release
$sharedModules | Foreach-Object {
$refFile = Get-ChildItem -Path "$env:REPOROOT\src\$_\obj\Release\net8.0\refint\$_.dll"
Write-Verbose -Verbose "RefAssembly: $refFile"
Copy-Item -Path $refFile -Destination "$refAssemblyFolder\$_.dll" -Verbose
$refDoc = "$env:REPOROOT\src\$_\bin\Release\net8.0\$_.xml"
if (-not (Test-Path $refDoc)) {
Write-Warning "$refDoc not found"
Get-ChildItem -Path "$env:REPOROOT\src\$_\bin\Release\net8.0\" | Out-String | Write-Verbose -Verbose
}
else {
Copy-Item -Path $refDoc -Destination "$refAssemblyFolder\$_.xml" -Verbose
}
}
Start-PSBuild -Clean -Runtime win7-x64 -Configuration Release
$winOnlyModules | Foreach-Object {
$refFile = Get-ChildItem -Path "$env:REPOROOT\src\$_\obj\Release\net8.0\refint\*.dll"
Write-Verbose -Verbose 'RefAssembly: $refFile'
Copy-Item -Path $refFile -Destination "$refAssemblyFolder\$_.dll" -Verbose
$refDoc = "$env:REPOROOT\src\$_\bin\Release\net8.0\$_.xml"
if (-not (Test-Path $refDoc)) {
Write-Warning "$refDoc not found"
Get-ChildItem -Path "$env:REPOROOT\src\$_\bin\Release\net8.0" | Out-String | Write-Verbose -Verbose
}
else {
Copy-Item -Path $refDoc -Destination "$refAssemblyFolder\$_.xml" -Verbose
}
}
Get-ChildItem $refAssemblyFolder -Recurse | Out-String | Write-Verbose -Verbose
# Set RefAssemblyPath path variable
$vstsCommandString = "vso[task.setvariable variable=RefAssemblyPath]${refAssemblyFolder}"
Write-Host "sending " + $vstsCommandString
Write-Host "##$vstsCommandString"
displayName: Build reference assemblies

- ${{ each value in parameters.ListOfFiles }}:
- pwsh: |
$FileName = '${{ value }}'
Expand All @@ -45,7 +107,7 @@ steps:
Import-Module -Name $env:REPOROOT\build.psm1
Import-Module -Name $env:REPOROOT\tools\packaging
Find-DotNet
New-ILNugetPackageSource -File $FileName -PackagePath '${{ parameters.PackagePath }}' -PackageVersion '${{ parameters.PackageVersion }}' -WinFxdBinPath '${{ parameters.WinFxdPath }}' -LinuxFxdBinPath '${{ parameters.LinuxFxdPath }}' -GenAPIToolPath '${{ parameters.GenAPIToolPath }}' -CGManifestPath $CGManifestPath
New-ILNugetPackageSource -File $FileName -PackagePath '${{ parameters.PackagePath }}' -PackageVersion '${{ parameters.PackageVersion }}' -WinFxdBinPath '${{ parameters.WinFxdPath }}' -LinuxFxdBinPath '${{ parameters.LinuxFxdPath }}' -CGManifestPath $CGManifestPath -RefAssemblyPath $(RefAssemblyPath)
displayName: 'Create NuGet Package source for single file'
- template: Sbom.yml@ComplianceRepo
Expand Down
9 changes: 0 additions & 9 deletions tools/releaseBuild/azureDevOps/templates/nuget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ jobs:
archiveFilePatterns: '$(System.ArtifactsDirectory)/packages/powershell-*-linux-x64-fxdependent.tar.gz'
destinationFolder: '$(linuxFxdPath)'

- task: PkgESInstallNuGetToolsPackage@10
displayName: 'Install package Microsoft.DotNet.BuildTools.GenAPI'
inputs:
packageName: Microsoft.DotNet.BuildTools.GenAPI
packageVersion: '1.0.0-beta-00081'
packageSources: 'https://nuget.org/api/v2'
installRoot: '$(GenAPIToolPath)'

- template: SetVersionVariables.yml
parameters:
ReleaseTagVar: $(ReleaseTagVar)
Expand All @@ -130,7 +122,6 @@ jobs:
PackagePath: $(PackagePath)
WinFxdPath: $(winFxdPath)
LinuxFxdPath: $(linuxFxdPath)
GenAPIToolPath: $(GenAPIToolPath)

- pwsh: |
Get-ChildItem $(linuxFxdPath)
Expand Down

0 comments on commit ac5cfc6

Please sign in to comment.