[VS2013]发布网站时修改配置文件
本文来自:https://msdn.microsoft.com/en-us/library/ee942158.aspx#encrypt_webconfig
Web Deployment FAQ for Visual Studio and ASP.NET
This topic answers frequently asked questions about how to deploy Visual Studio web projects.
![]() |
---|
This topic applies to Visual Studio 2012 and Visual Studio Express 2012 for Web. The topic covers features that are included in the latest Visual Studio Web Publish Update available as of June, 2013. Most of these features are also available in Visual Studio 2010 and Visual Web Developer 2010 Express when you install the Web Publish Update. |
Many of the answers instruct you to change deployment settings by editing the publish profile (.pubxml) file or the wpp.targets file. For information about how to do this, see How to: Edit Deployment Settings in Publish Profile (.pubxml) Files and the .wpp.targets File in Visual Studio Web Projects.
This topic contains the following sections:
Why don't all of the files in my project folder get deployed?
Can I include specific files or folders from outside of my project folder?
When should I use Web Deploy parameters instead of Web.config transformations?
How do I deploy an Entity Framework database that uses DbContext without using Migrations?
How to make Web Deploy use file checksums instead of dates to determine which files were changed?
How can I debug the deployment packaging or publishing process?
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 one-click publish create a package for archival purposes?
Can I specify that a package should be created every time I build a solution?
How do I keep my application domain from restarting multiple times during a long deployment process?
Why do I get an error that says ASP.NET 4 is required when ASP.NET 4 is already installed?
Why does deployment fail when it attempts to execute CREATE USER or CREATE ROLE database commands?
Can I create a single package and use it to deploy to both IIS 6 and IIS 7?
Why does remote deployment fail for large files, although local deployment succeeds?
Can I exclude specific files or folders from deployment?
You can limit the files that are deployed by selecting the Only files needed to run this application or All files in this projectoptions on the Package/Publish Web tab. If you select the All files in this project option, you can right-click a file in Solution Explorer and select Exclude From Project to keep it from being deployed. For more information about what files are excluded when you use the Only files needed to run this application or All files in this project options, see Why don't all of the files in my project folder get deployed?.
If these options are not flexible enough for you, another option is to edit the .pubxml or the .wpp.targets file and add an ExcludeFilesFromDeployment element or an ExcludeFoldersFromDeployment element (or both) in the PropertyGroupelement. In each element, you can specify a single name, or you can specify multiple names delimited by semicolons (;), as shown in the following example:
<PropertyGroup">
<ExcludeFilesFromDeployment>
File1.aspx;File2.aspx
</ExcludeFilesFromDeployment>
<ExcludeFoldersFromDeployment>
Folder1;Folder2
</ExcludeFoldersFromDeployment>
</PropertyGroup>
Another option is to use the PublishIgnore NuGet package. This option is explained in Web Publishing a simpler way to exclude files/folders from being published on the .NET Web Development and Tools blog.
For more information, see the following posts on Sayed Hashimi's blog:
Why don't all of the files in my project folder get deployed?
From the Project menu select Package/Publish Settings to open the Package/Publish Web tab of the Project Propertieswindow. A drop-down list in the section labeled Items to deploy (applies to all deployment methods) offers three options:
Only files needed to run this application. This is the default value. Visual Studio tries to determine which files are required for the application to run successfully. For example, this includes assemblies in the bin folder, files generated during the build, and files marked as Content. To see if a file is marked as Content, select the file in Solution Explorer, and check the file's Build Action property in the Properties window. You can change the Build Action value to Content to cause the file to be deployed, or change it to something else, such as None, to prevent the file from being deployed. Some file types that are automatically set to Content include .master, .svc, .ashx, .asax, .skin, .browser, .config, .and sitemap. A file must be included in the project in order to have a Build Action property.
All files in this project. Visual Studio deploys all files that are included in the project, regardless of their Build Actionproperty values.
All files in the project folder. Visual Studio deploys all files that are in the project folder and subfolders, regardless of whether they are included in the project or their Build Action property values.
If you are familiar with MSBuild syntax, you can find details about how these three options work in the following files:
Microsoft.Web.Publishing.OnlyFilesToRunTheApp.targets
Microsoft.Web.Publishing.AllFilesInTheProject.targets
Microsoft.Web.Publishing.AllFilesInProjectFolder.targets
These files can be found at the following location in a computer that has Visual Studio installed:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\
Can I include specific files or folders from outside my project folder?
Yes. For information about how to do this, see Build Package including extra files or excluding specific files on Sayed Hashimi's blog.
How do I disable Web.config transformation?
You have several options:
Comment out specific transforms in the Web.config transform file.
Rename the transform file to a name that does not correspond to a defined build configuration or a Publish profile. For example, you might change Web.Debug.config to Web.Debugx.config. (You might have to rename the file outside of Visual Studio.)
Delete the transform file. If you have customized the file, the customizations will be lost.
Edit the .pubxml file or .wpp.targets file by adding a TransformWebConfigEnabled element to the PropertyGroupelement and setting its value to False.
When should I use Web Deploy parameters instead of Web.config transformation?
Web Deploy parameters are more complex to set up than Visual Studio Web.config transformations but are very flexible. Web Deploy parameters are complex to set up because they can automate many other deployment tasks, such as updating database scripts and IIS settings. Web Deploy parameters are useful for Web.config transformation when you are creating a deployment package and when you are creating the package you don't know the values that need to go into the deployed Web.config file. Web Deploy parameters let you specify values for the parameters when the package is installed, not just when it is created. This is especially useful in enterprise environments, where it's common for different people to be responsible for creating and installing deployment packages. For example, the developer who creates a package might not know certain passwords that need to be in the Web.config file. The IT administrator who installs the package can enter those values when the package is installed. For more information, see Parameterization vs. Web.config Transformation on Vishal Joshi's blog and How to: Use Web Deploy Parameters in a Web Deployment Package.
How do I deploy a Code First database without Migrations?
When you implement an Entity Framework Code First context class to access a database, the Settings tab of the Publish Webwizard displays a check box that lets you use Code First Migrations to automate deployment for that database. But if you are only accessing the database by using the Code First API, and Code First is not being used to create the database, you can't use Migrations to deploy it. In this scenario, what you want is the Update database check box that lets you deploy a SQL Server database that you don't use a Code First context for.
How do I deploy an Entity Framework database that uses DbContext without using Migrations?
In Visual Studio, if you have the Publish Web wizard open, close it.
In the application Web.config file, create an additional connection string element for the database. Give this new connection string element a name that does not match either the context class name or the fully qualified class name.
Build the project, and then open the Publish Web wizard and select the profile you want to work with.
Select the Settings tab.
You now see two entries for the database in the Databases section of the tab, one for the context class (with the Execute Code First Migrations check box) and one for the new connection string in the Web.config file.
In the entry for the context class, enter the connection string that you want the application to use at run time, and clear the Execute Code First Migrations check box.
In the entry for the new Web.config file connection string, enter the connection string that should be used to make schema changes during deployment, and select Update database.
For more information about how to enter database deployment settings, see How to: Deploy a Web Project Using One-Click Publish in Visual Studio.
How to make Web Deploy use file checksums instead of dates to determine which files were changed?
By default, Web Deploy determines which files need to be copied to the server by comparing the dates that the local files were last changed against the dates that the server files were last changed. If you use a source control system that changes file dates when you check out files, it appears that they have all changed, and Web Deploy copies them all to the server when you publish.
An alternative for this scenario is to configure Web Deploy to use file checksums to determine which files have changed. Use checksums only if file dates are unreliable indicators of what has changed, because comparing checksums takes more CPU processing time than comparing dates.
To configure Web Deploy to use checksums instead of dates to determine which files need to be copied to the server, add the following element to the .pubxml file:
<MSDeployUseChecksum>true</MSDeployUseChecksum>
Insert this element in the PropertyGroup element, as shown below:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSDeployUseChecksum>true</MSDeployUseChecksum>
<!— other settings omitted to keep the example short -->
<PublishDatabaseSettings>
<!— this section omitted to keep the example short -->
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
See also Web publishing updates for app offline and usechecksum.
How to encrypt the Web.config file during deployment?
You can configure Web Deploy to automatically encrypt the Web.config file on the destination server by adding the following element to the .pubxml file:
<MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule>
Insert this element in the PropertyGroup element, as shown below:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSDeployEnableWebConfigEncryptRule>true</MSDeployEnableWebConfigEncryptRule>
<!— other settings omitted to keep the example short -->
<PublishDatabaseSettings>
<!— this section omitted to keep the example short -->
</PublishDatabaseSettings>
</PropertyGroup>
</Project>
This feature only works with Web Deploy 3.5 and later versions, and it does not work in Windows Azure Web Sites. Windows Azure has other options for securely storing sensitive data. For more information, see Windows Azure Web Sites: How Application Strings and Connection Strings Work.
[VS2013]发布网站时修改配置文件的更多相关文章
- VS2013发布网站删除.CS文件
VS2013发布网站时,默认不删除.CS文件,想要删除的话,需要一些配置 1.在要发布的网站上右键,选择"发布网站". 2.在发布窗口中,会让你选择一个发布配置文件,没有的话点 ...
- vs2013发布网站合并程序是出错(ILmerge.merge:error)
Vs2013发布网站时,生成错误提示: 合并程序集时出错: ILMerge.Merge: ERROR!!: Duplicate type 'manage_ForcePasswrod' found in ...
- asp.net core项目发布网站时的选项
发布网站时的选项 Debug 通常称为调试版本,它包含调试信息,并且不作任何优化,便于程序员调试程序. Release 称为发布版本,它往往是进行了各种优化,使得程序在代码大小和运行速度上都是最优的, ...
- VS2010 发布网站时如何使DLL文件名固定
VS在发布网站时,bin目录里为所有cs生成的dll文件每次都是随机命名的,如:App_Web_xxxxxxxx.dll(xxxxxxx是8个小写的字母和数字组成的字符串,随机的),这样对更新 Liv ...
- VS2010 发布网站时文件丢失
问题:使用VS发布网站时,发现一些Flv等文件丢失,没有发布到指定文件夹中. 解决办法:打开文件属性窗口,找到生成操作,选项选择“内容”即可. 详细内容可参考官方文档: http://msdn.m ...
- VS2013发布网站详细步骤
以下是我发布网站的时候,搜索到的可以使用的办法,同样适用于vs2013(已经尝试). 1.打开你的VS2012网站项目,右键点击项目>菜单中 重新生成一下网站项目:再次点击右键>发布: V ...
- 第一次用IIS发布网站时遇到的两个问题
1. 配置错误 说明: 在处理向该请求提供服务所需的配置文件时出错.请检查下面的特定错误详细信息并适当地修改配置文件. 分析器错误消息: 无法识别的属性“targetFramework”.请注意属性 ...
- 使用MSBuild Tools调用csproj项目文件发布网站时$(SolutionDir)宏参数值丢失为空的解决方案
使用Visual Studio打开解决方案,对<网站项目>右键点击<发布>,一切都是正常的,所有宏都可用,宏参数值也是正确的. 而通过批处理脚本命令调用MSBuild.exe对 ...
- vs2013发布网站
第一次在Server2008中发布网站,期间发生了很多的错误,这里记录下来,以供以后的学习. (1).首先在IIS上先建一个网站,(网站名称.物理路径.类型 IP地址 和端口)然后点击确认,这样就是先 ...
随机推荐
- struts2文件上传1
<form action="hello/UploadAction_upload.action" enctype="multipart/form-data" ...
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie
https://blog.csdn.net/cml_blog/article/details/52135115 当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名 ...
- 安装Centos7时提示 /dev/root does not exits
安装centos 7时提示 "Warning: /dev/root does not exist, could not boot" 这个问题是木有找到你的U盘. 在一个能够编辑U盘 ...
- ClusterControl docker 环境搭建
ClusterControl 是一款比较强大的数据库管理平台,包含了丰富的数据库管理功能. 我们可以用来方便的进行数据管理 测试使用docker-compose 管理 环境准备 docker-comp ...
- Singer 学习十二 指南
版本0.3.0 tap是一个应用程序,需要一个配置文件和可选的状态文件作为输入,并产生有序的流记录, 状态和模式信息作为输出. 一个记录是任何类型的JSON编码的数据.tap 状态消息用于保留一个调用 ...
- heptio scanner kubernetes 集群诊断工具部署说明
heptio scanner 是一款k8s 集群状态的诊断工具,还是很方便的,但是有一点就是需要使用google 的镜像 参考地址 https://scanner.heptio.com/ 部署 kub ...
- Promise实例的then方法
- python 高阶函数学习, map、reduce
一个函数可以接收另一个函数作为参数,这样的函数叫做高阶函数. 函数map(): map()函数接收两个参数,一个是函数,一个是Iterable, map把函数作用于序列的每一个元素,并把结果作为Ite ...
- kubernetes 中,Pod、Deployment、ReplicaSet、Service 之间关系分析
deploy控制RS,RS控制Pod,这一整套,向外提供稳定可靠的Service. 详见:https://blog.csdn.net/ucsheep/article/details/81781509
- py-day1-2 python的循环语句
死循环: 条件循环: 练习 第一题: n = 1 while n < 11: if n == 7: pass else: print(n) n = n + 1 print('-----end-- ...