【问题标题】:web.config transforms not being applied on either publish or build installation packageweb.config 转换未应用于发布或构建安装包
【发布时间】:2010-06-16 14:49:48
【问题描述】:

今天我开始在 VS 2010 中使用 web.config 转换。首先,我尝试了与该主题的许多博客文章中相同的 hello world 示例 - 更新连接字符串。

我创建了如下所示的最小示例(类似于this blog 中的示例)。问题是,每当我在 .csproj 文件上右键单击 ->“发布”或右键单击 ->“构建部署包”时,我都没有得到正确的输出。我得到的不是转换的 web.config,而是 no web.config,而是包含两个转换文件。

我做错了什么?感谢您的帮助!

Web.config:

<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <connectionStrings>
    <add name="ConnectionString" 
    connectionString="server=(local); initial catalog=myDB; 
    user=xxxx;password=xxxx" providerName="System.Data.SqlClient"/>
  </connectionStrings>
</configuration>

Web.debug.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="ConnectionString"
      connectionString="server=DebugServer; initial catalog=myDB; 
      user=xxxx;password=xxxx"
      providerName="System.Data.SqlClient"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(name)"/>
  </connectionStrings>
</configuration>

Web.release.config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add name="ConnectionString"
      connectionString="server=ReleaseServer; initial catalog=myDB; 
      user=xxxx;password=xxxx"
      providerName="System.Data.SqlClient"
      xdt:Transform="SetAttributes"
      xdt:Locator="Match(name)"/>
  </connectionStrings>
</configuration>

【问题讨论】:

    标签: c# asp.net visual-studio-2010 web-config


    【解决方案1】:

    不可避免地与这些事情,答案实际上是盯着我的脸。 xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0" 在 web.config 的 &lt;configuration&gt; 节点中的存在意味着我的转换不匹配。删除它解决了这个问题。

    【讨论】:

    • 删除 xml 命名空间属性有副作用吗?我遇到了与您相同的问题,并希望采用与您相同的修复策略,但只是好奇它是否会破坏已经很脆弱的遗留 .NET 2.0 网站....
    • 我也有同样的问题,但是我在 web.config 中的配置节点没有定义命名空间
    • @SpaceBison - 根据this post,命名空间是不必要的。事实上,删除它可以修复智能感知。
    【解决方案2】:

    在您的 web.release.config 和 web.debug.config 文件中,将相同的命名空间添加到您的转换中,ala

    <?xml version="1.0"?>
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
    

    ...

    【讨论】:

      【解决方案3】:

      我遇到了类似的问题,修复是因为我为我的环境设置了解决方案配置,但我从未创建与解决方案配置一致的项目配置。

      检查:

      1. 在“构建”-->“解决方案配置”下
      2. 更改您的“活动 解决方案配置”,并确保您的项目配置 根据您命名的配置文件排列。

      【讨论】:

        【解决方案4】:

        对我来说是这样的:

        (1) 菜单构建-配置管理器

        (2) 在我的案例中选择活动解决方案发布并正确配置它(我在那里选择了调试,因此没有应用来自发布的转换)

        【讨论】:

          猜你喜欢
          • 2013-01-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-07-01
          • 2022-02-19
          • 1970-01-01
          • 2023-04-02
          相关资源
          最近更新 更多