有人可以指出我在这里做错了什么吗?
我正在尝试设置一个 ASP.NET Web 应用程序项目,以使用两个版本的 web.config 文件进行编译,以进行发布和调试版本。因此,为了简单起见,这是我的 web.config:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="WhyMicrosoftSucksSoMuch" connectionString="" 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="WhyMicrosoftSucksSoMuch"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename='C:\FilePath\Database1.mdf';User Instance=true"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(connectionString)" />
</connectionStrings>
</configuration>
如果我在调试配置下发布它,生成的 web.config 看起来不错,但是当我尝试在调试配置下从 VS2010 运行我的项目时,当我的逻辑尝试访问数据库时,我会收到错误:
The ConnectionString property has not been initialized.
那么这里有什么技巧呢?
PS。请不要将我指向 this document 。我试着读了好几次,但太多多余的信息让我头疼。我猜 MS 不知道brief是什么。最佳答案
在 Debug模式下运行它时,它不会应用任何转换。
它仅在发布期间应用它们。您可以将调试连接字符串放在主 web.config 中,并将生产连接字符串添加到 web.release.config
此外,您可能会想使用
xdt:Transform="Replace"
关于asp.net - 无法弄清楚 VS2010 中的 web.debug.config 与 web.config 替代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9387232/