Posted in:

A while ago I decided I needed an MSBuild task that could update the version numbers in my AssemblyInfo.cs file. I had a search around the web, but all the custom tasks I found seemed to work in a different way to what I wanted. So I created my own.

What I wanted was a simple way to say “increment the revision number but leave other numbers the same”, or “set the version to exactly this”. So I came up with a simple syntax to let me do just that. For example:

<SetVersion FileName="AssemblyInfo.cs" AssemblyVersion="1.2.+.=" />

This means, set the major version to 1, set the minor version to 2, increment the revision number and leave the build number at whatever it was before. You can also specify a rule for AssemblyFileVersion if you want to keep them both in sync.

SetVersionTask is open source, and hosted on GitHub. You can download the build of the latest version there, and read more detailed instructions on how to set it up in your MSBuild script.

I had originally planned to make it work for nuspec files too, but I don’t have a pressing need for that just yet. Shouldn’t be too hard to add though. Feel free to make use of it if it does what you need.

Comments

Comment by Anonymous

Hi,

You won't need it for NuGet as you can pass the versionnumber as an argument, which overrides the version in the nuspec file.

Anonymous
Comment by Mark H

thanks anonymous, I didn't know that

Comment by Agba Uchenna Linus

How can I pass the version number as an argument to the MSBuild script? Thanks

Agba Uchenna Linus
Comment by Mark Heath

it's been a long time since I worked with this, so afraid can't recall the syntax off the top of my head. You should be able to get an answer from StackOverflow

Mark Heath