.NET Framework Bookmark and Share   
 index > MSBuild > Target (private)
 

Target (private)

Hello,
How canI create a private Target in msbuild. I mean I want a target which can be called from some other target but not from outside (not from command line). ?

Thanks a lot
jimama
You have to be very careful with using conditions on targets . I personally tend to avoid them.

Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build
My Blog: sedodream.com
Visual C# MVP
Sayed Ibrahim Hashimi
You can't. You could add a condition to the target though and set that condition to true before you call it from another target. Of course a command line call could also set the condition to true... Can you post more about your scenario if this a big issue for you. Thanks.. Mike
Mike Fourie
I got this sub target:

<Target Name="SetPublishTargetInvokedFlag">
<CreateProperty Value="true">
<Output TaskParameter="Value" PropertyName="PublishTargetInvoked"/>
</CreateProperty>
</Target>

Which suppose to be called from some other target and the SetPublishTargetInvokedFlag is not supposed to be called from command line. Any way?
jimama
how are you calling that target within your file?
Mike Fourie
<CallTarget Targets="SetPublishTargetInvokedFlag"></CallTarget>

from some other target. Any ideas?
jimama
right, well its not foolproof, but you could do something like this

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Default" DependsOnTargets="SetVariables;SetPublishTargetInvokedFlag"/>
<Target Name="SetVariables">
<PropertyGroup>
<InFile>true</InFile>
</PropertyGroup>
</Target>
<Target Name="SetPublishTargetInvokedFlag" Condition="$(InFile) == 'true'">
<Message Text="Hello from SetPublishTargetInvokedFlag"/>
</Target>
</Project>

if you run msbuild YOURFILE.proj /t:SetPublishTargetInvokedFlag from the command line, the target will not execute. But you can easily change that to msbuild YOURFILE.proj /t:SetPublishTargetInvokedFlag /p:InFile=true and it will run!

Note i used DependsOnTargets rather than CallTarget as there is a 'Feature' in CallTarget
Mike Fourie
But it seems problematic because you can call the SetVariables from the command line and then the SetPublishTargetInvokedFlag that i don't want to be called form command line and then you are not protected again. I mean you hide the SetPublishTargetInvokedFlag but if i will run SetVariables and then SetPublishTargetInvokedFlag - it will be exposed again. Any way to make it private ? Thanks a lot
jimama
Not that I know of.
Mike Fourie
You have to be very careful with using conditions on targets . I personally tend to avoid them.

Sayed Ibrahim Hashimi
My Book: Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build
My Blog: sedodream.com
Visual C# MVP
Sayed Ibrahim Hashimi

You can use google to search for other answers

Custom Search

More Threads

• Can CustomPropertiesForBuild pass an Item/ItemGroup?
• Strange problem with dependencies
• Run set of tasks with multiple data sets
• How to build solution with Reportin Service project by MSBuild
• Debug to Release mode switching takes MINUTES with SP1!?
• Help with MSBuild task
• Error in VS Build: Files has invalid value "<<<<<<< .mine". Illegal characters in path
• BuildItem and directories
• ContinueOnError, yet still failing the build?
• How to report a bug in MSBuild