【问题标题】:How to Publish a ClickOnce application with Azure DevOps Pipeline on different environments?如何在不同环境中使用 Azure DevOps Pipeline 发布 ClickOnce 应用程序?
【发布时间】:2019-11-12 03:53:32
【问题描述】:

我尝试了几天来使用 Azure DevOps Pipeline 发布我的 ClickOnce 应用程序。在详细介绍之前,我想从发布视图中执行以下操作:

我从一个工件和 2 个发布阶段开始,在我的暂存阶段使用暂存变量修改 config.deploy 文件,并在我的生产阶段使用生产变量修改 config.deploy 文件。部署工作正常,但由于哈希检查系统,应用程序安装无法正常工作。

所以我决定用 2 个工件创建 2 个构建。我在第一次构建时将经典 drop 重命名为 drop_staging,在第二次构建时将其重命名为 drop_production。我希望构建系统 (MSBuild) 能够在构建和发布过程中选择正确的 app.Debug.config 然后 app.Release.config 文件。

这是我的构建定义

这是我的构建参数

/target:publish 
/p:ApplicationVersion=$(Build.BuildNumber) 
/p:PublishURL=http://app-staging.example.com/   
/p:UpdateEnabled=true  
/p:UpdateMode=Foreground  
/p:ProductName="App Staging" 
/p:OutputPath="$(build.ArtifactStagingDirectory)\Publish\\"

配置设置为 Staging 用于第一次构建,然后设置为 Production 用于第二次构建。当然,我在 Visual Studio 中有 StagingProduction 构建定义。我的项目中有一个app.configapp.Staging.configapp.Production.config

我不能简单地在构建后添加一个任务来转换我的配置文件,因为我不会尊重哈希。我应该想办法让我的构建使用正确的 XML 转换配置文件。我没有看到任何其他解决方案,或者可能在构建之前应用此转换?是否可以?你的解决方案是什么?

【问题讨论】:

    标签: azure-devops clickonce azure-pipelines


    【解决方案1】:

    最后我可以通过在构建之前添加文件转换来解决这个问题。

    如果您需要更多帮助,请参阅我的 YAML 转换详细信息

    steps:
    
    - task: FileTransform@1
    
      displayName: 'File Transform: '
    
      inputs:
    
        folderPath: App.Example
    
        enableXmlTransform: true
    
        xmlTransformationRules: '-transform **\*.Staging.config -xml **\*.config'
    
        fileType: xml
    
    
    #Your build pipeline references the ‘BuildPlatform’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
    
    
    
    steps:
    
    - task: VSBuild@1
    
      displayName: 'Build solution'
    
      inputs:
    
        solution: Example.sln
    
        msbuildArgs: '/target:publish /p:ApplicationVersion=$(Build.BuildNumber) /p:PublishURL=http://staging.example.com/   /p:UpdateEnabled=true  /p:UpdateMode=Foreground  /p:ProductName="App Staging" /p:OutputPath="$(build.ArtifactStagingDirectory)\Publish\\"'
    
        platform: '$(BuildPlatform)'
    
        configuration: Staging
    

    【讨论】:

    • 太棒了!感谢您在此处分享您的解决方案,您可以接受它作为答案,这样它可以帮助遇到相同问题的其他社区成员,我们可以归档这个帖子,谢谢。
    • 非常感谢这篇文章拯救了我的一天!
    • 首先没看懂示例代码的内容。但是这里有一篇关于转换细节的好文章File transforms and variable substitution reference
    • 事实上,Azure 上的很多变化。这不再是最新的了。
    【解决方案2】:

    要添加到构建解决方案阶段,您可以在 msbuildArgs 上使用如下所示的 Visual Studio 发布配置文件。请注意,这不会为您执行版本递增

    - task: VSBuild@1
      displayName: 'Publish Project'
      inputs:
        solution: '$(projectSolution)'
        msbuildArgs: '/target:publish /p:ApplicationRevision=$(applicationRevision) /p:PublishProfile="Application/PublishProfiles/HerbalPublishProfile.pubxml" /p:PublishDir="$(build.ArtifactStagingDirectory)\Publish\\"'
        platform: '$(buildPlatform)'
        configuration: '$(buildConfiguration)'
        msbuildArchitecture: x64
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-26
      • 2020-09-14
      • 2022-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-15
      相关资源
      最近更新 更多