【问题标题】:Visual Studio 2013 uses wrong configuration fileVisual Studio 2013 使用错误的配置文件
【发布时间】:2016-08-31 12:07:02
【问题描述】:

我有一个 C# Web 项目。我打开了配置管理器,选择了“Active solution configuration”

在新窗口中,我输入了名称 (Dev),并没有复制任何设置。我勾选了“创建新项目配置”。

我右键单击我的 Web.config 并选择“添加配置转换”。 Web.Dev.config 按预期缩进在 web.config 下。

我的 web.config 包含错误的数据库值:

<connectionStrings>
    <add name="PdxContext" connectionString="Data Source=badServer; Initial Catalog=badDB; Integrated Security=true; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />
</connectionStrings>

我的 Web.Dev.config 部分包含有效的 DB 值:

<connectionStrings>
    <add name="PdxContext" connectionString="Data Source=.\sql2012; Initial Catalog=test; Integrated Security=True" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>

...但是当我选择 Dev 配置并点击运行时,该站点使用 web.config 文件而不是 web.dev.config 运行(它尝试连接到名为“badDB”的不存在的数据库主机“badServer”)。

如果我右键单击 web.dev.config 并选择“预览转换”,则转换后的 Web.config 正确显示它将使用 web.dev.config 中的 connectionStrings 值。

哦,在“Dev”的活动解决方案配置的配置管理器中,配置列有“Dev”。

有什么想法吗?

【问题讨论】:

  • 我也有与内置调试配置完全相同的问题。它忽略 Web.Debug.config 中的值
  • 我认为它可能只在部署下工作。但是,多个开发人员如何在同一个项目上工作,但配置不同呢?我猜他们必须拥有自己的 web.config 副本,并在每次执行更改 web.config 的 SVN 更新时用他们的副本覆盖 web.config?这看起来很笨拙。

标签: visual-studio-2013 configurationmanager


【解决方案1】:

可以在这里找到解决方案: https://stackoverflow.com/a/3994081

如果您使用的是 Visual Studio 2013,还请参阅 Matti Price 对该帖子的回复,“对于在更高版本的 VS 中遇到此问题的任何人,我必须将 更改为 之后一切正常。"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    • 2014-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 1970-01-01
    相关资源
    最近更新 更多