CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Web Deployment Project for Visual Studio 2005 and 2008

By Satheesh babu
Posted On Sep 06,2008
Article Rating:
Be first to rate
this article.
No of Comments: 3
Category: Visual Studio 2005/2008
Print this article.

Web Deployment Project for Visual Studio 2005 and 2008

 

Introduction

                        Deployment of ASP.Net sites can be done through Copy Website and Publish Website feature of Visual Studio. Using Copy Website, we can copy the compiled version of the asp.net site to the target virtual directory location. When we use Publish feature of Visual studio, we can specify the path where it can publish the compiled version of the asp.net site. Both of these mechanisms will produce number of assemblies with unreadable names inside the BIN directory. We can use the Publish Website feature when we right click the website in the solution explorer. Refer the below figure for Publish Website feature of Visual Studio 2005.

 

These features does not have option for fixed assembly naming, lacks in post build option, can’t modify configuration settings during build and etc. Thus, it lacks in   some flexibility we require for deploying webapplications. At times, we might require providing some build actions, making single output assembly where the Publish option does not help in these scenarios. 

As an answer to the above difficulty, Microsoft developed a plug-in that has the entire features which we require for deploying web applications called Web Deployment Plugin.

For Visual Studio 2005, the plug-in can be downloaded here.

For Visual Studio 2008, the plug-in can be downloaded here.

 

Some of the useful features of this plug-in are discussed here by taking Visual Studio 2005 Web Deployment plug-in as example. All these features are also applicable for Visual Studio 2008 Web Deployment plug-in.

 

Features of the Plug-in

The Web Deployment project will provide the following features for building and deploying ASP.NET Web sites:

Ø       ASP.NET 2.0 precompilation as part of the build process.

Ø       More flexible options for generating compiled assemblies from a Web project, including these alternatives:

o         A single assembly for the entire Web site.

o         One assembly per content folder.

o         A single assembly for all UI components.

o         An assembly for each compiled file in the Web site.

Ø       Assembly signing options.

Ø       The ability to define custom pre-build and post-build actions.

Ø       The ability to exclude folders from the build.

Ø       The ability to modify settings in the Web.config file, such as the <connectionString> element, based on the Visual Studio build configuration.

Ø       Support for creating .msi files with setup projects.

 

Download the Plug-in from the above location and install in your machine. The plug-in will automatically integrate with Visual Studio.

 

Adding Web Deployment Project in Visual Studio

In the Build menu of Visual studio, we can find “Add Web Deployment Project” Option. Click to add a new Web Deployment project to your solution. Refer the below figure.

 

When we click “Add Web Deployment Project”, it will open a dialog box like,

 

 

We can specify the name and location to store the project in the dialog. After adding the Web Deployment Project the solution explorer will look like,

Building the Site

Right click the Web Deployment Project(GridViewDemo_deploy) and Click Build.

Note

Set the Debug Mode to False for the website before building the website. You can see the project output in the folder location you have specified in the above Dialog box.

 

Point to Note

If you have sub websites, then you should have a separate web deployment project for the sub websites.

 

Moving forward, we will see the various feature this plug-in provides for deployment.

To manage configuration settings, Right Click the project and choose “Property Pages”. It will bring a property dialog like below.

 

 

It contains 4 tabs,

Ø       Compilation

Ø       Output Assemblies

Ø       Signing

Ø       Deployment

 

Moving forward, we will see some of the useful settings that can be done while generating deployment files. For a full feature list description visit the msdn page linked in reference section.

 

Compilation Page

Output Folder

                        We have to specify the folder location where our output files have to be copied. For our comfort ness we can specify the location within our project directory itself.

Generate Debug information

This will make the Debug attribute to true in Web.Config file. So if you are putting the release finally make sure that you are unchecking it. It also creates the .pdb files in the bin directory.

Use IIS metabase Path for Source input

Specify the metabase path of IIS here. This can be used to prevent the compilation errors when there are subwebsites. So specifying this attribute prevent the compiler to compile the sub websites. Read more about metabase here,

Allow this precompiled site to be updatable

Make sure that you are checking this attribute to make ASPX and ASCX file to be updatable after deployment. Unchecking this option will make the compiler to compile the ASPX and ASCX to an assembly. Physically, these files will be present in the output directory but you can’t find any HTML markup inside when you uncheck this option.

 

Output Assemblies Page

This Page is pretty explanatory and it has so many useful settings that can be managed. The page will look like,

 




Merge all outputs to a single assembly

This is equivalent to what we do in visual studio 2003.

Treat as library component

Removes the App_code.compiled file. This enables the project's App_Code.dll assembly to be added to the Bin folder of another Web site without conflicting with the App_Code.dll assembly in the other Web site.

Merge each folder output to its own assembly

 This property makes the compiler to output one assembly per folder.

Merge all pages and controls to a single assembly

This gives one assembly for all ASCX and ASPX in the project and App_Code files will be outputted as a separate assembly.

Version Output Assemblies

As name suggests it is used to provide assembly versions.

 

Signing Page

This page contains attribute to sign the assembly with key file generated with sn.exe. This is not most commonly used setting in the projects.

 

Deployment Page

The Page will look like,

 

Enable Web.config file section replacement

To make a replacement of a particular section in Web.Config during build we can use this option. This section that should be replaced can be in separate file and can contain multiple section names that are separated by semicolon. The Syntax is, sectionName=filename. Note that section names are case sensitive and files can only contain relevant sections.

Example:

appSettings=appsettings.config

 

What happen when we install Web Deployment Plug-in?

Installing this plug-in will install a utility called aspnet_merge.exe in the location C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0 by default. This is the utility that is doing all the above actions for us. We don’t want Visual studio to be installed also to use this utility because it supports command line build also.

 

Web Deployment plug-in for Visual Studio 2008

All these features are also applicable for Visual Studio 2008 Web Deployment plug-in.

Below, you can find a quick list of WDP 2008 features.

Ø       Migration from WDP for VS 2005 to WDP for VS 2008.

Ø       Replacing WDP output only if Pre-Compilation succeeds.

Ø       Creating IIS Applications.

Ø       Using aspnet_merge.exe version which is installed with Visual Studio 2008.

Ø       Core WDP Features.

Visit here to read more about these features.

 

Common Error and Resolution

Aspnet_merge.exe exited with code 1.

This error will occur when we have same class name for 2 classes in the project.

 

 

The output given by the compiler is below.

 

Validation Complete

------ Build started: Project: babutest_deploy, Configuration: Debug Any CPU ------

C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets(574,9): error MSB6006: "aspnet_merge.exe" exited with code 1.

Done building project "babutest_deploy.wdproj" -- FAILED.

========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

The above output does not show a detailed output about what and where the actual error occurred. So, to get the detailed output of what and where the error happened,

Click Tools>Options>

It will open a window like,

 

Check “Show All settings” checkbox to get the full listing of Options. Click Project and Solutions>Build and Run> Select “Diagnostic” of “MSBuild project build output verbosity” dropdown and click OK.

 

When we build the deployment project again, we can get the full description of the error. I have bolded the class name that is duplicated in the below error description.

 

Command:

    C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe -v /babutest -p F:\Articles\babutest -u -f -d "C:\Documents and Settings\Satheesh\My Documents\Visual Studio 2005\Projects\babutest\babutest_deploy\Debug\\"

    The "AspNetCompiler" task is using "aspnet_compiler.exe" from "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe".

    Utility to precompile an ASP.NET application

    Copyright (C) Microsoft Corporation. All rights reserved.

   

   

  Done executing task "AspNetCompiler".

  Task "ToggleDebugCompilation"

    Updateing web.config compilation debug = 'True' ...

    Successfully updated web.config compilation debug = 'True' ...

  Done executing task "ToggleDebugCompilation".

  Task "RemoveDir" skipped, due to false condition; ('$(DeleteAppDataFolder)' == 'true') was evaluated as ('' == 'true').

    Command:

 

    C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\aspnet_merge.exe "C:\Documents and Settings\Satheesh\My Documents\Visual Studio 2005\Projects\babutest\babutest_deploy\Debug" -o babutest_deploy -debug -copyattrs

    The "AspNetMerge" task is using "aspnet_merge.exe" from "C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\aspnet_merge.exe".

    Utility to merge precompiled ASP.NET assemblies.

    Copyright (c) Microsoft Corporation. All rights reserved.

   

    An error occurred when merging assemblies: ILMerge.Merge: ERROR!!: Duplicate type '_Default' found in assembly 'App_Web_epckofnt'.

    C:\Program Files\MSBuild\Microsoft\WebDeployment\v8.0\Microsoft.WebDeployment.targets(574,9): error MSB6006: "aspnet_merge.exe" exited with code 1.

  Done executing task "AspNetMerge" -- FAILED.

Done building target "AspNetMerge" in project "babutest_deploy.wdproj" -- FAILED.

 

Done building project "babutest_deploy.wdproj" -- FAILED.

 

Build FAILED.

 

Time Elapsed 00:00:03.87

========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

 

The information’s that are bolded in the error information will give us a clue to find the error! For Deploying asp.net application in Windows 2003 Server, read my article on Deploying Application in Asp.Net.

 

Downloads

Web Deployment Plugin for Visual Studio 2005

Web Deployment Plugin for Visual Studio 2008

 

Conclusion

We can use this plug-in given by Microsoft for generating deployment files since we can have more control on the outputted assemblies. To have a more detailed understanding on all the features I suggest you to read the msdn article here.

 

Similar Articles
You can contribute to CodeDiget.Com:
Donate to CodeDigest.com
Article Feedback
Comments
App_Code.dll missing from Bin folder
If you are missing App_Code.dll assembly from Bin folder. Do the following:

Go to Property Pages of your Web Deployment project, Click 'OutputAssemblies' from the tree view and select 'Merge each individual folder output to its own assembly' radio button. It work for me.

The output Bin folder now contained App_Code.dll, App_global.asax.dll and App_GlobalResources.dll.

HTH
Exclude folders?
Allegely, the web deployment plug-in allows you do exclude folders, but I don't see how/where.
uff
Gracias por el post, fue muy útil