Share via


Automated Deployment in ASP.NET 4 - Frequently Asked Questions

Visual Studio 2010 and ASP.NET 4 work with IIS Web Deploy to automate many deployment tasks for Web application projects. We have created how-to, walkthrough, and overview documents to cover this feature, some of which are already available (see ASP.NET Deployment Content Map). More will be released when the product is officially released. 

 

To cover some smaller issues that we know people will have questions about, we have created an FAQ document. I am posting this preliminary version in order to elicit new questions that we have not thought of yet, which people would like to see answered. Comments on the format and content of the document as it stands are also welcome.

 

  -- Tom Dykstra
ASP.NET User Education
This posting is provided "AS IS" with no warranties, and confers no rights.

 

ASP.NET Web Application Project Deployment FAQ

This topic answers frequently asked questions about deploying Web application projects.

Many of the answers instruct you to change deployment settings by editing the project file. For information about how to do this, see How to: Edit Deployment Settings in the Project File. [This document is not public yet, so I have copied it inline at the end of this page]

This topic contains the following sections.[In the final version these will be links]

  • Can I specify files or folders that should not be deployed?
  • Can I adjust the amount of detail I get in the Output window about packaging or publishing progress?
  • Can I deploy my database's full-text catalog?
  • Can I reference system-generated database objects in custom deployment scripts?
  • Can I use Remote Agent service over HTTPS with one-click publish?
  • Can I use the Web Deploy tempAgent provider setting with one-click publish?
  • Can I interrupt packaging or publishing if I need to start over because I forgot something?
  • Can one-click publish create a package for archival purposes?
  • Can I specify that a package should be created every time I build my solution?
  • Can I change the default location where Visual Studio creates the deployment package?
  • Can I configure delegation rules so that developers can deploy to staging servers but not change IIS settings?

Can I specify files or folders that should not be deployed?

Yes. You can limit the files that are deployed by selecting the Only files needed to run this application or All files in this project options on the Package/Publish Web tab. If you select the Only files needed to run this application option, you can exclude files from the project to keep them from being deployed.

If these options are not flexible enough for you, you can edit the project file and add an ExcludeFilesFromDeployment element in the appropriate PropertyGroup element, as shown in the following example:

 <ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment> 

To specify folders to exclude, add an ExcludeFoldersFromDeployment element in the appropriate PropertyGroup element, as shown in the following example:

 <ExcludeFoldersFromDeployment>Folder1;Folder2</ExcludeFoldersFromDeployment> 

In both cases you can specify a single name or multiple names delimited by semicolons (;).

Can I adjust the amount of detail I get in the Output window about packaging or publishing progress?

The packaging and publishing verbosity level is controlled by the same Visual Studio setting that determines MSBuild verbosity. From the main menu, select Tools and then Options. In the Options dialog box expand Projects and Solutions, and then select Build and Run. You will then see the MSBuild project build output verbosity drop-down list, and you can select one of the following options from that list:

· Quiet

· Minimal

· Normal

· Detailed

· Diagnostic

These options correspond to what you can set by using the /verbosity or /v flag when you run MSBuild from the command line. For more information about MSBuild command line flags, see MSBuild Command Line Reference.

Can I deploy my database's full-text catalog?

By default, each script that Visual Studio automatically generates for deployment runs in a transaction. Scripts that deploy full-text catalogs do not run successfully in transactions. Therefore, by default Visual Studio does not create scripts for full-text catalogs.

To specify that the automatically generated deployment script for a database should not run in a transaction and should include a full-text catalog, edit the project file to make the following changes:

· Set the Transacted attribute of the Source element for the automatically generated script to False.

· Set the CopyAllFullTextCatalogs attribute of the PreSource element for the automatically generated script to True.

Can I reference system-generated database objects in custom deployment scripts?

By default, when you specify that Visual Studio should automatically generate scripts to deploy database structure, new names for system-generated objects (for example, constraints) are generated in the destination database. Therefore, if you write a custom script to modify or drop one of these objects, and if you specify the name that was generated for it in the source database, the script might fail when it runs in the destination database.

If you want system-generated object names to be the same in the destination database as they are in the source database, edit the project file and add the following attribute to the PreSource element for the automatically generated script: DriIncludeSystemNames="True".

Can I use Remote Agent service over HTTPS with one-click publish?

No. When you enter an HTTPS URL in the Service URL text box of the Publish Web dialog box, Visual Studio will automatically use the Windows Management service. If you want to use HTTPS, we recommend that you use Windows Management service.

Can I use the Web Deploy tempAgent provider setting with one-click publish?

No. If you want to use the tempAgent provider setting, you must use the Web Deploy command line or the deploy.cmd file that Visual Studio generates.

Can I interrupt packaging or publishing if I need to start over because I forgot something?

Yes. Press CTRL-BREAK. Packaging or publishing will stop. When you restart, Visual Studio will pick up where it left off without redoing any work that was already completed.

Can one-click publish create a package for archival purposes?

Yes. Edit the project file and add a CreatePackageOnPublish element in the appropriate PropertyGroup element, as shown in the following example:

 <CreatePackageOnPublish>True</CreatePackageOnPublish>

Can I specify that a package should be created every time I build my solution?

Edit the project file and add a DeployOnBuild element in the appropriate PropertyGroup element, as shown in the following example:

 <DeployOnBuild>True</DeployOnBuild>

The DeployDefaultTarget element must also be set to Package, but setting it is optional, because that is the default value.

Can I change the default location where Visual Studio creates the deployment package?

Edit the project file and add an IntermediateOutputPath element in the appropriate PropertyGroup element, as shown in the following example:

 <IntermediateOutputPath>Path</IntermediateOutputPath>

Replace Path with the full path to the folder where you want all the files that are associated with the deployment package to be created.

Can I configure delegation rules so that developers can deploy to staging servers but not change IIS settings?

This is possible in IIS 7 and later versions. For information about delegating deployment permissions, see the following topics:

· Delegate Site and Application Management (IIS 7) on the Microsoft TechNet Web site.

· Delegating Administration on the IIS.NET Web site.

· Configuring the Web Deployment Handler.

How to: Edit Deployment Settings in the Project File

Some settings that specify how a Visual Studio Web application project creates Web deployment packages, or how one-click publish works, are not available in the Visual Studio UI. To change these settings, you must change them in the project file. This topic describes how to do this.

The topic does not enumerate all of the settings that you can change, and it does not describe how to set default values that apply whenever you open new projects. Other ASP.NET deployment topics describe options that are available, and they link to this topic for instructions that describe how to change those options. For more information, see ASP.NET Deployment Content Map.

If you are familiar with MSBuild you can set default values in the .targets files that are used for Web publishing. These files are located in the following folder:

%Program Files%\MSBuild\Microsoft\VisualStudio\v10.0\Web

For more information about MSBuild, see MSBuild Reference.

Editing the Project File

The following procedure explains how to edit the project file and how to find the XML elements that need to be changed.

To open and edit the project file

1. Open the project's .project file (the file that has the .csproj or .vbproj extension) in a text editor.

If the project is in a solution that has multiple projects, and if you have the project opened in Visual Studio, you can right-click the project name in Solution Explorer and select Unload Project, then right-click the project and select Edit. If the project is not in a solution, use Windows Explorer to navigate to the project directory, and open the .csproj or .vbproj file by using Notepad or another text editor. (You can find the path to the project file in the Project Folder field of the Properties window.)

2. Find the PropertyGroup element that pertains to the build configuration that you are entering settings for.

For example, if you are creating settings for the Debug build configuration, look for the PropertyGroup element that has the following opening tag:

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

3. If the setting that you want to configure is not related to database deployment, add a new element under the PropertyGroup element.

For example, suppose you find the following PropertyGroup element:

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
   <DebugType>pdbonly</DebugType>
   <Optimize>true</Optimize>
   <OutputPath>bin\</OutputPath>
   <DefineConstants>TRACE</DefineConstants>
   <ErrorReport>prompt</ErrorReport>
   <WarningLevel>4</WarningLevel>
   <!-- Other settings -->
 </PropertyGroup>

To change the default location where the package is created, you would add an IntermediateOutputPath element, as shown in the following illustration:

 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
   <IntermediateOutputPath>C:\TEMP\</IntermediateOutputPath>
   <DebugType>pdbonly</DebugType>
   <Optimize>true</Optimize>
   <OutputPath>bin\</OutputPath>
   <DefineConstants>TRACE</DefineConstants>
   <ErrorReport>prompt</ErrorReport>
   <WarningLevel>4</WarningLevel>
   <!-- Other settings -->
 </PropertyGroup>

4. If you want to configure settings that are related to database deployment, perform the following steps:

a. Find the PublishDatabaseSettings element within the PropertyGroup element that you want to change.

The PublishDatabaseSettings element resembles the following example:

<PublishDatabaseSettings>

<Objects>

<ObjectGroup Name="ApplicationServices-Deployment"

Order="1">

<Destination Path="" />

<Object Type="dbFullSql">

<PreSource Path="..." ScriptSchema="True"

ScriptData="False"

CopyAllFullTextCatalogs="False" />

<Source Path="..." Transacted="True" />

</Object>

</ObjectGroup>

</Objects>

</PublishDatabaseSettings>

b. In the PublishDatabaseSettings element, find the ObjectGroup element that corresponds to the database that you want to configure.

For each line that you entered in the Database Entries grid on the Package/Publish SQL tab, you will see an ObjectGroup element. The name of the ObjectGroup element is the name in the Database Entries grid.

c. In the ObjectGroup element, find the Object element that corresponds to the script that you want to configure.

There is one Object element for each database script. The Object element in the preceding example represents the automatically generated deployment script. If you add custom scripts, there will be an additional Object element for each custom script.

Within the Object element are Source and PreSource elements. Most database settings that you might want to configure in the project file require setting attributes on these elements.

d. Set attributes of the Source or PreSource elements to configure database deployment.

For example, to change the preceding example so that the automatically generated script include SQL Drop statements for each database object before the statements that create the objects, add the ScriptDropsFirst attribute to the PreSource element, as shown in the following example:

<PublishDatabaseSettings>

<Objects>

<ObjectGroup Name="ApplicationServices-Deployment"

Order="1">

<Destination Path="" />

<Object Type="dbFullSql">

<PreSource Path="..." ScriptSchema="True"

ScriptData="False" ScriptDropsFirst="True"

CopyAllFullTextCatalogs="False" />

<Source Path="..." Transacted="True" />

</Object>

</ObjectGroup>

</Objects>

</PublishDatabaseSettings>

5. Save the changes and close the project file.

6. If you edited the project file by unloading the project, in Solution Explorer right-click the project and select Reload Project.

Give Your Feedback on the Documentation

Help us improve the developer documentation by taking the Visual Studio and .NET Framework Content Survey. This survey will give us a better understanding of the type of applications you are developing as well as how you use Help and how we can improve it. The survey takes only 10 minutes, and we appreciate your feedback

Comments

  • Anonymous
    January 06, 2011
    Yeah, I like your post. Very informative... Could you please advise the provider that support .net 4? I am looking for it now. I have 3 names here, www.discountasp.net, winhost, or www.asphostportal.com? My friend recommend me to go with asphostportal. As the price is low and their support is prompt too.
  • Anonymous
    January 07, 2011
    An internet search for "asp.net 4 hosting" will turn up quite a few choices.  I have personally had good experiences with discountasp.net.