Search code examples
asp.netvisual-studio-2013vs-web-site-project

ASP.Net Website - publishing doesn't move all files


When publishing my ASP.Net Website (not a Web Application), the publisher does not include the Web.ConnectionStrings.config file that is next to the web.config. This is required since my web config looks like this:

<connectionStrings configSource="Web.ConnectionStrings.config"/>

How can I get a File System Publish to include files that Visual Studio seems to be ignoring. Please note that this is a website created using [File] > [New Website] in Visual Studio, not a [File] > [New Project] ASP.Net site so Content=Include will not work.

Steps to reproduce:

  1. In Visual Studio: File > New > Website..
  2. Create the Web.ConnectionStrings.config xml document (see ConnectionStrings.config code below).
  3. In the web config link up the Web.ConnectionStrings.config file to the Web.Config file (see Web.config code below)
  4. Publish the website to a folder on your file system, the Web.ConnectionStrings.config doesn't move with the rest of the files.

Web.config:

<configuration>
  <connectionStrings configSource="Web.ConnectionStrings.config"/>
  ..

Web.ConnectionStrings.config:

<?xml version="1.0" encoding="utf-8" ?>
<connectionStrings>
  <add name="connString" connectionString="yourConnectionstringhere"/>
</connectionStrings>

Solution

  • The way you publish the website is OK.

    But the name of the file into which the connectionstrings get stored must not start with the prefix web., just call it connectionstrings.config instead.

    In web.config you put:

    <configuration>
      <connectionStrings configSource="connectionStrings.config"/>
    

    In the renamed file connectionstrings.config you place:

    <?xml version="1.0" encoding="utf-8" ?>
    <connectionStrings>
      <add name="connString" connectionString="yourConnectionstringhere"/>
    </connectionStrings>