Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to publish ClickOnce application using build definition?

I'm currently publishing the ClickOnce application manually by right clicking .csproj. Is there a way I can do the same from the solution directly so that I can use it with the build definition for continuous integration?

like image 514
Anidil Avatar asked Nov 25 '15 21:11

Anidil


1 Answers

You can't publish the ClickOnce application from solution directly, but you can build and publish ClickOnce application with both XAML build and vNext build, and use MSBuild argument “/target:publish” to make MSBuild create the ClickOnce publish folder. Here are two blogs with detailed steps to build and publish ClickOnce application:

Build and Publish a ClickOnce App using Team Build/VSO, please refer to blog: http://blogs.msdn.com/b/tfssetup/archive/2015/09/15/build-and-publish-a-clickonce-app-using-team-build-vso.aspx

Building ClickOnce apps using build vNext, please refer to blog: http://blogs.msdn.com/b/tfssetup/archive/2015/10/15/building-clickonce-apps-using-build-vnext.aspx

Assuming you are using XAML build, so I'd like to highlight the points in the blog with XAML build. To achieve build and publish a ClickOnce application using Team Build, you need to edit the XAML build definition with following steps:

  1. Set the publish path in the properties of the project, which would correspond to the destination. Then checkin your project to TFS.

  2. Create a copy of template TFVCTemplate.12.xaml to do customization. In order to make the build process get a few environment data, you need to:

    • Create two environment variables – DropLocation and WorkingDirectory.

    • Add two events of type GetEnvironmentVariable from the tool box. Add them any place you prefer within the flow.

    • Use the first to set the variable DropLocation with data “Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.DropLocation”.

    • Use the second variable to set the variable WorkingDirectory with data “Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.BuildDirectory”.

    • Create new argument of type DestinationLocation and set to In with type String. This would be used to hold the location (file location) where your end data is going to go.

The reason we are editing the XAML build definition is the way ClickOnce publishing is done by MsBuild. MSBuild publish doesn’t do the copy of files to the destination, it creates a folder within bin and puts the files there.

  1. As by default TFS copies the bin folder to the output drop location. But we need the app.publish folder. In order to find a way to take the published files from the publish folder. You need to:

    • Search for “Copy binaries to drop” activity within the template.

    • In the properties over write the existing source location(which would be the bin folder, like WorkingDirectory + "\src\Desktop\TeamAdmin\ClickOnceTest\ClickOnceTest) to something like this – WorkingDirectory + "\src\Desktop\TeamAdmin\ClickOnceTest\ClickOnceTest\bin\Debug\app.publish".

  2. Add an event CreateDirectory, to create the directory again. We can use the destination location variable we created before. And Copy the files from the drop location to the desired location.

  3. Now we can create a new build definition and enter the value for the DestinationLocation and the MSBuildArguments “/target:publish” and queue the build.

like image 56
Cece Dong - MSFT Avatar answered Nov 15 '22 04:11

Cece Dong - MSFT