bwe*_*rks 6 c# msbuild app-config web-config web-config-transform
我的团队爱上了发布个人资料.我们有许多测试环境,使用Web.config转换,我们可以替换每个环境中的机器名称,配置设置等,这使我们的构建/部署/测试过程更加容易.
例如:
Web.config
Web.dev.config
Web.int.config
Web.prod.config
Run Code Online (Sandbox Code Playgroud)
但是,我们有许多测试应用程序可用于访问我们的Web服务,实现为控制台应用程序.我们希望能够在这些配置文件上进行相同类型的转换,这样我们就可以在拾取构建丢弃时减少与手动编辑配置文件相关的测试手工操作.
基本上,我们想要这个:
App.config
App.dev.config
App.int.config
App.prod.config
Run Code Online (Sandbox Code Playgroud)
我对这些配置转换的理解是它们与我们的Web项目中相应的发布配置文件相关:
Properties
PublishProfiles
dev.pubxml
int.pubxml
prod.pubxml
Run Code Online (Sandbox Code Playgroud)
我试图将类似的文件添加到我们的控制台应用程序项目中,但我怀疑它是Web发布MSBuild目标中实际使用它们的东西.
有没有办法专门挂钩到构建的这一部分,以便我们可以转换非Web配置?
小智 9
要将多个app.configs添加到控制台应用程序:
我正在使用visual studio 2013.在这个版本中,我们没有配置转换.请安装配置转换扩展.
首先在解决方案配置中添加环境 右键单击该App.config
文件.单击Add config Transform.它增加了解决方案配置的数量.
在App.config
:
<appSettings>
<add key="key" value="some value" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
复制此代码App.Release.Config
:
<appSettings>
<add key="same key which you have given in app.config" value="some new value" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
Run Code Online (Sandbox Code Playgroud)
最后,构建解决方案.
我一直在为 Azure WebJobs 项目寻找一种简单的解决方案,以便在构建过程中转换 App.config,以便与服务器上的 Visual Studio 和 MSBuild 配合使用。
对于 Azure WebJobs 项目,以下添加有.csproj
帮助:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="Exists('App.$(configuration).config')">
<Message Text="Transforming config files..." Importance="high" />
<TransformXml Source="App.config" Transform="App.$(Configuration).config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" />
<PropertyGroup>
<AppConfig>$(IntermediateOutputPath)$(TargetFileName).config</AppConfig>
</PropertyGroup>
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(AppConfig)" Condition="'$(AppConfig)'!=''">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Run Code Online (Sandbox Code Playgroud)
与构建一起使用,不需要扩展,并且 App.config 不会被覆盖。基于Dia Louhichi 的回答。
我找到的最简单的解决方案是使用 Slowcheetah;他们的网站上有使用 MSBuild 等的教程,我相信在从开发推到质量检查等之后可以正确切换。
http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5
它只适合我:)
归档时间: |
|
查看次数: |
10767 次 |
最近记录: |