14

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.

Liam
  • 27,717
  • 28
  • 128
  • 190
ferventcoder
  • 11,952
  • 3
  • 57
  • 90

4 Answers4

11

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>
Tim Booker
  • 2,801
  • 1
  • 25
  • 36
8

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.

ferventcoder
  • 11,952
  • 3
  • 57
  • 90
  • 4
    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? – Franci Penov Oct 01 '08 at 21:42
  • 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. – ferventcoder Oct 03 '08 at 05:27
5

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.

Franci Penov
  • 74,861
  • 18
  • 132
  • 169
-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.

kodefuguru
  • 554
  • 4
  • 4