如何创建两个版本的MSIX包(QA\PROD)并在同一台机器上部署



为了安装QA和amp;在同一台机器上生产应用程序的版本?

# Starter pipeline
# Start with a minimal pipeline that you can customize to build and deploy your code.
# Add steps that build, run tests, deploy, and more:
# https://aka.ms/yaml
# Build defintion variables to define:
# AgentPool = BUILD2_CD
# Env1 = Dev or  UAT
# Env2 = QA or PROD 
# BuildVersion = 1.0.0.1 , example

trigger:
- none
pool:
#name: BUILD2
name: $(AgentPool)
demands:
- npm
- msbuild
- visualstudio
- vstest
- DotNetFramework
variables:
BuildPlatform: 'x64'
BuildConfiguration: 'release'
major: 2
minor: 0
build: 0
revision: $[counter('rev', 0)]
BuildOutputFolder: 'Runtime'
isDevelop: $[eq(variables['Env1'], 'DEV')] # runtime expression
CertExportDir: '$(Build.ArtifactStagingDirectory)AppxPackages$(MsixPackageRootFolderName)'
CertFilePath: '$(Build.ArtifactStagingDirectory)AppxPackages$(MsixPackageRootFolderName)PIE21stMortgage.pfx'
MsixPackageRootFolderName: 'DotnetCoreInstaller_$(BuildVersion)_$(BuildPlatform)_Test'

jobs:
- job: Phase1 
displayName: "Client DotnetCore Installer "
timeoutInMinutes: 50 
strategy:
maxParallel: 2
matrix: 
ENV_1:
Multiplier: $(Env1)
ENV_2:
Multiplier: $(Env2)

steps:
- task: PowerShell@2
displayName: 'REST API : Update Build Version '
inputs:
targetType: filePath
filePath: ./Automation/RestApi/RestApiVersionCounter.ps1
continueOnError: true
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
- task: PowerShell@1
displayName: 'PowerShell Script - Update ApplicationRevision '
inputs:
scriptType: inlineScript
inlineScript: |
$fileVersion =  $Env:BuildVersion.Split(".")
$last3Numbers = [int]$fileVersion[3].ToString()

$path = "$(Build.SourcesDirectory)/DotnetCore/DotnetCore.csproj"
$word = "<ApplicationRevision>.*$"
$replacement = "<ApplicationRevision>" + $last3Numbers + "</ApplicationRevision>"
$text = get-content $path 
$newText = $text -replace $word,$replacement
$newText > $path
(Get-Content $path) | Out-File -encoding UTF8 $path

- task: PowerShell@1
displayName: 'PowerShell Script - Update ApplicationVersion'
inputs:
scriptType: inlineScript
inlineScript: |
$path = "$(Build.SourcesDirectory)/DotnetCore/DotnetCore.csproj"
$word = "<ApplicationVersion>.*$"
$replacement = "<ApplicationVersion>" + $Env:BuildVersion + "</ApplicationVersion>"
$text = get-content $path 
$newText = $text -replace $word,$replacement
$newText > $path
(Get-Content $path) | Out-File -encoding UTF8 $path

- task: PowerShell@1
displayName: 'PowerShell Script - Set BuildOutputFolder variable'
inputs:
scriptType: inlineScript
inlineScript: |
switch ($env:Multiplier) {
"PROD" {
$folderName = "Release"
}
"UAT" {
$folderName = "UATRelease"
}
"DEV" {
$folderName = "Debug"
}
"QA" {
$folderName = "QARelease"
}
}

Write-Host "Setting 'BuildOutputFolder' variable to: $folderName" -Verbose
Write-Host ("##vso[task.setvariable variable=BuildOutputFolder;]$folderName") -Verbose

- task: FileTransform@1
displayName: 'File Transform: App.config'
inputs:
folderPath: DotnetCoreFolder
enableXmlTransform: true
xmlTransformationRules: -transform **App.$(BuildOutputFolder).config -xml **App.config
fileType: xml  
- powershell: |
# Update appxmanifest. This must be done before the build.
[xml]$manifest= get-content ".DotnetCoreInstallerPackage.appxmanifest"
# $manifest.Package.Identity.Version = "$(major).$(minor).$(build).$(revision)"    
$manifest.Package.Identity.Version = "$(BuildVersion)"
$manifest.Package.Applications.Application.VisualElements.DisplayName = "DotnetCore.$(Multiplier)"  
$manifest.save("DotnetCoreInstaller/Package.appxmanifest")
displayName: 'Version Package Manifest'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
projects: '.DotnetCoreDotnetCore.csproj'
- task: CopyFiles@1
displayName: 'Copy PIE21stMortgage.pfx File to: $(build.artifactstagingdirectory)'
inputs:
SourceFolder: D:versionsCERT
Contents: PIE21stMortgage.pfx
TargetFolder: $(CertExportDir)
- task: MSBuild@1
inputs:
solution: DotnetCoreInstaller/DotnetCoreInstaller.wapproj
platform: $(buildPlatform)
configuration: $(buildConfiguration)
msbuildArguments: '/p:OutputPath=NonPackagedApp
/p:UapAppxPackageBuildMode=SideLoadOnly  
/p:AppxBundle=Never 
/p:GenerateAppInstallerFile=True 
/p:AppInstallerUri=\sharesIntranet$(Multiplier)DotnetCore 
/p:AppInstallerCheckForUpdateFrequency=OnApplicationRun 
/p:AppInstallerUpdateFrequency=1
/p:AppxPackageOutput=$(Build.ArtifactStagingDirectory)DesktopApp.msix 
/p:AppxPackageSigningEnabled=false
/p:PublishAssemblyName=$(Multiplier)
/p:ProductName=$(Multiplier)'
displayName: 'Package the App'
- script: '"C:Program Files (x86)Windows Kits10bin10.0.18362.0x64signtool"
sign /fd SHA256 /f $(CertExportDir)/$(CertName) /p "$(CertPassword)" $(Build.ArtifactStagingDirectory)DesktopApp.msix'
displayName: 'Sign MSIX Package'
- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: MSIX Package'
inputs:
PathtoPublish: $(Build.ArtifactStagingDirectory)
ArtifactName: ClientDotnetCoreInstaller$(Multiplier)

- task: CopyFiles@1
inputs:
SourceFolder: '$(Build.ArtifactStagingDirectory)'
Contents: '**'
TargetFolder: '\sharesIntranet$(Multiplier)DotnetCore'
OverWrite: true

- task: DeleteFiles@1
displayName: 'Delete PIE21stMortgage.pfx'
inputs:
SourceFolder: '\21stmortgagesharesIntranet$(Multiplier)DotnetCoreAppxPackages$(MsixPackageRootFolderName)'
Contents: 'PIE21stMortgage.pfx'    

- task: DeleteFiles@1
displayName: 'Delete files from $(Build.SourcesDirectory) '
condition: always()
continueOnError: True
enabled: False
inputs:
SourceFolder: $(Build.SourcesDirectory)
Contents: '*'

在yaml管道上方。有两个powershell任务PowerShell Script - Update ApplicationRevision用于更新ApplicationRevision。第二个powershell任务将覆盖第一个任务。您可以对上述powershell任务使用条件,以便在每个策略中只运行其中一个。见下文:

- task: PowerShell@1
displayName: 'PowerShell Script - Update ApplicationRevision '
condtion: eq(variables['Multiplier'],'QA')
inputs:
scriptType: inlineScript
inlineScript: |
$fileVersion =  $Env:BuildVersion.Split(".")
$last3Numbers = [int]$fileVersion[3].ToString()
...


- task: PowerShell@1
displayName: 'PowerShell Script - Update ApplicationVersion'
condtion: eq(variables['Multiplier'],'Prod')
inputs:
scriptType: inlineScript
inlineScript: |
$path = "$(Build.SourcesDirectory)/DotnetCore/DotnetCore.csproj"
$word = "<ApplicationVersion>.*$"
....

条件添加到powershell任务中,使其在策略中运行。

相关内容

最新更新