在.NET MVC 3.0应用程序中,我有以下配置appSettings:
<appSettings>
<add key="SMTPHost" value="mail.domain.com"/>
<add key="SMTPUsername" value="user@gmail.com"/>
<add key="SMTPPort" value="25"/>
<add key="SMTPPwd" value="mypassword"/>
<add key="EmailFrom" value="notific@gmail.com"/>
</appSettings>
Run Code Online (Sandbox Code Playgroud)
为了调试,我定义了以下配置转换:
<appSettings>
<add key="SMTPPort" value="58" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
我在调试模式下运行应用程序,但我的SMTP端口仍然从web.config,而不是web.Debug.config.
任何人都可以建议这种配置可能出错吗?
asp.net asp.net-mvc web-config web-config-transform slowcheetah
我知道Visual Studio 2010中的web.config提供了从数据库从调试模式切换到发布模式的功能.
这是我的Web.Release.config:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="Testing1" connectionString="Data Source=test;Initial Catalog=TestDatabase;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是我的Web.Debug.config代码:
<?xml version="1.0"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
<add name="Live1" connectionString="Data Source=Live;Initial Catalog=LiveDatabase;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" …Run Code Online (Sandbox Code Playgroud) 如何Web.debug.config在visual studio 2010内置调试器中合并和使用?
我想让web.config转换在本地工作,但显然只在进行部署时才会发生转换.
有没有人知道如何运行msbuild目标"TransformWebConfig"而不通过"rebuild"进程,还指定并输出目录在哪里吐出转换后的web.config?
编辑:使用Sayed的答案,我创建了一个.bat文件来为我运行任务:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Msbuild.exe "D:\Demo\Transformation.proj" /t:TransformWebConfig
copy /Y "D:\Demo\Web.config" "D:\MyProject\Web.config"
del ""D:\Demo\Web.config"
Run Code Online (Sandbox Code Playgroud)
"Transformation.proj"是Sayed的代码片段的副本,在下面的答案中.只需指定转换的源,目标和目标.新文件(在本例中为已转换的"web.config")将位于"D:\ Demo"目录中.我只是将其复制以覆盖我的项目的web.config,最后,删除"demo"文件夹中生成的文件.
另外,我创建了一个宏来运行这个批处理文件并为我执行转换:
Public Module DoTransform
Sub RunTransformBatchFile()
Try
Process.Start("D:\Demo\RunTransform.bat")
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
End Module
Run Code Online (Sandbox Code Playgroud)
您还可以在工具栏上添加一个按钮来运行此批处理和/或指定要执行的快捷键.
asp.net web-config visual-studio-2010 web-deployment msdeploy
我有一个WebForms项目,其中一个连接字符串被硬编码到web.config中(对于Debug - web.Debug.config).此连接字符串指向用于开发的DB服务器.
我想运行该数据库的本地副本,以便我的更改不会立即影响其他人.
我一直在做的是进入web.config并更新连接字符串以指向我的本地数据库.这可行,但有点乏味,因为我必须记住排除web.config,如果我撤消所有更改,必须重新更新它.
因为,就像我说的,其他人正在使用这个解决方案,我想避免检查任何内容或修改Web配置.
有没有办法覆盖web.config连接字符串以强制站点指向我的本地数据库而不检查任何源控件?