azure-powershell-1/tools/PostBuildModuleAlc.ps1

95 строки
3.5 KiB
PowerShell
Исходник Обычный вид История

# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------
<#
.SYNOPSIS
Generate InitializeAssemblyLoadContext.ps1 and put it under output folder.
.PARAMETER ModuleFolder
The output folder for module, e.g. C:\azure-powershell\artifacts\Debug\Az.Compute
.PARAMETER AlcEntryAssembly
Entry assembly name of current module Assembly Load Context, e.g. "Azure."
.PARAMETER AlcRefAssembly
Assembly referenced by module entry assemblies, separated by ';', e.g. "Azure.Storage.Blobs;Azure.Storage.Common"
#>
param (
2021-09-28 09:29:19 +03:00
[Parameter(Mandatory = $true)]
[string]
$ModuleFolder,
2021-09-28 09:29:19 +03:00
[Parameter(Mandatory = $true)]
[string]
$AlcEntryAssembly,
2021-09-28 09:29:19 +03:00
[Parameter(Mandatory = $true)]
[string]
$AlcRefAssembly,
2021-09-28 09:29:19 +03:00
[Parameter(Mandatory = $true)]
[string]
$Configuration
)
$alcTemplate = @'
if($PSVersionTable.PSEdition -eq 'Core')
{
try {
$assemblyLoadContextFolder = [System.IO.Path]::Combine($PSScriptRoot, "..", "ModuleAlcAssemblies")
2021-09-28 09:29:19 +03:00
Write-Debug "Registering module AssemblyLoadContext for path: '$assemblyLoadContextFolder'."
[Microsoft.Azure.PowerShell.AuthenticationAssemblyLoadContext.AzAssemblyLoadContextInitializer]::RegisterModuleAssemblyLoadContext("%ASSEMBLY_LOAD_CONTEXT_ENTRY_ASSEMBLY%", $assemblyLoadContextFolder)
2021-09-28 09:29:19 +03:00
Write-Debug "AssemblyLoadContext registered."
} catch {
Write-Warning $_
}
}
'@
$alcTemplate = $alcTemplate.Replace("%ASSEMBLY_LOAD_CONTEXT_ENTRY_ASSEMBLY%", $AlcEntryAssembly)
$scriptPath = [System.IO.Path]::Combine($ModuleFolder, "PostImportScripts", "InitializeAssemblyLoadContext.ps1")
2021-09-28 09:29:19 +03:00
if (-not (Test-Path $scriptPath)) {
New-Item -ItemType File -Path $scriptPath -Force
}
$alcTemplate | Out-File -FilePath $scriptPath -Encoding utf8 -Force
$isReleaseConfiguration = $Configuration -eq 'Release'
$alcDestinationDir = [System.IO.Path]::Combine($ModuleFolder, "ModuleAlcAssemblies")
$entryAssemblyPath = [System.IO.Path]::Combine($ModuleFolder, $AlcEntryAssembly + ".dll")
2021-09-28 09:29:19 +03:00
if (-not (Test-Path $alcDestinationDir)) {
New-Item -ItemType Directory -Path $alcDestinationDir -Force
}
2021-09-28 09:29:19 +03:00
if ($isReleaseConfiguration) {
Move-Item -Path $entryAssemblyPath -Destination $alcDestinationDir -Force
}
2021-09-28 09:29:19 +03:00
else {
Copy-Item -Path $entryAssemblyPath -Destination $alcDestinationDir -Force #Move-Item cause test project build error: CS0006 metadata file AlcWrapper.dll could not be found
}
2021-09-28 09:29:19 +03:00
if (-not [System.String]::IsNullOrEmpty($AlcRefAssembly)) {
$refAssemblies = $AlcRefAssembly.Split(';')
$refAssemblies | ForEach-Object {
$refAssemblyPath = [System.IO.Path]::Combine($ModuleFolder, $_ + ".dll")
2021-09-28 09:29:19 +03:00
if ($isReleaseConfiguration) {
Move-Item -Path $refAssemblyPath -Destination $alcDestinationDir -Force
}
else {
Copy-Item -Path $refAssemblyPath -Destination $alcDestinationDir -Force
}
}
[Compute] Add-AzVhd Convenience Layer (#15994) * Add support for assemlby load context * Add sample code for supporting assembly load context in Compute module * Format mark down file * Refine assembly load context logic * Update analysis tool to support Assembly load context * Code refinement * Add System.Text.Encodings.Web as framework assembly during analysis * Merge with main branch * Fix static analysis issue * changelog * add-azvhd convenience layer * move all storage related calls to the AlcWrapper project * update * Update src/Compute/Compute/help/Add-AzVhd.md * create PSPageBlobClient.cs in alcWrapper and move content to it * suppress 'too many positional parameters' issue to avoid breaking change * Delete AzureStorageService.cs * Update PSPageBlobClient.cs * Add support for assemlby load context * Add sample code for supporting assembly load context in Compute module * Format mark down file * Refine assembly load context logic * Update analysis tool to support Assembly load context * Code refinement * Add System.Text.Encodings.Web as framework assembly during analysis * Merge with main branch * Fix static analysis issue * changelog * add-azvhd convenience layer * move all storage related calls to the AlcWrapper project * update * create PSPageBlobClient.cs in alcWrapper and move content to it * Update src/Compute/Compute/help/Add-AzVhd.md * suppress 'too many positional parameters' issue to avoid breaking change * Delete AzureStorageService.cs * Update PSPageBlobClient.cs * remove storage component from get-azvm * Update ChangeLog.md * breaking change warning removed Co-authored-by: Erich(Renyong) Wang <eriwan@microsoft.com> Co-authored-by: erich-wang <erich.wang@outlook.com> Co-authored-by: Yeming Liu <11371776+isra-fel@users.noreply.github.com>
2021-11-16 10:11:43 +03:00
}