c# - web.config 转换未应用于发布或构建安装包

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

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

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

网络调试配置:

<?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>

最佳答案

不可避免地,有了这些东西,答案实际上就在眼前。 xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0"的存在在<configuration> web.config 的节点意味着我的转换不匹配。删除它解决了问题。

关于c# - web.config 转换未应用于发布或构建安装包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3054389/

相关文章:

javascript - 如何在javascript中隐藏进度条

c# - 重复单步调试≠运行调试

visual-studio-2010 - 如何在TFS 2010中找出所有 check out 的文件?

c# - ASP.NET Core 2.0 动态认证

asp.net - MSCharts “No http handler was found for request type ' GET'”错误

c# - C# 文件的结构会影响编译的内容吗?

asp.net - 拆分 ASP.NET MVC Controller

asp.net - 如何在 Visual Studio 中组织 Web 应用程序项目?

c# - 在特定条件下使用 LINQ 从列表中获取数字

c# - 我怎样才能在 C# 中获得 C+ +'s "const"的等价物?