How to use Msbuild.Community.Tasks.Version in csproj file

I want to use VersionTask from MSBuild Community Tasks to set the calculation type of Revision. However, I hardly understand how to actually include a task in my csproj file.

The project has AssemblyInfo.cs, which has the following attribute:

[assembly: AssemblyVersion("3.2.5.*")] 

What I want to do is to redo the processing of the Revision processing with my own custom processing.

I put the custom Version task in the csproj file as follows:

 <UsingTask TaskName="MyCo.Build.Tasks.Version" AssemblyFile="$(SolutionDir)\..\Build\.build\MyCo.Build.Tasks.dll" /> 

The actual task is then called as follows:

  <Target Name="BeforeBuild"> <Message Text="Setting Revision Number to $(BuildNumber)" /> <MyCo.Build.Tasks.Version RevisionType="BuildServerNumber" Revision="$(BuildNumber)" /></Target> 

I see the target BeforeBuild being invoked due to the Message task, but the exe file still has the standard generated numbering as follows: File version: 3.2.5.27547

I was expecting something like 3.2.5.111 (build number passed to MSBuild as a parameter).

Since the Version task overrides the default processing of the "*" value for version 1, I don’t think it is necessary to actually modify the AssemblyInfo.cs file.

Do I need to pass the output value from the Version task to the MSBuild parameter? Do I really need to use the AssemblyVersion task to update the values ​​in the file?

Obviously, I'm trying not to modify AssemblyInfo.cs, I just want to override version number handling.

Can anyone advise?

EDIT: I just found the following usage example in a chm file from the installer, which partially answers my question.

  <Version BuildType="Automatic" RevisionType="Automatic" Major="1" Minor="3" > <Output TaskParameter="Major" PropertyName="Major" /> <Output TaskParameter="Minor" PropertyName="Minor" /> <Output TaskParameter="Build" PropertyName="Build" /> <Output TaskParameter="Revision" PropertyName="Revision" /> </Version> <Message Text="Version: $(Major).$(Minor).$(Build).$(Revision)"/> 

However, when I run the assembly, I can output the generated version of the assembly to the Message task, but the exe file still has the default version, as before

+4
source share
2 answers

I have permission for this here: How to override version number

In the end, I had to actually update the AssemblyInfo file for each project during the build. Therefore, on the build server (TeamCity), I placed the code that I need in the Microsoft.Common.targets file so that it is not required in every advertisement, and then passed the release number and TeamCity build number for each build task.

+2
source

Revision is the number of days from January 1, 2000, when you set it to Automatic - you can specify your own "StartDate" if you want.

0
source

Source: https://habr.com/ru/post/1483614/


All Articles