Recently, I decided to include the revision number from the SVN repository into the assembly major/minor build information (e.g., 1.0.1234.0, where 1234 is the SVN revision number). The reason I had to do this, our applications gets installed locally at multiple user's computers primarily for testing/demo purposes and over time, it was getting hard to track the problems/bugs resported as it was too hard to figure which version was installed on their machine. And, nant is used as the primary build tool.
First, let's create a target to retrieve the latest SVN revision number.
<target name="RetriveSVNRevisionNumber" description="Retreiving the latest revision number of the working copy">
<echo message="Retrieving Subversion revision number"/>
<exec program="${tortoisesvn.dir}/SubWCRev.exe" >
<arg value="." />
<arg value="revision.include.default" />
<arg value="revision.include" />
</exec>
</target>
The above section retrieves the version number into the local project. For more details, refer this link.
In our case, the contents of revision.include.default file looks like:
<project name="RevisionSpecificProperties">
<property name="revision.value" overwrite="true" value="$WCREV$" />
</project>
Ok, now after retrieving the version number, we need to update our global SolutionInfo.cs file that will hold the assembly information.
<target name="UpdateAssemblyInfo" depends="GenerateBuildNumber" description="Updating the Assembly Information by overwriting the SolutionInfo.cs file with a new one." >
<asminfo output="SolutionInfo.cs" language="CSharp">
<imports>
<import namespace="System.Reflection" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="AssemblyCompanyAttribute" value="Company Name" />
<attribute type="AssemblyVersionAttribute" value="${build.version}" />
<attribute type="AssemblyFileVersionAttribute" value="${build.version}" />
</attributes>
</asminfo>
</target>
<target name="GenerateBuildNumber">
<script language="C#">
<imports>
<import name="System.Globalization" />
<import name="System.Threading" />
</imports>
<code>
<![CDATA[
public static void ScriptMain(Project project) {
Version version = new Version(project.Properties["build.version"]);
int major = version.Major;
int minor = version.Minor;
int build = version.Build;
int revision = version.Revision;
build = Convert.ToInt32(project.Properties["revision.value"]);
version = new Version(major, minor, build, revision);
project.Properties["build.version"] = version.ToString();
}
]]>
</code>
</script>
<delete file="revision.include" />
</target>
The above targets, creates/updates an existing SolutionInfo.cs file which can be linked to all the projects in the solution so, all assemblies gets updated with the latest revision number in their build info.
Tuesday, January 22, 2008
Visual Studio 2005 Customizing build process
Visual Studio 2005 provides a great set of features to customize the build process. Recently, I had an requirement to customize the build process for an in house web application to conditionally include files and project references. In my case, I had an web application projects and multiple library projects which were being references by the webapp. For one particular installation, I had to exclude one library project (say Project One ) and several aspx pages in the web app that were using Project One. MSDN had a nice article on a new feature called web deployment project which allows to customize the build process. But, I didn't want to add an additional project to existing solution, so I tried to solve my problem in a different way.
1. I created a seperate build configuration named "ExcludeProjectOne". Right click on Solution->Choose Configuration Manager->Select New from Active Configuration.
2. Uncheck the project you don't want to build in that configuration (Here, it is ProjectOne)
Now, when you choose the active configuration as ExcludeProjectOne, the library project "Project One" is excluded from the build process. But, it still didn't solve the problem in my web app project which references the ProjectOne and some aspx files which uses it. So, I manually edited the Web.csproj file to achieve the desired action.
I created a new itemgroup element with a condition attribute and placed all the necessary files and the project reference inside the itemgroup element.
The above changes allowed to me have a build configuration for the web application where I can exclude the library and the related aspx pages being built.
1. I created a seperate build configuration named "ExcludeProjectOne". Right click on Solution->Choose Configuration Manager->Select New from Active Configuration.
2. Uncheck the project you don't want to build in that configuration (Here, it is ProjectOne)
Now, when you choose the active configuration as ExcludeProjectOne, the library project "Project One" is excluded from the build process. But, it still didn't solve the problem in my web app project which references the ProjectOne and some aspx files which uses it. So, I manually edited the Web.csproj file to achieve the desired action.
I created a new itemgroup element with a condition attribute and placed all the necessary files and the project reference inside the itemgroup element.
The above changes allowed to me have a build configuration for the web application where I can exclude the library and the related aspx pages being built.
Subscribe to:
Posts (Atom)