Introduction
Sometimes it's useful to add additional Key/Value pairs to the VERSIONINFO
resource. The two most useful for me are, the time when the executable was built and on which machine it was built. The benefit of putting that information into the VERSIONINFO
resource is that I can easily access it with Windows Explorer. This article describes how this can be accomplished by leveraging the integration of MSBUILD with VS2005.
Fortunately, VS2005 has the capability to take a .res file instead of an icon as input. The bad news here is that if a res file is used, it must be manually compiled (using rc.exe) and synchronization with the existing .NET assembly attributes (e.g., AssemblyTitleAttribute
) is lost. This is where MSBUILD comes in. I wrote a small build script and a task that does the following:
- Create a temporary .rc file
- Scan 'AssemblyInfo.cs' and put data into .rc file
- Add additional data to .rc file
- Compile .rc into .res using rc.exe
- Switch from icon option to resource file option
- Delete temporary files after compilation
Using the Code
The first step that has to be done to get started with the code is to create a new folder in the MSBuild vendor extension path (usually, this is C:\Program Files\MSBuild) and manually copy the files CP.MSBuild.dll and CP.MSBuild.targets from the download there. The next step is to insert the following snippet to each C# project we want to have the additional processing.
<Import Project="$(MSBuildExtensionsPath)\<created folder>\CP.MSBuild.targets" />
Note that the build script will only work for C# projects that don't already use a resource file.
Points of Interest
The build script as published here is tailored to my current needs. The code and script, however, should be easy enough to read and modify that it can be used in more advanced scenarios.
The source download contains the two projects CP.MSBuild.csproj and TestApp.csproj. They should be all that is needed to debug the build script. Note, however, that CP.MSBuild has to be built before the TestApp can be built.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.