visual-studiomsbuilddotnet-tool

dotnet build -h and --help show different options, how is the difference in behavior and toolset?


I know in MS developer world is still MSBuild behind everything. But how can it be, that in a Windows Terminal the commands dotnet build -h and dotnet build -help gives different results? The first version with -h has the alternatives -? and --help, while writing -help shows totally different help and options:

PS C:\> dotnet build -h
Description:
  .NET-Generator

Nutzung:
  dotnet build [<PROJECT | SOLUTION>...] [options]

Argumente:
  <PROJECT | SOLUTION>  Das Projekt oder die Projektmappendatei, die verwendet werden soll. Wenn keine Datei angegeben ist, durchsucht der Befehl das aktuelle Verzeichnis nach einer Datei.

Optionen:
  --ucr, --use-current-runtime         Verwenden Sie die aktuelle Runtime als Zielruntime.
  ...

versus:

PS C:\> dotnet build -help
Syntax:              MSBuild.exe [Optionen] [Projektdatei | Verzeichnis]

Beschreibung:         ....

Optionen:            Beachten Sie, dass Sie Optionen über
                     "-option", "/option" und "--option" angeben können.
...

How can I know what toolset and version the command dotnet build uses, when I write dotnet build mysolution.sln, which seems OK for both variants? Where are the differences and which build system does Visual Studio 2022 uses (or how can I find out)? And next, how can I be sure on the build server is used the same tooling?


Solution

  • The dotnet utility is cross platform and contains an array of tools for .NET development that are used via sub commands.

    Relevant to the question, dotnet contains its own embedded copy of msbuild. There is a dotnet msbuild sub command and the dotnet build and dotnet clean sub commands are also MSBuild. The sub commands that use MSBuild, accept MSBuild command line options.

    -?, -h, and --help are options recognized by the dotnet utility.

    -help is not an option recognized by dotnet and it is passed to the internal MSBuild. -help is a recognized msbuild option. You can see this in the command output reported in the question.

    dotnet build -h reports

    ...
      dotnet build [<PROJECT | SOLUTION>...] [options]
    ...
    
    

    and dotnet build -help reports

    Syntax:              MSBuild.exe [Optionen] [Projektdatei | Verzeichnis]
    
    ...
    

    Note that although you ran the dotnet command, the -help syntax says MSBuild.exe.

    Use dotnet --version to get the SDK version of .NET.

    Use dotnet msbuild --version to get the version of the embedded MSBuild.

    To get the host version of dotnet and the available SDKs and runtimes, use dotnet --info.

    If an edition of Visual Studio is installed, there will be a stand alone copy of MSBuild available. You would be correct if you guessed that msbuild --version will provide the version.