Set the Version of your ASP.NET web application
Imagine you want to release your Web application to your client in a way you can provide individual updates in the future and not the complete Web Site with every new release. Visual Studio allows you to publish a Web site using fixed names, this option creates an assembly for the code code behind of each page of your site, additionally if you mark your Web Site as –Updatable-, you will be able to replace those individual assemblies of your Web Site, this is a very cool and useful feature.
When publishing a Web application like this, you will have your application divided in multiples assemblies, and of course it would be interesting to be able to set the version of each assembly so we can keep track of the release, and identify which versions are deployed on a client, however in Visual Studio there is no way to set the versions of an ASP.NET application assemblies, I searched for different ways to try to do this without any luck, until I found a little tool called ILMerge that allows merging assemblies, so I start digging into this and found the solution for what I wanted, this tool also lets you apply the properties of one assembly into others, and that is when it hits me:
After publishing your Web site, I can merge the individual ASP.NET assemblies with “nothing” and provide a “dummy” assembly only with properties like version number, company, copyright. and stamp them into the original ASP.NET assembly. The result is the same assembly but with a version number!
To demonstrate this process Il will provide a step by step example:
Publish your Web site as updatable and check the -use fixed names- option.
Inside the “bin” folder of your just published application you will find the assemblies, for each assembly you want to version, follow the next steps:
Create an .cs file with the same name as your assembly, for example mypage_aspx_.dll, and enter the following code:
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("My App Title")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Cesar Intriago")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("Copyright © Cesar Intriago 2011")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: AssemblyVersion("2.5.0.0")]
[assembly: AssemblyFileVersion("2.5.0.0")]
Now we are ready to stamp the above properties in our assemblies, the next step is to build that .cs code into an assembly:
csc.exe /target:library /nologo /warn:0 mypage_aspx.cs
Move the resulting assembly into an “attributes” folder. Now we are ready to use ILMerge, we will merge only the original ASP.NET assembly into a new assembly with the same name inside a “versions” folder, and during this merge process we will apply the new assembly properties:
ilmerge.exe /attr:attributes\mypage_aspx.cs.dll
/target:library /ndebug /out: versions\mypage_aspx.cs.dll
mypage_aspx.cs.dll
The following image describes the meaning of each parameter:
This may be a cumbersome process, but it’s the way I found how to version an ASP.NET assembly, if you know another we will happy to hear it. The good news is that you can automate this process because it just uses command lines, you can even create a nice post-publish Visual Studio tool to mange and set the version of your Web Application.
ILMerge Download (from Microsoft):