How can I exclude web.config when publishing in Visual Studio 2013?

When using the Publish Web Site feature in Visual Studio 2013. How can you prevent the publication of the web.config so that it does not overwrite the web.config server?

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

How do I exclude web.config when publishing to Visual Web Developer Express?

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

+3


source to share


2 answers


Excluding the web.config file is not the recommended solution. Instead, you should use the web.config transform file, which is the web.xxx.config file.

Example of transformation configuration file

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



The configuration configuration file uses XDT (XML Document Transform) syntax. For example, if you want to change your connection string, you can use this piece of code in your transform 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>

      

See Web.config Transformation Syntax for Deploying Web Projects with Visual Studio for more examples and information.

+2


source


Just select web.config properties and change "Build Action" to "None" and "Copy To Output Directory" to "Do not copy"



+13


source







All Articles