Apply Web.Config transformations outside of a web deployment

Is there any way to apply VS 2010. Converting Web.Config beyond web deployment, say during debugging? This will give me a big push to be able to freely switch between different environments.

+10
web-config
Jun 22 2018-11-11T00:
source share
2 answers

Yes, you can explicitly perform the Web.config conversion by invoking the TransformXml MSBuild task during the AfterBuild step in the project file.

Here is an example:

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

Related Resources:

+15
Jun 22 2018-11-11T00:
source share

The above solution made an excellent starting point for me, but in the end I got the following, which does not require a copy task and does not have problems with file usage errors.

 <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> <Target Name="AfterBuild"> <TransformXml Condition="exists('$(TempBuildDir)\Web.$(Configuration).config')" Source="$(TempBuildDir)\Web.config" Destination="$(OutputPath)Web.config" Transform="$(TempBuildDir)\Web.$(Configuration).config" /> <ItemGroup> <DeleteAfterBuild Include="$(OutputPath)Web.*.config" /> </ItemGroup> <Delete Files="@(DeleteAfterBuild)"> <Output TaskParameter="DeletedFiles" PropertyName="deleted" /> </Delete> <Message Text="DELETED FILES: $(deleted)" Importance="high" /> </Target> 
+3
Dec 20 '11 at 16:35
source share



All Articles