Reputation: 5329
I have the following dummy build script files:
Common.targets
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Target Name="TargetA">
<Message Text="This is TargetA"/>
</Target>
<Target Name="TargetB">
<Message Text="This is TargetB"/>
</Target>
</Project>
EntryPoint.proj
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<Import Project="Common.targets"/>
<Target Name="EntryPointTarget" DependsOnTargets="TargetA">
<!--But why this message is not shown during build?-->
<Message Text="This is Entry Point Target"/>
</Target>
</Project>
Why is EntryPointTarget message not shown during build?
Upvotes: 1
Views: 324
Reputation: 35911
If you do not specify a target on the commandline and no DefaultTarget is specified then msbuild executes the first target it sees, TargetA in this case. If you switch TargetA and TargetB you'll see TargetB being executed first. If you remove the import and make EntryPointTarget not depend on any other targets EntryPointTarget will be executed. Those aren't proper fixes obviously, so either:
msbuild EntryPoint.proj /t:EntryPointTarget
DefaultTargets=EntryPointTarget
attribute to the Project
tag, then you can just call msbuild EntryPoint.proj
and it will execute EntryPoint.Upvotes: 1