Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

msbuild - _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)MicrosoftVisualStudiov10.0WebApplicationsMicrosoft.WebApplication.targets" />
  <Target Name="AfterBuild">
    <RemoveDir Directories="$(ProjectDir)..OutputMyWeb" ContinueOnError="true" />
    <MSBuild Projects="MyWeb.csproj" Properties="Configuration=Release;WebProjectOutputDir=$(ProjectDir)..OutputMyWeb;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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 MvcApplication1MvcApplication1.csproj

# UseWPP_CopyWebApplication = true requires PipelineDependsOnBuild = false

Long story:

Have a look at VisualStudiov10.0WebApplicationsMicrosoft.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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...