标签: web-config-transform

App.Config转换为Visual Studio中不是Web项目的项目?

对于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

528
推荐指数
9
解决办法
20万
查看次数

有没有办法使用web.config转换进行"替换或插入"?

我正在使用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转换,因为我不能总是依赖原始配置文件有/没有某个键.

有没有办法做到这一点?

asp.net xslt web-config-transform xdt-transform

172
推荐指数
4
解决办法
9万
查看次数

Web Config转换以添加子元素

我在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元素的子元素(有效地取消注释上面的内容)?

我熟悉如何进行基本的转换,但之前从未这样做过.

asp.net web-config web-config-transform

99
推荐指数
1
解决办法
3万
查看次数

Web Config Transform无法正常工作

在.NET MVC 3.0应用程序中,我有以下配置appSettings:

web.config中

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

为了调试,我定义了以下配置转换:

web.Debug.config

<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

82
推荐指数
5
解决办法
5万
查看次数

MSBuild脚本和VS2010发布应用Web.config转换

所以,我安装了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方式

xml asp.net msbuild visual-studio-2010 web-config-transform

70
推荐指数
4
解决办法
3万
查看次数

如何使用配置转换删除ConnectionString

我有一个带有几个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)

显然没有接近正确的语法,但你得到我的漂移...

.net c# web-config visual-studio web-config-transform

65
推荐指数
2
解决办法
4万
查看次数

Web配置转换:如果不存在则插入

当且仅当目标中不存在匹配的元素时,我想应用转换.使用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配置节)但显然不是.

xpath web-config web-config-transform

46
推荐指数
4
解决办法
2万
查看次数

如何使用web.Release.config转换进行URL重写?

我有一个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转换不仅适用于此部分?

asp.net asp.net-mvc web-config-transform

45
推荐指数
3
解决办法
1万
查看次数

TFS 2012和web.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尚未应用转换.还有什么我需要做的吗?

tfsbuild web-config-transform tfs2012

30
推荐指数
2
解决办法
1万
查看次数

Web.config Build vs Release转换不起作用

我有一个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 release web-config build web-config-transform

29
推荐指数
1
解决办法
3万
查看次数