How not to publish an Asp.net mvc configuration file

Asked

Viewed 246 times

2

I’m separating my web.config in several files, for example, there is now connections.config that my web.config reference as follows <connectionStrings configSource="connections.config"/>

I will go up to version control that files Connections.config with the development data, but on the production server will exist one of it with the production connection data.

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

I do the publication of the system by right-clicking on the project, Publisher. where I set up a profile of FTP.

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

Updating:

I’m wearing VS2015

1 answer

2


Using files of transformation.

Note that your file Web.config drift to two other:

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

When you publish in production, change the Release.

I suppose your Web.config should be more or less like this:

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

In the Web.Release.config, you will wear so:

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

Make a Publish pointing as configuration Release and see what happens to the Web.config in the publication directory.


EDIT

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

  • In the Solution Explorer, right click on the file;
  • Select the Properties option;
  • On the line Build Action, select None.
  • In vdd he published the file connections.config and removed the <connectionStrings configSource="connections.config"/> of web.config, what I wanted was for him to publish the web.config, but did not publish the connections.config. Or I saw wrong?

  • @user3517631 I edited the answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.