Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2015 pubxml: how to exclude or eliminate the <PublishDatabaseSettings> section

I need to exclude database related settings from the Web Deploy publishing. I tried to delete the section in the pubxml file, but it comes back when I create a deployment package.

Is there any way way to exclude database related settings from the Web Deploy publishing?

like image 800
Allan Xu Avatar asked Jul 12 '16 23:07

Allan Xu


1 Answers

Figured out a way:

  • Externalize the config with configsource

Change your web.config to include connection strings as an external file.

<connectionStrings configSource="web.connectionstrings.config"/>

Then add a new file web.connectionstrings.config and it should be in exactly this format (by that I mean no higher level nodes needed):

<connectionStrings>
  <add name="DefaultConnection" connectionString="Data Source=localhost; Initial Catalog=DEFAULT; Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>

The stupid publish tool isn't smart enough to look in here.

Avoid editing database-related settings in the .pubxml file, because Visual Studio changes these automatically as it finds changes in the project.

Now if you have some connections strings you DO want deployed, and some you don't then that's a different story and you'll have to find some other way to merge them in.

I might add if you are facing this problem in the first place you may be doing deployment wrong, but this was a solution for me because I really did want the hardcoded values to be deployed.

Although not directly addressing this issue - thanks to @scotthanselman who inspired this answer by taking about secret connection strings in this article.


Beautiful!

enter image description here

In addition, uncheck this. I don't know about you but the thought of a pubxml deploying anything to my database terrifies me!

enter image description here

like image 118
Simon_Weaver Avatar answered Sep 27 '22 02:09

Simon_Weaver