对于Visual Studio 2010基于Web的应用程序,我们具有Config Transformation功能,通过该功能,我们可以为不同的环境维护多个配置文件.但是,对于Windows Services/WinForms或控制台应用程序,App.Config文件无法使用相同的功能.
这里提供了一种解决方法:将XDT魔术应用于App.Config.
然而,它并不简单,需要许多步骤.有没有更简单的方法来实现相同的app.config文件?
app-config .net-4.0 visual-studio web-config-transform slowcheetah
我正在使用web.config转换,如下面的帖子所述,以便为不同的环境生成配置.
http://vishaljoshi.blogspot.com/2009/03/web-deployment-webconfig-transformation_23.html
我可以通过匹配键来进行"替换"转换,例如
<add key="Environment" value="Live" xdt:Transform="Replace" xdt:Locator="Match(key)" />
Run Code Online (Sandbox Code Playgroud)
我可以做"插入",例如
<add key="UseLivePaymentService" value="true" xdt:Transform="Insert" />
Run Code Online (Sandbox Code Playgroud)
但我真正觉得有用的是一个ReplaceOrInsert转换,因为我不能总是依赖原始配置文件有/没有某个键.
有没有办法做到这一点?
我在web.config中有以下配置:
<resizer>
<sizelimits imageWidth="0" />
<plugins>
<add name="MvcRoutingShim" />
<!--<add name="AzureReader" connectionString="DataConnectionString" /> -->
<add name="DiskCache" />
<add name="PrettyGifs" />
<add name="AnimatedGifs" />
</plugins>
</resizer>
Run Code Online (Sandbox Code Playgroud)
在web.config.Release中,如何将AzureReader元素添加为plugins元素的子元素(有效地取消注释上面的内容)?
我熟悉如何进行基本的转换,但之前从未这样做过.
在.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
所以,我安装了VS 2010,我正在修改我的TeamBuity构建集成的MSBuild脚本.一切都很好,只有一个例外.
如何告诉MSBuild我要应用我在发布构建时创建的Web.conifg转换文件...
我有以下产生编译的网站但它,它将Web.config,Web.Debug.config和Web.Release.config文件(全部3)输出到编译的输出目录.在工作室中,当我执行发布到文件系统时,它将执行转换并仅输出具有适当更改的Web.config ...
<Target Name="CompileWeb">
<MSBuild Projects="myproj.csproj" Properties="Configuration=Release;" />
</Target>
<Target Name="PublishWeb" DependsOnTargets="CompileWeb">
<MSBuild Projects="myproj.csproj"
Targets="ResolveReferences;_CopyWebApplication"
Properties="WebProjectOutputDir=$(OutputFolder)$(WebOutputFolder);
OutDir=$(TempOutputFolder)$(WebOutputFolder)\;Configuration=Release;" />
</Target>
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒..!
我知道这可以通过其他方式完成,但我想尽可能使用新的VS 2010方式
我有一个带有几个ConnectionStrings的Web.config
<connectionStrings>
<add name="connStr1" connectionString="...
<add name="ConnStr2" connectionString="...
<add name="connStr3" connectionString="...
Run Code Online (Sandbox Code Playgroud)
有没有办法使用配置转换来删除特定的连接字符串?就像是:
<connectionStrings>
<xdt:Remove connStr2?
Run Code Online (Sandbox Code Playgroud)
显然没有接近正确的语法,但你得到我的漂移...
当且仅当目标中不存在匹配的元素时,我想应用转换.使用http://webconfigtransformationtester.apphb.com/尝试各种xpath表达式,但到目前为止没有运气.
例如,如果目标web.config看起来像这样:
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后输出应该如下所示:
<configuration>
<connectionStrings>
<add name="MyCs" provider="System.Data.SqlClient" connectionString="" />
<add name="SomeOtherCs" provider="System.Data.SqlClient" connectionString="" />
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但如果目标看起来像这样:
<configuration>
<connectionStrings>
<add name="MyCs" provider="System.Data.IChangedIt" connectionString="my connection string here" />
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
然后转换的结果应如下所示:
<configuration>
<connectionStrings>
<add name="MyCs" provider="System.Data.IChangedIt" connectionString="my connection string here" />
<add name="SomeOtherCs" provider="System.Data.SqlClient" connectionString="" />
</connectionStrings>
<system.web>
<compilation debug="true" />
</system.web>
</configuration>
Run Code Online (Sandbox Code Playgroud)
换句话说,我只想将命名连接字符串添加到配置中,但让管理员用自己的值填充它.我认为它会如此简单xdt:Transform="Insert" xdt:Locator="XPath(count(/configuration/connectionStrings)=0)"(如果不存在则添加cs配置节)但显然不是.
我有一个web.config重写规则指定将所有流量移动到https.该规则有效,但我在调试时不需要SSL.我已经完成了一堆web.release.config转换工作,因此我决定在那里放一个重写规则.问题是重写规则没有像其他设置那样进行转换.这是web.config设置:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<rewrite></rewrite>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)
以下是正在进行的转型:
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect HTTP to HTTPS" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{HTTPS}" pattern="^OFF$"/>
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther"/>
</rule>
</rules>
</rewrite></system.webServer>
Run Code Online (Sandbox Code Playgroud)
如果我只是将重写规则复制到web.config它可以正常工作.有没有人有任何想法为什么web.Release.config转换不仅适用于此部分?
我试图让我的TFS Build创建与我为我的构建选择的配置相关联的web.config转换.当我运行构建时,我检查web.config文件没有应用转换.当我从VS2012发布时,转换正常.
我已经设置了TFS 2012(Update 2),并且有一个单独的构建服务器.我没有在构建服务器上安装VS2012,但我将C:\ Program Files(x86)\ MSBuild\Microsoft\VisualStudio\v11.0\Web和WebApplications文件夹和文件从我的开发机器复制到构建服务器.
我在我的项目中创建了一些配置,并在关联的网站上添加了一些转换.{configname} .config.
我已经创建了一个构建并将要构建的项目 - 要构建的配置设置为我项目中的一个配置.我注意到它只有Debug和Release,它没有我创建的任何配置.(附带问题:这是正确的,还是应该显示我创建的所有配置?)
所以我运行构建并检查输出文件夹,web.config尚未应用转换.还有什么我需要做的吗?
我有一个ASP.NET Web应用程序项目,通过实体框架连接到远程数据库.在调试期间(例如,在我的本地计算机上运行项目),数据库的IP地址与发布期间的IP地址不同(例如,在将项目上载到我的Web服务器并从浏览器运行之后).到目前为止,我总是手动更改Web.config文件中的数据库连接字符串以在两者之间切换(基本上我必须连接字符串,一个名为'Debug',一个'Release',我只是在部署时交换名称).
现在我只是注意到应该可以通过Web.config Transformation Syntax自动发生这种情况,你可以将修改后的连接字符串放在Web.Release.config版本中,然后在Release版本下构建DLL时应该使用它.
但它似乎对我不起作用......
这是我的常规Web.config文件的相关部分(其中包含用于本地使用的Debug连接字符串):
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<!-- Debug connection string. Release connection string is in Web.Release.config file -->
<add name="DatabaseEntities" connectionString="A" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
这是Web.Release.config文件,如果DLL处于Release模式下,根据示例应将"DatabaseEntities"连接字符串"A"替换为"B":
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!-- Replace the DatabaseEntities connection string with the Release version (local IP address) -->
<connectionStrings>
<add name="DatabaseEntities"
connectionString="B"
xdt:Transform="Replace" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
(显然"A"和"B"只是我真实连接字符串的占位符)
当我调试应用程序时(例如只按F5),使用默认的Web.config,我可以访问数据库.然后,我通过Configuration Manager将构建配置更改为Release.解决方案中的所有项目都设置为发布配置.然后我构建解决方案(仅通过Build或甚至通过完整的重建(例如Clean,Rebuild)).我将新构建的DLL上传到Web服务器,以及Web.config和Web.Release.config文件,当我尝试访问我无法访问的数据库时,它仍然试图通过调试IP地址访问数据库因此无法找到它......
似乎Web.Release.config文件被完全忽略,或者至少没有替换连接字符串.
我究竟做错了什么?转换语法错了吗?我没有正确地在发布模式下构建应用程序吗?
asp.net ×6
web-config ×5
asp.net-mvc ×2
slowcheetah ×2
.net ×1
.net-4.0 ×1
app-config ×1
build ×1
c# ×1
msbuild ×1
release ×1
tfs2012 ×1
tfsbuild ×1
xml ×1
xpath ×1
xslt ×1