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

1

12

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?

Willamina answered 12/7, 2016 at 23:17 Comment(3)
Where you ever able to fix this?Bolection
@DirkBoer: no, I gave up.Willamina
@AllanXu managed to find this by googling for "no i gave up" pubxmlBerne
B
3

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

Berne answered 25/4, 2017 at 1:18 Comment(3)
If you're using web.config transformations for connection strings you'll want to do something like this too #31338433Berne
PS. Don't forget deploy the connectionstrings file ;-)Berne
Everyone uses web.config transforms. It's INSANE that these pubxml files override it and try to force another string to be used in the pubxml file. It's impossible to remove too. When you uncheck 'use this connection string at runtime' in publish settings, it just leaves it there anyway. And if you toggle the setting, it repeatedly adds duplicate lines to the pubxml file. This all started since they updated the U.I. for publishing in VS 2015 or 2017 and it's broke as hell.Athiste

© 2022 - 2024 — McMap. All rights reserved.