Publish Web Application Project via MSBuild

Assuming that you’re running it from the same directory the .csproj file exists in (using Visual Studio 2005 Command Prompt):

msbuild wapProjectName.csproj /p:Configuration=Release

msbuild wapProjectName.csproj /target:_CopyWebApplication /property:OutDir=c:\SomePath\
  /property:WebProjectOutputDir=c:\SomePath\ /p:Configuration=Release

copy bin\*.* c:\SomePath\bin\



Creating Virtual Directory for ASP.NET 2.0 programmatically

For all of you programmers out there, who develop for 1.1 and 2.0 on the same machine – this trick can be quite useful for you !

If you’re still using IIS, you’ll want to create a VD(Virtual Directory) which support 2.0 for those application developed for that version, and still use VD which support 1.1 for your older application. Running an 2.0 application with VD of 1.1 (and vice versa, of course) will not work.
Where’s the catch you may ask ?
Well, if you add a new virtual directory, you may notice that the chosen (default) version is the one you have in the Default Web Site. This can cause some annoying problems as some of your developers(or your server(s) administrator(s)) will define 2.0 as their default while the others will define 1.1 as their default. Just mentioning “define a new Virtual Directory for the application X” won’t be enough.

The trick is to create a new Virtual Directory in the old fashion way, and just after it – call

%windir%\Microsoft.Net\Framework\[wanted version]\aspnet_regiis.exe -s w3svc/1/root [your Vitual directory name]

But hack, why do you need to remember all of this ?

Use the new(here is the old, without 2.0 support), improved, stylish, with 2.0 support – VDCreator:

VDCreator bin(EXE & Config only) (4.81 KB)

VDCreator Source (39.56 KB)

last but not least 

Ken helped me on this one so thanks mate !


Automated build for my ASP.NET project using NAnt

As I’ve promised – I share with you my experience with NAnt while attempting to automate my build process for my ASP.NET project. After reading a lot on the subject, I must admit that the documentation is quite poor and the “open source” examples are not exactly what I’m looking for. Before I’ll start, if you don’t know what is NAnt or NAnt contrib, now will be a good time to do some reading, I’ll wait…

Requirements (What do you need to install before you can start):

  1. Download and install NAnt.
  2. Add the nant\bin directory path to your PATH variable (“System Variables”).
  3. Download and install NAnt contrib.
  4. Integrate between NAnt and NAnt contrib using these steps:

    1. Copy nant-contrib\bin\*.dll to nant\bin\ directory.
    2. Create the folder nant\bin\tasks\net (manually).
    3. Copy nant-contrib\bin\*.dll to nant\bin\taks\net directory.

  5. Download NAnt.UtilityTasks.dll and put it in nant\bin directory.

Let’s Start:

OK, now we’re ready to start the build process; So here is my solution structure:

   – WebProject (ASP.NET project)
      – *AssemblyInfo.cs
      – Other files and directories (& porno, of course)
   – BusinessLayer (Class Library)
   – DataAccessLayer (Class Library)
   – EntitiesLayer (Class Library)
   – *SolutionInfo.cs
  – etc..

* Before I continue about the process itself, I must mention that I’m using “Link File” option in order to share my AssemblyVersion attribute in my ClassLibraries projects. In a perfect world, ASP.NET projects would be able to “Link File” as well, but (surprisingly) it’s not; So I have 2 places which hold the AssemblyVersion:
1. MySolution\SolutionInfo.cs (This file is being linked in all of my class libraries).
2. MySolution\WebProject\AssemblyInfo.cs.

Great, we can carry on –
I’ve discussed about the proper build process with my friends A&A (The Amir’s aka “The markowitz” and “The Engel”) and we’ve agreed that we require 2 processes – “Build”(complete new version) and “Rebuild”(rebuild the current version, it’s required after the Build process failed for some reason).

The desired processes work flow
Note: you don’t need to copycat my process, you’re a free human being, consider me as your Build mentor :-o

1. “Build” process –
   1.1 Increment my build version (SolutionInfo.cs & AssemblyInfo.cs)
         In order to do that, I’m using a great code snippet I found during my last weekend searches to 
         create a new version number. Afterwards, I’m checking-out the SolutionInfo.cs file and imprint the 
         new AssemblyVersion using <asminfo> task.
         Eventually I’m checking-in the SolutionInfo.cs file.

         * I’m using some properties – ${property_name} – for easy maintenance, you can see it in the 
            file I’ve upload (way over down).

   <vsscheckout username=“${vss.username}” password=“${vss.password}” 
      localpath=“${slndir}” recursive=“false” writable=“true” dbpath=“${vss.dbpath}” 
      path=“${vss.slnpath}/SolutionInfo.cs” failonerror=“true” />

   <asminfo output=“${slndir}\SolutionInfo.cs” language=“CSharp”>
         <import namespace=“System” />
         <import namespace=“System.Reflection”/>
         <import namespace=“System.Runtime.CompilerServices”/>
         <attribute type=“AssemblyVersionAttribute” value=“${build.version}” />
         <attribute type=“AssemblyCompanyAttribute” value=“${company}” />
         <attribute type=“AssemblyProductAttribute” value=“${product}” />
         <attribute type=“AssemblyCopyrightAttribute” value=“Copyright (c) 2005, ${company}.” />
         <attribute type=“AssemblyTrademarkAttribute” value=“Trademark by ${company}” />
         <attribute type=“AssemblyDelaySignAttribute” value=“false” />
         <attribute type=“AssemblyKeyFileAttribute” value=“..//..//..//key.snk” />
         <attribute type=“AssemblyKeyNameAttribute” value=“” />

   <vsscheckin username=“${vss.username}” password=“${vss.password}” 
      localpath=“${slndir}\SolutionInfo.cs” recursive=“false” writable=“true” 
      dbpath=“${vss.dbpath}” path=“${vss.slnpath}/SolutionInfo.cs”
      comment=“change build version: ${build.version}” />

         I use the same code (with minor changes) to update my AssemblyInfo.cs file as well.

   1.2 Put a label on the VSS with the current new version.
         This is even easier, I just use <vsslabel>(NAnt contrib) task:

           comment=“New build version: ${build.version}”

   1.3 Get the files from the VSS to my local directory recursively using <vssget>(NAnt contrib) task.

   1.4 If I’m required to (by property) – generate the projects pdb’s.
        This is great for release mode, I can pull the pdb’s for the version at the Production environment 
        and make some extreme production debugging using the pdb’s as symbols – 
        I must give the credit to “The markowitz” for the idea !

        The code is quite simple – build the solution in Debug mode and copy the *.pdb files
        to my “version_directory”\pdb\WebProject.
        You can see the code in the attached file.

   1.5 Build the solution.
         I’m using <solution> task and <webmap> for easy build.
         Again, nothing fancy, look in the attached file.

   1.6 Copy the web project output to my MySolution\Builds\[version_number] directory for 
        an easy XCOPY deployment. I’m using <copywebproject> task in order to do 
        this magic, it’s working like a charm.  
   <copywebproject project=“${slndir}\WebApp\WebApp.csproj” 
      todir=“${outdir}\WebApp” configuration=“${config}” />

2. “Rebuild” process – 
      Call steps 1.3 to 1.6.

I recommend that you’ll download VSTweak and let the VS.NET treat your .build file as .xml file.

I’m going to add a NAnt task which will get all the *.js\*.htc files from the web project (.csproj) and format them
via Jazmin – this will cut down the size of the files(by removing comments and other not-required characters) for performance improvement (the smaller the file is, the faster the client will download it).

If you’re using my file as your “template”, I would appreciate if you’ll add a comment and let me know about it, including new features you’ve added or planning to add. I’ve dedicated my time to share with you, please do the same grace with me. Thanks !

My (template) build file: (3 KB)

How to run the build file ?
You’ll need to configure the file I’ve attached (5 minutes max).
Go to your solution directory and copy the “” file into it.
Now, activate “cmd” and navigate to that directory.
Type “nant build” and Voila !


Using MSBuild – Is it Smart ?

I’m struggling with myself about what’s the best way now to create an automated build mechanism for my dotNET project. I read a lot during the last weekend about using Nant and Nant Contrib and I’ve managed to pull something off quite easily. * I’ll upload the build file and my remarks about the process as soon as I’ll finish (Can’t wait ah ? ;-)).

I saw that Microsoft shipped their automated tool – MSBuild – with VS.NET 2005 (beta 2); But in order to make use of MSBuild in my v1.1 .NET framework, I’ll need to do some DIRTY hacks which I don’t seem to like in this case. You ask yourself why ?

1. This is a beta version, meaning the bugs will be all over me !

2. I personally think that using the beta version of any program in my Production environment is a big risk, too big in my opinion.

3. Let’s say that I found a bug and I need to get it fixed; MS will cry that this version isn’t supported in v1.1 framework (dah! that’s why I did my dirty hack) and in any case it’s only a beta and I need to wait for the final release – and they’ll be right ! (damn, I hate when it happens).

4. NAnt is an old(sorry… but I mean it as a compliment) open source freeware – there are less bugs and I can always dig in and make the required changes !

Therefore, I’m thinking of staying with NAnt just until the final release of MSBuild will be available.

What do you think ?


Add Virtual Directory programmatically, for easy “new-box” deployment.

I’m always trying to make my project deployment as easy as possible.


One of the “problems” I’ve encountered is keeping my solution structure, that is:

– MySolutionDirectory

      – MyWebProject

      – MyBusinessLayerClassLibrary

      – MyDataAccessLayerClassLibrary

      – MyEntitiesClassLibrary

      – etc.


This is hard to do, especially when the “Add Web Project” creates a virtual directory in

my wwwroot directory by default which breaks my desired structure.


When I want to initialize the Solution or to pull the entire solution from the

VSS (e.g – on a new programmer station) I need to take these steps beforehand

  1. Create the directory [solution-path]\[web-project\webservice name]
  2. Go to my IIS and add the required virtual directory which will redirect to step 1 path.

Otherwise, the VS.NET will create the web folders in my wwwroot automatically, which will again break my preferred structure.

In addition, in some of my solutions, I have more than 1 web project\webservice and repeating these steps can get very annoying.


So, after reading about IIS API, I’ve created an IIS helper utility for creating virtual directories by

demand in one-click EXE.


The configuration file is quite simple:



This sample demonstrates how to add “MyWebProject” Virtual Directory and create another

Virtual Directory, under “MyWebProject”, named “MyWebShareProject”.


* 2 Notes:

  1. You can create the virtual directory under a WebSite by using “WebSiteName” element under the “Directory” element.
  2. If the “DirectoryPathdoesn’t exist – the utility will create it before setting the Virtual Directory path.


Now, when a co-worker in my company is trying to deploy my solution on his station, all he needs to

do is to run VDCreator.exe and he can continue the deployment via VS.NET -> “Open From Source Control…” option.


That’s what I call “child’s play” deployment.


The files:

VDCreator (4.62 KB)  (EXE & config file only)

VDCreator (9.64 KB) (Source files included)