有没有办法在Web部署之外应用VS 2010 Web.Config转换,在调试期间?这将给我一个很大的推动力,以便能够在不同环境之间自由切换.
解决方法
是的,您可以通过在项目文件中的AfterBuild步骤期间调用TransformXml MSBuild任务来显式执行Web.config转换.
以下是一个例子:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> <Target Name="AfterBuild" Condition="exists('Web.$(Configuration).config')"> <!-- Generates the transformed Web.config in the intermediate directory --> <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)Web.config" Transform="Web.$(Configuration).config" /> <!-- Overwrites the original Web.config with the transformed configuration file --> <Copy SourceFiles="$(IntermediateOutputPath)Web.config" DestinationFolder="$(ProjectDir)" /> </Target>
相关资源:
> Web.config transformations for App.config files
> Can I specify that a package should be created every time I build a solution?