MSBuild - Getting the target called from command line
Asked Answered
A

4

15

Does anyone know how to get the name of the TARGET (/t) called from the MSBuild command line? There are a few types of targets that can be called and I want to use that property in a notification to users.

Example:

msbuild Project.proj /t:ApplicationDeployment /p:Environment=DEV

I want access to the target words ApplicationDeployment in my .Proj file.

Is there a property I can access? Any clue how to do this?

EDIT: I do not want to have to also pass in a property to get this.

UPDATE: This is based on deployment scripts using MSBuild scripts. My build server is not used for deploying code, only for building. The build server itself has build notifications that can be opted into.

Aviles answered 29/9, 2008 at 18:40 Comment(0)
A
7

I found the answer!

<Target Name="ApplicationDeployment" >
    <CreateProperty Value="$(MSBuildProjectName) - $(Environment) - Application Deployment Complete">
      <Output TaskParameter="Value" PropertyName="DeploymentCompleteNotifySubject" />
    </CreateProperty>

I would like to give partial credit to apathetic. Not sure how to do that.

Aviles answered 30/9, 2008 at 16:4 Comment(2)
How is that an answer to your question? This will not give you the list of the targets invoked on the command line, it will create the new property when particular task is executed. Was your question wrong?Sorn
In essence this achieves the same end result. This will let you set a property that can tell you what the called target was (in my case AppDeploy vs DBDeploy). In each instance of getting to each target you could set this same property. I elaborated some more by adding things to the value I create.Aviles
O
10

I'm not sure how to do exactly what you ask, but could you pass that string using the /p option?

msbuild Project.proj /t:ApplicationDeployment /p:Environment=DEV;MyValue=ApplicationDeployment

The only other way I can see to do it is to use a conditional property in each target, and thus establish the first target to be invoked.

<Target Name="ApplicationDeployment">
<PropertyGroup>
  <InvokedTarget Condition="'${InvokedTarget}'==''">ApplicationDeployment</InvokedTarget>
</PropertyGroup>

...
</Target>
Olivas answered 29/9, 2008 at 19:29 Comment(6)
I could, but I would like to know how to access the target itself.Aviles
Thanks for the down vote. I did read the MSBuild documentation to check, and I don't believe MSBuild offers this information. Workaround offered.Olivas
Property Group doesn't work inside of a target. How is that for awesome?Aviles
Hmm, there are plenty of examples in Microsoft.TeamFoundation.Build.targets of PropertyGroup being used inside target. Perhaps this is a TeamBuild-only thing.Olivas
Perhaps this is a MSBuild 2008 thing?Aviles
This workaround only works if you control the definition of the target in question.Duffie
A
7

I found the answer!

<Target Name="ApplicationDeployment" >
    <CreateProperty Value="$(MSBuildProjectName) - $(Environment) - Application Deployment Complete">
      <Output TaskParameter="Value" PropertyName="DeploymentCompleteNotifySubject" />
    </CreateProperty>

I would like to give partial credit to apathetic. Not sure how to do that.

Aviles answered 30/9, 2008 at 16:4 Comment(2)
How is that an answer to your question? This will not give you the list of the targets invoked on the command line, it will create the new property when particular task is executed. Was your question wrong?Sorn
In essence this achieves the same end result. This will let you set a property that can tell you what the called target was (in my case AppDeploy vs DBDeploy). In each instance of getting to each target you could set this same property. I elaborated some more by adding things to the value I create.Aviles
S
6

There's no way to do this (that I am aware of). MSBuild doesn't have a property for the list of targets requested to build.

However, if you find a way, keep in mind that it might not be a single target, but instead a list of targets to build.

Sorn answered 29/9, 2008 at 19:51 Comment(0)
D
-3

I'd recommend using a server like CCNET to handle build executions and notification. Sure, you can do things to your MSBuild script to send out notificatioms, but that domain belongs to the build server.

Danella answered 29/9, 2008 at 21:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.