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.
Use MSBuild at a command prompt To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.
To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.
A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.
Builds the targets in the project file that you specify. If you don't specify a project file, MSBuild searches the current working directory for a file name extension that ends in proj and uses that file. You can also specify a Visual Studio solution file for this argument.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With