Question

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

Was it helpful?

Solution

Try to use AfterBuild target instead of PublishToFileSystem:

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

or check Overriding Predefined Targets on MSDN

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top