msbuildbuild-automationautomated-deploy

MSBuild - Getting the target called from command line


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.


Solution

  • 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.