我的持续集成服务器(TeamCity)配置为在构建时运行我们应用程序中的所有单元测试。在运行这些测试之前,我需要更改一些 appSettings 以使它们对我们的 CI 服务器有效。我通过使用 Visual Studio 提供的部署项目为我的 Web 项目实现了类似的目标。我可以对测试项目做同样的事情吗?
谢谢,贡萨洛
有可能对 App.config 文件使用 Web.config 转换通过解决方法。
您只需在构建过程的正确阶段调用适当的 MSBuild 任务即可。
将此代码片段添加到您的项目文件中:
<UsingTask
TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('App.$(Configuration).config')">
<!-- Generates the transformed App.config in the intermediate directory -->
<TransformXml
Source="App.config"
Destination="$(IntermediateOutputPath)$(TargetFileName).config"
Transform="App.$(Configuration).config" />
<!-- Forces the build process to use the transformed configuration file -->
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config"/>
<AppConfigWithTargetPath
Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
Then 添加额外的 App.config 文件到您希望应用转换的每个构建配置的项目。例如:
<ItemGroup>
<None Include="App.config" />
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</None>
</ItemGroup>
相关资源:
- Web 应用程序项目部署的 Web.config 转换语法 http://msdn.microsoft.com/en-us/library/dd465326.aspx
- .Config文件转换 http://www.olegsych.com/2010/12/config-file-transformation/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)