How not to publish an asp.net mvc configuration file

2

I am separating my web.config into several files, for example, there is now connections.config that my web.config refer as follows <connectionStrings configSource="connections.config"/>

I will upload this connections.config files to the development data, but on the production server there will be one of them with the production connection data.

How do I not publish the files that are in the project, with the development data, on top of what is on the server.

I publish the system by right-clicking the project, publisher. where I set up a profile of FTP .

What do I need to do to never publish the file connections.config ?

Updating:

I'm using VS2015

    
asked by anonymous 28.07.2015 / 18:09

1 answer

2

Using Transformation Files .

Notice that your Web.config file derives to two others:

  • Web.Release.config ;
  • Web.Debug.config .

When you publish to production, change Release .

I suppose your Web.config should be something like this:

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

In Web.Release.config , you will use this:

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  ...
  <connectionStrings xdt:Transform="Remove" />
  ...
</configuration>

Make a Publish pointing to Release setting and see what happens to Web.config in the publishing directory.

EDIT

By your comment, I think you also want the file not to appear in the post.

  • In Solution Explorer , right-click on the file;
  • Select Properties;
  • In the Build Action row, select None .
28.07.2015 / 18:34