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.
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>
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.
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.
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.
来源:https://stackoverflow.com/questions/150047/msbuild-getting-the-target-called-from-command-line