_CopyWebApplication with web.config transformations
Asked Answered
T

1

44

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.

Terry answered 31/12, 2009 at 1:53 Comment(0)
L
76

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.

Levulose answered 1/6, 2010 at 21:11 Comment(3)
I wonder I there is a way to fix copying a libraries referced via other project to be included in msbuild ouput dir?Seeley
I tried to do this with WebDeploy use /p:WebPublishMethod=FileSystem and using the pubxml files. I could not get it to work. This solution is the best way I've found. One word of advice: I couldn't get it to work without the OutDir property set. You'll need to include it in the command line even if it's already defined in your project's properties.Baillie
This also helped with an issue compiling TypeScript files when redirecting build artifacts using `/p:OutDir=..\publish`.Shag

© 2022 - 2024 — McMap. All rights reserved.