Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Publish a ClickOnce application with Azure DevOps Pipeline on different environments?

I try for several days now to publish my ClickOnce application with Azure DevOps Pipeline. Before going in detail here is what I would like to do from my release view:

enter image description here

I started with one artifact and 2 release stage modifying the config.deploy file with staging variables during my Staging stage and modifying the config.deploy file with production variables during my Production stage. Deployment was working fine but installation of application was not working because of hash check system.

So I decided to create 2 builds with 2 artifacts. I renamed the classic drop by a drop_staging during my first build and drop_production for my second build. I was hoping the build system (MSBuild) was able to select the correct app.Debug.config then app.Release.config file during the build and publish process.

Here is my build definition

Build definition

Here is my build arguments

/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\\"

Configuration is set to Staging for first build then on Production for second build. I have, of course, a Staging and Production build definition in visual Studio. I have an app.config with app.Staging.config and app.Production.config in my project.

I cannot simply add a task to transform my config file after the build because I will not respect the hash. I should find a way to say to my build to use the correct XML transformation config file. I don't see any other solution or maybe applying this transformation before the build? Is it possible? What are your solutions?

like image 996
Bastien Vandamme Avatar asked Nov 12 '19 03:11

Bastien Vandamme


People also ask

How do I publish my ClickOnce application?

Publishing with ClickOnce. In Solution Explorer, right-click the project and choose Publish (or use the Build > Publish menu item).

How do you set the environment on an azure pipeline?

There are 3 ways to get an environment variable value on your build server: Set the value on the build machine. Set the value in the YAML build script. Set the value in Azure DevOps for the build pipeline definition.


1 Answers

finally I could solve this by adding a file transform before my build.

enter image description here

In case you need more help here is my YAML detail for transformation

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
like image 177
Bastien Vandamme Avatar answered Oct 27 '22 06:10

Bastien Vandamme