Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_CopyWebApplication with web.config transformations

I am trying to have my web application automatically Publish when a Release build is performed. I'm doing this using the _CopyWebApplication target. I added the following to my .csproj file:

  <!-- Automatically Publish in Release build. -->   <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />   <Target Name="AfterBuild">     <RemoveDir Directories="$(ProjectDir)..\Output\MyWeb" ContinueOnError="true" />     <MSBuild Projects="MyWeb.csproj" Properties="Configuration=Release;WebProjectOutputDir=$(ProjectDir)..\Output\MyWeb;OutDir=$(ProjectDir)bin\" Targets="ResolveReferences;_CopyWebApplication" />   </Target> 

This works but with one issue. The difference between this output, and the output generated when using the Publish menu item in Visual Studio, is that the Web.Release.config transformation is not applied to the Web.config file when using the MSBuild method. Instead, Web.config, Web.Release.config, and Web.Debug.config are all copied.

Any ideas are appreciated.

like image 999
Jeremy Avatar asked Dec 31 '09 01:12

Jeremy


People also ask

How to add Web config transformation file?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is Xdt transformation?

XDT is a simple and straight forward method of transforming the web. config during publishing/packaging. Transformation actions are specified using XML attributes defined in the XML-Document-Transform namespace, that is mapped to the xdt prefix.

Where is web config file in Visual Studio 2019?

config file is located in the %SystemRoot%\Microsoft.NET\Framework\%VersionNumber%\CONFIG\ folder. The default settings that are contained in the Machine.


1 Answers

I've been hitting my head against the wall for this. After hiking through the MSBuild targets I've come across something very "opaque".

Long story short: Try using the new _WPPCopyWebApplication. It works on my machine. The old _CopyWebApplication does not support transformations for legacy reasons. This is what I do:

msbuild /t:Rebuild /p:OutDir=..\publish\;Configuration=Release;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False MvcApplication1\MvcApplication1.csproj  # UseWPP_CopyWebApplication = true requires PipelineDependsOnBuild = false 

Long story:

Have a look at VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets. It's so wrong. Find _CopyWebApplication in line 70. The comment is:

The original _CopyWebApplication is now a Legacy, you can still use it by setting $(UseWPP_CopyWebApplication) to true. By default, it now change to use _WPPCopyWebApplication target in Microsoft.Web.Publish.targets. It allow to leverage the web.config trsnaformation. [all sic]

Uh oh. UseWPP_CopyWebApplication defaults to false (line 27) which makes sense if you don't want to break the existing _CopyWebApplication. So setting it to true will actually use the new WPP stuff introduced to VS 2010. I prefer this over calling a "hidden" target.

like image 84
Jabe Avatar answered Oct 05 '22 00:10

Jabe