VS2015 pubxml:如何排除或消除<PublishDatabaseSettings>部分 [英] VS2015 pubxml: how to exclude or eliminate the <PublishDatabaseSettings> section

查看:62
本文介绍了VS2015 pubxml:如何排除或消除<PublishDatabaseSettings>部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 Web 部署发布中排除数据库相关设置.我试图删除 pubxml 文件中的部分,但是当我创建部署包时它又回来了.

有没有办法从 Web Deploy 发布中排除数据库相关设置?

解决方案

想出了一个办法:

  • 使用 configsource
  • 外部化配置

更改您的 web.config 以包含连接字符串作为外部文件.

然后添加一个新文件 web.connectionstrings.config,它应该是这种格式(我的意思是不需要更高级别的节点):

<添加名称=默认连接"connectionString=数据源=本地主机;初始目录=默认;集成安全=真"providerName=System.Data.SqlClient"/></connectionStrings>

愚蠢的发布工具

此外,取消选中此项.我不了解您,但是想到 pubxml 将任何内容部署到我的数据库中的想法让我感到害怕!

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:

  • 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!

这篇关于VS2015 pubxml:如何排除或消除&lt;PublishDatabaseSettings&gt;部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆