Last active
May 18, 2016 10:42
-
-
Save chrisoldwood/7576895756bcbd0d3c62 to your computer and use it in GitHub Desktop.
Visual C# pre-build step to generate a common AssemblyVersionInfo.cs from a version number defined by a couple of environment variables.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<PreBuildEvent> | |
if not defined PRODUCT_VERSION set PRODUCT_VERSION=0.0.0 | |
if not defined BUILD_NUMBER set BUILD_NUMBER=1 | |
echo using System.Reflection;>"$(SolutionDir)Source\AssemblyVersionInfo.cs" | |
echo [assembly: AssemblyVersion("%25PRODUCT_VERSION%25.%25BUILD_NUMBER%25")]>>"$(SolutionDir)Source\AssemblyVersionInfo.cs" | |
</PreBuildEvent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a technique for injecting a build number into a global file called
AssemblyVersionInfo.cs
. The product-common assembly properties are split into two files stored near the root of the source tree -AssemblyProductInfo.cs
&AssemblyVersionInfo.cs
- with the latter generated by a pre-build step in the first assembly to be compiled. These two files are linked into each assembly project. Only the static properties fileAssemblyProductInfo.cs
is checked into the VCS.On the CI server you create two environment variables, one for the fixed part of the product version and the other comes from the build number counter -
PRODUCT_VERSION
andBUILD_NUMBER
. These are concatenated above to make the full, 4-part version number.Notes:
The reason we use
0.0.0.1
for the default build number is to avoid the default (1.0.0.0
) so we can easily see when we've forgotten to link the global ones in, and because FX Copy complains if you use0.0.0.0
as it thinks you haven't set one.Be careful when pasting the snippet into the Build Events edit box in the Visual Studio UI. The snippet above was taken from the
.csproj
file and so has the>
,>>
and%
characters escaped.