How to: Edit Deployment Settings in the Project File
The Visual Studio UI does not provide a way to specify every setting for how a Visual Studio Web application project creates Web deployment packages, or for how one-click publish works. To change settings for which Visual Studio provides no UI, 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.
Web deployment tools have been improved in Visual Studio 2012. You can install the improved tools in Visual Studio 2010 and Visual Web Developer 2010 Express by installing the Visual Studio Web Publish Update. For information about how to use the new tools, see the documentation for Visual Studio 2012. A good place to start is Web Application Project Deployment Overview for Visual Studio and ASP.NET.
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:
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
Open the project's .project file (the file that has the .csproj or .vbproj extension) by using one of the following methods:
If the project is in a solution, and if you have the project opened in Visual Studio, right-click the project name in Solution Explorer and select Unload Project, and then right-click the project and select Edit. (If you want to use this method in a solution that contains only one project, make sure that the Always show solution option is selected. You can find this option in the Projects and Solutions section of the Options dialog box, which you can select from the Tools menu.)
Use Windows Explorer to navigate to the project directory, and then open the .csproj or .vbproj file by using Notepad or another text editor. (You can find the path to the project folder in the Project Folder field of the Properties window.)
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' ">
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>
If you want to configure settings that are related to database deployment, perform the following steps:
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>
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.
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 of these elements.
Set attributes of the Source or PreSource elements to configure database deployment.
For example, you might want to change the preceding example so that the automatically generated script includes SQL Drop statements for each database object that run before the statements that create the object. To do so, 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" />s <Source Path="..." Transacted="True" /> </Object> </ObjectGroup> </Objects> </PublishDatabaseSettings>
Save the changes and close the project file.
If you edited the project file by unloading the project, in Solution Explorer, right-click the project and then select Reload Project.
From the Build menu, select Clean ProjectName.