Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClickOnce deployment minumum required version auto-increment with MSBuild

We current do manual builds/publish from Visual Studio 2010 and we require users to always be running the latest version (check before startup and minimum required version set). I am working on scripting our deployment out and have no issues using msbuild to build/publish. However, I have not found a way to auto-increment the minimum required version when msbuild runs. What are my options to automatically bump this when publishing via msbuild?

I did see quite a few articles on this topic here, but they seemed to be specific to VS and not MSBuild.

like image 713
UnhandledExcepSean Avatar asked Jan 19 '12 16:01

UnhandledExcepSean


1 Answers

Updating the MinimumRequiredVersion Automatically

Introduction to Project Editor

  1. In Solution Explorer, right click on your project and select unload project.

    Screenshot of Unloading

  2. Once the project has become unavailable, right click again and select edit <project_name>.<lang> proj.

    Screenshot of Opening Editor

Introduction to MSBuild

  1. Properties use key/value pairs to extract information

    • Using the property name as an alias, you can use $(OutputPath) to obtain the value for the element <OutputPath>.\bin</OutputPath>
  2. We’ll use the following properties generated for a ClickOnce deployment

    <MinimumRequiredVersion>1.0.0.6</MinimumRequiredVersion>
    <ApplicationRevision>7</ApplicationRevision>
    <ApplicationVersion>1.0.0.%2a</ApplicationVersion>
    
  3. MSBuild Tasks can be specified in the project (*.proj) file and invoked during a build event.

    • FormatVersion is a built-in task for .NET 4.0 and later that formats the ApplicationVersion and ApplicationRevision into a single version number.

Implementation

  1. Copy and Paste the following code into the opened project file as a child element to the root <Project> element.

    <Target Name="AutoSetMinimumRequiredVersion" BeforeTargets="GenerateDeploymentManifest">
      <FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
        <Output PropertyName="MinimumRequiredVersion" TaskParameter="OutputVersion"  />
      </FormatVersion>
      <FormatVersion Version="$(ApplicationVersion)" Revision="$(ApplicationRevision)">
        <Output PropertyName="_DeploymentBuiltMinimumRequiredVersion" TaskParameter="OutputVersion"  />
      </FormatVersion>
    </Target>
    

    This code will take ApplicationVersion and ApplicationRevision as parameters in the Format Version task and will save the output by overwriting the MinimumRequiredVersion with the full publish version.

  2. Save and reload your project. Every ClickOnce deployment will now automatically update to the most recently published version.


Many thanks to Kev for their answer which I have basically rehashed here with a little bit of added clarification for any beginners. Here's a blog post I made about the issue that expands even more on my answer here.

like image 119
KyleMit Avatar answered Sep 22 '22 12:09

KyleMit