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?
Figured out a way:
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.
In addition, uncheck this. I don't know about you but the thought of a pubxml deploying anything to my database terrifies me!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With