2

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?

Community
  • 1
  • 1
smwikipedia
  • 61,609
  • 92
  • 309
  • 482
  • If you pass the `/v:diag` switch to MsBuild it will give you extremely verbose output, including properties for targets – stijn Aug 19 '14 at 16:34
  • Thanks. But that's too verbose information. I didn't see the definition for the `PacakgeLocation` property. – smwikipedia Aug 20 '14 at 01:35
  • Did you grep the complete output? Anyway: the output does contain something like 'using target `Package` from `. Open in text editor, look for the target and see what properties it uses. Thing is MsBuild itself just cannot know all possible properties, that's not how it works. Suppose a task uses a property $(Prop), Prop doesn't have to exist. So MsBuild cannot list it. The only reference is the fact it appears in the text. Hence you have to turn to simple text search. – stijn Aug 20 '14 at 07:45
  • btw for Targets this is different, MsBuild knows those: http://stackoverflow.com/questions/2618201/msbuild-is-there-a-way-to-list-all-the-build-targets-available-in-a-build-file You can also adapt that answer to list the avaiable PropertyGroups for instance, but again, it's not said that the properties used by the Package task would turn up. – stijn Aug 20 '14 at 07:46

2 Answers2

3

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.

Alexey Shcherbak
  • 3,394
  • 2
  • 27
  • 44
1

First pre-process the MsBuild script to flatten and consolidate all imported scripts into a single MsBuild file.

MsBuild.exe MyProject.proj /pp >Output.xml

Now, open Output.xml in Notepad and search for instances of $(Configuration) and $(PackageLocation).

$(Configuration) is one of the base default properties you'd find in most MsBuild projects and you'd see it used in Microsoft.Common.CurrentVersion.Targets in targets that are designed to fail the build if an invalid or unexpected Platform or Configuration property is used.

PackageLocation is specific-to ASP.NET projects and the import taxonomy would include Microsoft.Web.Publishing.targets which contains several targets dedicated to parsing and validating that property as part of the web publication workflow.

Nicodemeus
  • 4,005
  • 20
  • 23
  • 1
    Thanks. The `/pp` preprocessing is helpful. But I have something like this in the *.proj file. (See my Add 2). The properties, such as the `PackageLocation`, are included as attribute values of the MSBuild task. How to find their definitions? – smwikipedia Sep 09 '14 at 09:04