English 中文(简体)
_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.

最佳回答

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.

问题回答

暂无回答




相关问题
How can I overwrite file web.config with web.other.config?

I have a msbuild script with custom logic to deploy my service to the qa server automatically. I have to overwrite the default config with a dedicated one, but when I use <Copy SourceFiles="web....

How do I use MSBuild on a C# project with no compilable code

I have a C# web app project which actually has no ASP.Net or C# in it. It s just a single html page with some Javascript, CSS, and a couple of images. I want to use MSBuild to deploy a version of ...

您能否防止MSBuild.exe经营活动?

我用文字建造一些项目,偶尔利用习俗制造事件,给建筑系统造成了很大困难。 如果有可能,我想援引MSBuild.exe。

building .net applications without Visual Studio

I m interested to hear about people working with building .net applications using MSBuild, NAnt or similar tools. What are you using, why are you using it instead of the VS IDE? I like to use ...

How long does my Visual Studio C# compile take?

It seems like it should be possible to configure Visual Studio to print out how long the compile takes. Perhaps somewhere in the .sln file. If the sln is compiled from the command line using ...

热门标签