Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

wpf - How to create two versions of MSIX package (QAPROD) and deploy on the same machine?

What should I change so I can install both QA & Prod versions of app on the same machine?

# 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 Kits10in10.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: '*'
    

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In above yaml pipeline. There are two powershell tasks PowerShell Script - Update ApplicationRevision to update the ApplicationRevision. The second powershell task will override the first one. You can use conditions for above powershell tasks, so that only one of them will run in each strategy. See below:

- 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>.*$"
           ....
        

Add condtions to powershell task to make them run in their strategy.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...