Manish Pansiniya's Blog

.NET, C#, Javascript, ASP.NET and lots more…:)

MSBuild – Web Deployment Project – Custom Task ASP.NET 2.0

leave a comment »

Doing work on making automatic builds and deployment using Web Deployment Project for ASP.NET 2.0. It’s really a good tool and you can download it from here.

Now, next thing is to integrate the custom web.config section, folder creation and script executor.

Custom Web.Config Section
I make the following settings in deployment project for changing the web.config settings.
First, I made the follwoing file in my web project called TestingConnectionString.config

  <add name=“Test” connectionString=“Data Source=testing-server\2005;Initial Catalog=Test;Integrated Security=false;uid=test;password=admin123;”/>

Then in setting of Project, where you have Enable web config file section, tick it and put the following code to that


Also, I have checked the Create an IIS virutal directory for the output folder. Also I have given the virtual directory nameowing Creating Folder

Creating Folder
For creating folder follthings to be added in Web Deployment Project’s File. Right click on project and click open project file. Then at the end write this

<Target Name="AfterBuild">
<Message Text="After Build executing...$(TargetDir)"></Message>
<MakeDir Directories="D:\TestRelease_1\ServiceEvent"/>

Running Scripts
For running script, I used the joeyDotNet’s component. That can be downloaded at here. Then you need to put the dll into the tools folder of deployment folder. Then write the following section in your msbuild deployment file.

<UsingTask AssemblyFile=”Tools\joeyDotNet.MSBuild.Tasks.dll” TaskName=”RunSqlScripts” />
<OsqlConnString>-U test -P admin123 -H testing-server\2005</OsqlConnString>
<Target Name=”BuildDB”>
<Message Text=”Script Build executing…”></Message>
<RunSqlScripts ServerName=”$(ServerName)” OsqlConnectionString=”$(OsqlConnString)” DatabaseName=”$(Test)” OsqlPath=”$(Osql)” SqlScripts=”E:\Projects\HOBO1\ELM01\Source\ELM01.Database\DataScript\PopulateData.sql” WaitForExit=”true” />

Here you can define the settings. OSql is command. ServerName is name of the server where your database resides. OsqlConnString is the string parameter which is give to osql command.

That’s all. Very simple and timesaving. Just do it and tell me if you have any problem in doing so. 🙂


Written by Manish

March 13, 2007 at 1:59 pm

Posted in Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: