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.
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_CopyWebApplicationdoes not support transformations for legacy reasons. This is what I do:Long story:
Have a look at
VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets. It’s so wrong. Find_CopyWebApplicationin line 70. The comment is:Uh oh.
UseWPP_CopyWebApplicationdefaults 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.