Liero
Liero

Reputation: 27390

How to increment assemby versions on TFS only if they've changed?

Scenario

I would like to automate assembly versioning on tfs 2013 build server by attaching changeset number to assembly version. The tricky requirement is, that I want to change version only of those assemblies, that has changed since last build (any source file has changed in the project dir).

Ideally, I would like to avoid customization of xaml workflows or installing any plugins into tfs.

What I have

so far I have custom build.proj (msbuild project), where I read version from version.txt (e.g. 2.5.0) and append changeset number at the end. Then I replace AsseblyVersion attribute in each AssemblyInfo, build the solution, create nuget packages and build them.


Obviously, I need to store the assembly version somewhere. Should it be in source control? or some local cache on build server? Basically, I have this information also on my private nuget server, since nugets contains the version and therefore also changeset number.

What I need

How to change version only of those assemblies that has changed since last build? I need any advice is appreciated.

Upvotes: 2

Views: 637

Answers (2)

Giulio Vian
Giulio Vian

Reputation: 8353

I described in full details an MSBuild/TFS technique in a series of posts (first, second and third). There are some drawbacks, the most important is that the version number for an assembly is kept on the build server; if you lose the machine, you have to restore the numbers manually.

It works because MSBuild is smart enough to rebuild only what is changed, you just need to find the proper hooks in the process.

Upvotes: 1

Cece Dong - MSFT
Cece Dong - MSFT

Reputation: 31075

You need to use build script to achieve what you want. You can check ApplyVersionToAssemblies.ps1 and add your own logic into the script to compare which project has been changed between the latest build and previous build, then determine which assemblies are changed during the build.

Upvotes: 1

Related Questions