Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 944
ferventcoder Avatar asked Sep 29 '08 18:09

ferventcoder


People also ask

How use MSBuild command line?

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.

How do I run MSBuild target?

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.

What is MSBuild target?

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.

What does MSBuild command do?

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.


2 Answers

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>
like image 165
Tim Booker Avatar answered Oct 20 '22 19:10

Tim Booker


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.

like image 24
ferventcoder Avatar answered Oct 20 '22 19:10

ferventcoder