Search code examples
msbuildmsbuild-taskmsbuild-4.0

How can I know which properties are applicable for MSBuild?


From here, I get to know how to create a Web Deployment Package with MSBuild. The command line looks like this:

MSBuild "MyProjectName.csproj" /T:Package /P:Configuration=Staging;PackageLocation="D:\Vishal\Package.zip"

The Configuration, PackageLocation are both properties.

I just wonder how can I know which properties are applicable? And their formal definitions?

I searched the MSBuild Reserved and Well-Known Properties, but they are not there. And I searched the MSBuild Task, still no luck.

ADD

It seems different project types have their specific properties. For example, the PackageLocation property should be specific to a Web Application project. What I am looking for is the specific definition of these properties.

ADD 2

I have a MSBuild task as below.

> <MSBuild Targets="Clean; Package"
> Projects="$(XXXSolutionDirectory)\Web\Web.csproj"
> Properties="Configuration=$(Configuration); Platform=$(Platform);
> OutputPath=$(BinDirectory)\Web_Deployment_Package;
> PackageLocation=$(BinDirectory)\Web_Deployment_Package;
> PublishDir=$(BinDirectory); OutDir=$(BinDirectory);
> IntDir=$(IntDirectory); TfsBuild=$(TfsBuild);
> CscToolPath=$(CscToolPath); CscToolExe=$(CscToolExe);
> VbcToolPath=$(VbcToolPath); VbcToolExe=$(VbcToolExe);
> TargetProfile=$(XXXConfiguration)"></MSBuild>

The properties such as PackageLocation are placed within the Properties attribute of MSBuild task. Rather than in a PropertyGroup definition. And this is the only place it shows up in the build proj file. So where can I find its definition to understand its intended usage?


Solution

  • Ok, let's start first with the bit of fundamental processing pipeline of MSBuild. When msbuild engine parses your proj file - it takes all

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.CSharp.targets
    

    around line 379 you can see

    <Import Project="Microsoft.Common.targets" />
    

    this means - in the final big script - instead of line 379 you'll see the content of c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets

    then in the next phase - msbuild will calculate all Global Properties and Items values. It has some rules on which value (because you may have multiple property declarations with different values which will end up in a property with single value - usually last one or global one wins) will be assigned to property, but I'll omit these details here.

    And the properties you specified in msbuild command line also participating in this process. Particular property declaration can be in more than one .targets file but that really doesn't matter. What's matter is - what value this property will have at the end of global property processing phase. But if you really want to know where is particular property is defined - you need to manually search through all imported .targets files and find property declaration tag. Targets files can be in your .NET Fw folder or in installed SDKs (if you have specific project types like Azure .ccproj ones)

    For example - let's take most popular property "Configuration". I sought in all .targets files text <Configuration and Microsoft.Common.targets line 132 has this entry:

    <Configuration Condition=" '$(Configuration)'=='' ">Debug</Configuration>
    

    As you can see - there is a condition which is saying - set configuration to Debug if it's not yet defined. Because you specified this property's value as a command line parameter - your property will have higher priority and will cause this condition to be false, thus your value will be the final value of this particular property. Same for PublishDir - Microsoft.Common.targets line 425:

      <!-- Output location for publish target. -->
      <PropertyGroup>
        <PublishDir Condition="'$(PublishDir)' != '' and !HasTrailingSlash('$(PublishDir)')">$(PublishDir)\</PublishDir>
        <PublishDir Condition="'$(PublishDir)'==''">$(OutputPath)app.publish\</PublishDir>
      </PropertyGroup>
    

    and so on.

    Some properties (especially for custom project types ) can be defined in it's own SDK .targets files, but if you'll open that custom .zzProj file and may find project properties there OR you can manually follow all <import directives - and eventually will find where every specific property is defined. And usually along with definition - you can trace how this property is being used by targets (search for $(MyPropertyName) ) and tasks, thus - alter it for your own needs or spot bugs or weird usages.

    Hope this helps you.