How can I get MSBuild to increase the version number of the publish publication version of ClickOnce on the build server?

We have an NAnt script that is checked from CVS and then runs MSBuild to publish the application. The problem is that we must remember to always increase the version in Visual Studio.

We have the opportunity to automatically increase this value when publishing, but this will be erased during the next control, and I would prefer not to get the script assembly to check the project file.

Is there an easy way to do this?

+7
source share
3 answers

In the end, I did this using NAnt xmlpoke, so for the version we ended up with 20.0.dayofyear.hourminute - this is mostly unique in assemblies.

There is no need for custom tasks, but a later version of MSBuild also has pokexml, so it can work with that.

<target name="pokerevision" depends="init"> <property name="projectname" value="MyProject.GUI" /> <!-- This is a bit flawed because 231 could mean 02:31 or 23:01, but we never build before 3 am. --> <property name="app.revision" value="${datetime::get-hour(datetime::now())}${datetime::get-minute(datetime::now())}" /> <echo message="revision: ${app.revision}" /> <xmlpoke file="${Solution.Path}\${projectname}\${projectname}.csproj" xpath="//x:Project/x:PropertyGroup[1]/x:ApplicationRevision" value="${app.revision}" > <namespaces> <namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" /> </namespaces> </xmlpoke> <property name="app.version" value="20.0.${datetime::get-day-of-year(datetime::now())}.${app.revision}" /> <echo message="version: ${app.version}" /> <xmlpoke file="${Solution.Path}\${projectname}\${projectname}.csproj" xpath="//x:Project/x:PropertyGroup[1]/x:ApplicationVersion" value="${app.version}" > <namespaces> <namespace prefix="x" uri="http://schemas.microsoft.com/developer/msbuild/2003" /> </namespaces> </xmlpoke> </target> 
+2
source

MinimumRequiredVersion Update Automatically

Introduction to Project Editor

  • In Solution Explorer, right-click on your project and select Upload Project.

    Screenshot of Unloading

  • Once the project becomes 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 retrieve information

    • Using the property name as an alias, you can use $(OutputPath) to get the value for the <OutputPath>.\bin</OutputPath>
  2. Make good use of the following properties generated for 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 file (* .proj) and called during the build event.

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

Implementation

  1. Copy and paste the following code into the open project file as a child of the <Project> root 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 save the result by overwriting MinimumRequiredVersion with the full version of the publication.

  2. Save and reload the project. Each ClickOnce deployment is now automatically updated to the latest published version.


Many thanks to Kev for their answer , which I basically rephrased here with a little added clarification for beginners. Here 's a blog post I made a question that further expands my answer here.

+10
source

You have several options, here are two:

Edit
Sorry, I misunderstood your question.

See Jason Stanroom's accepted answer here:
How do I get the ClickOnce publication version according to the version of the AssemblyInfo.cs file?

+1
source

All Articles