使用Visual Studio 2013发布时如何排除web.config? [英] How to exclude web.config when publishing with Visual Studio 2013?

查看:411
本文介绍了使用Visual Studio 2013发布时如何排除web.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2013中使用发布网站"功能时.如何排除发布web.config以便不覆盖服务器web.config?

When using the "Publish Web Site" feature in Visual Studio 2013. How can you exclude publishing the web.config so that it doesn't overwrite the server web.config?

除了VS版本,问题与以下相同.

The question is identical to the following except the VS version.

如何排除网络.使用Visual Web Developer Express发布时进行配置?

但是,其解决方案不适用于VS2013.在VS2013中找不到生成操作"选项.并设置"ExcludeFilesFromDeployment"会导致编译问题.

However, its solution does not apply to VS2013. "Build Action" option cannot be found in VS2013. And setting "ExcludeFilesFromDeployment" causes compile problems.

推荐答案

不建议使用web.config文件.您应该改用web.config转换文件,这是 web.xxx.config 文件.

Excluding the web.config file is not the recommended solution. You should use web.config transformation file instead, this is the web.xxx.config file.

发布网站时,Visual Studio将合并本地的web.config与相应的 web.xxx.config 文件

When you publish your website, Visual Studio will merge your local web.config with the corresponding web.xxx.config file

配置转换文件使用XDT(XML文档转换)语法.例如,如果您想更改您的 connectionstring ,则可以在转换文件中使用以下代码:

The config transform file use XDT (XML Document Transform) syntax. For example, if you want to change your connectionstring, you can use this piece of code in you transformation file :

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="MyDB" 
         connectionString="value for the deployed Web.config file" 
         xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>

请参见 Web的Web.config转换语法使用Visual Studio进行项目部署以获取更多示例和信息.

See Web.config Transformation Syntax for Web Project Deployment Using Visual Studio for more examples and information.

这篇关于使用Visual Studio 2013发布时如何排除web.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆