简体   繁体   中英

Run other than the DefaultTarget for a project configuration under Visual Studio 2010

I've a MSBuild target in my csproj to copy files and folders of my web application to a target path after build.

<Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">
...

If I call MSBuild via command line with the target "PublishToFileSystem" everything works fine.

But now I want to "use" this target also for a special configuration in Visual Studio (like Release, Debug, ...).

How can I assign a configuration to another target than the DefaultTarget "Build" set in the project with DefaultTargets:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Thanks, Konrad

Try to use AfterBuild target instead of PublishToFileSystem:

<Target Name="AfterBuild" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder">

or check Overriding Predefined Targets on MSDN

If you want to do this for a specific solution configuration and you're suffering from ciruclar dependencies as I was, the easiest thing I could come up with is writing your own Target to use as default target. That target starts other targets based on a condition on the configuration.

<Target Name="CustomBuild">
  <CallTarget Targets="SignAndroidPackage" Condition="'$(Configuration)' == 'UITest'"/>
  <CallTarget Targets="Build" Condition="'$(Configuration)' != 'UITest'"/>
</Target>

And then simply change the Default target at the top of the project definition to that CustomBuild target.

<Project DefaultTargets="CustomBuild" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Here's an approach that might suit your need: run a custom msbuild target from VisualStudio

(this is trick #78 in the book MSBuild Trickery )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM