Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the ClickOnce Publish version to match the AssemblyInfo.cs File version?

Every time I publish the application in ClickOnce I get get it to update the revision number by one. Is there a way to get this change automatically to change the version number in AssemblyInfo.cs file (all our error reporting looks at the Assembly Version)?

like image 641
Kris Erickson Avatar asked Sep 04 '08 18:09

Kris Erickson


People also ask

How do I get AssemblyInfo CS go?

It is located under the folder "Properties". AssemblyInfo. cs file also get created, when you create any Web Application project.

What is AssemblyInfo file?

AssemblyInfo. cs contains information about your assembly, like name, description, version, etc. You can find more details about its content reading the comments that are included in it.


3 Answers

We use Team Foundation Server Team Build and have added a block to the TFSBuild.proj's AfterCompile target to trigger the ClickOnce publish with our preferred version number:

<MSBuild Projects="$(SolutionRoot)\MyProject\Myproject.csproj"
         Properties="PublishDir=$(OutDir)\myProjectPublish\;
                     ApplicationVersion=$(PublishApplicationVersion);
                     Configuration=$(Configuration);Platform=$(Platform)"
         Targets="Publish" />

The PublishApplicationVersion variable is generated by a custom MSBuild task to use the TFS Changeset number, but you could use your own custom task or an existing solution to get the version number from the AssemblyInfo file.

This could theoretically be done in your project file (which is just an MSBuild script anyway), but I'd recommend against deploying from a developer machine.

I'm sure other continuous integration (CI) solutions can handle this similarly.


Edit: Sorry, got your question backwards. Going from the ClickOnce version number to the AssemblyInfo file should be doable. I'm sure the MSBuild Community Tasks (link above) have a task for updating the AssemblyInfo file, so you'd just need a custom task to pull the version number from the ClickOnce configuration XML.

However, you may also consider changing your error reporting to include the ClickOnce publish version too:

if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
{
    Debug.WriteLine(System.Deployment.Application.ApplicationDeployment.
                                                        CurrentDeployment.CurrentVersion);
}
like image 82
Jason Stangroome Avatar answered Oct 11 '22 17:10

Jason Stangroome


I implemented this recently using some custom tasks. An issue I found with implementing this with ClickOnce is that all your DLL files are updated. This causes the ClickOnce update to download all the application files every update. This bypasses on of the nice features of the ClickOnce deployment where only the modified files are re-downloaded in an update.

Just something to think about when implementing something like this with ClickOnce.

like image 21
Todd Avatar answered Oct 11 '22 16:10

Todd


Steps:

  1. Use external incrementing version number (if you leverage a continuous integration server like CruiseControl.NET, then it comes from the build label).
  2. Use GlobalVersionInfo.cs (file link-referenced by all projects in your solution) to hold the current version and update it on the build with the AssemblyInfo task from the MSBuild Community tasks.
  3. Script Mage command-line tool from the .NET SDK to update the ClickOnce manifest, using the same version (see the -v and -mv switches).

BTW, a nice bonus is that, whenever you automatically publish a newer ClickOnce deployment version via the integration script, if you also specify the minimal version to mage.exe (same as version), then every user will be updated automatically on the next application launch.

like image 35
Rinat Abdullin Avatar answered Oct 11 '22 17:10

Rinat Abdullin