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

人盡茶涼 提交于 2019-12-04 18:05:27

问题


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?


回答1:


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!

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



来源:https://stackoverflow.com/questions/38340292/vs2015-pubxml-how-to-exclude-or-eliminate-the-publishdatabasesettings-section

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!