user1902346
user1902346

Reputation: 819

msbuild and file version change

I am trying to make the following build scenario in my environment (using Jenkins and git) on my .net projects which are all under abc solution:

  1. Pull the changes from git.
  2. Build the solution that only the projects that were updated turing the pull will be built and also the dependencies.
  3. The build command should build these projects and its dependencies with a specific assembly version. for example: 1.2.3.4
  4. Each assemblyinfo.cs of the projects that were build should be changed to
[assembly: AssemblyVersion("1.2.3.4")]
[assembly: AssemblyFileVersion("1.2.3.4")]

Any idea on a nice way for doing step 3 and 4 ? I tried to run this command line but it did not gave me the result I wanted.

msbuild.exe abc.sln /p:Configuration=Release;VersionAssembly=1.2.3.4

Appreciate your kindly answers. Thanks

Upvotes: 4

Views: 4239

Answers (1)

Dávid Molnár
Dávid Molnár

Reputation: 11563

Use MSBuild.Community.Tasks and add the following to the *.csproj project files:

<Import Project=".\tasks\MSBuild.Community.Tasks.Targets"/>

<AssemblyInfo CodeLanguage="CS"  
    OutputFile="AssemblyInfo.cs" 
    AssemblyVersion="$(BUILD_NUMBER)" 
    AssemblyFileVersion="$(BUILD_NUMBER)" />

Run msbuild and pass the desired build number as a parameter:

msbuild abc.sln /p:BUILD_NUMBER=1.2.3.4

Upvotes: 3

Related Questions