我的方法有点问题web.debug.config
and web.release.config
files.
更具体地说,我的网页只会使用默认的web.config
文件,并完全忽略debug
and release
文件。
不仅当我在本地运行项目时会发生这种情况,而且当我将其发布到 IIS 服务器时也会发生这种情况。
我正在使用 Visual Studio 2010 Ultimate(无 Service Pack)。
以下是配置文件:
web.config
:
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="MyConn" connectionString="SomeConnectionString"
providerName="System.Data.SqlClient"/>
</connectionStrings>
</configuration>
web.debug.config
and web.release.config
:
<?xml version="1.0"?>
<configuration xmlns:xtd="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="MyConn" connectionString="SomeOtherConnectionString"
providerName="System.Data.SqlClient"
xtd:Transform="Replace"
xtd:Locator="Match(name)"/>
</connectionStrings>
</configuration>
正如我之前提到的,该网站使用来自web.config
文件,而不是来自web.release.config
.
另一个有趣的点是,在我发布项目的物理文件夹中,所有三个config
文件存在;每个都与 VS 解决方案中出现的完全相同。
有建议吗?
您需要运行转换。如果你只是将 3 个 web.config 放在你的文件夹中,它将不起作用。你可以运行它,它将改变你的 web.config
MSBuild.exe Project.csproj /T:TransformWebConfig /P:Configuration=Release
然后,您将在构建时创建的 obj 文件夹中创建一个名为 TransformWebConfig 的文件夹。转换后的 web.config 将在其中。
您还可以看看这篇文章,他创建了一个构建目标来自动实现这一点。
http://vishaljoshi.blogspot.com/2010/05/applying-xdt-magic-to-appconfig.html http://vishaljoshi.blogspot.com/2010/05/applying-xdt-magic-to-appconfig.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)