With the move from project.json
to the new csproj
format introduced with VS2017, I'm struggling to understand the difference between the dotnet
cli and the new msbuild
and when to use one over the other.
1) To build a new csproj
netstandard library from the command line, should I be calling the dotnet
cli (for example dotnet restore
dotnet build
) or use msbuild
(for example msbuild ExampleNetstandard.sln
).
2) Also, my understanding is that there are two versions of msbuild
, one built on the full framework and another targeting dotnet core
. Is this correct? Should I always use the dotnet version
3) Is dotnet cli
standalone or does it require msbuild
to be installed?. For instance when you install the dotnet SDK does this install msbuild as well? If so is this different to the version that is installed with vs2017?
Questions
Both do fine as currently
dotnet
is built on top ofmsbuild
. So it's a matter of taste. You could also call msbuild tasks by using the dotnet CLI. (dotnet msbuild <msbuild_arguments>
)In the beginning, all the .NET core stuff was only in
dotnet
and not inmsbuild
. This was cumbersome as a lot of stuff that was already built onmsbuild
wasn't working well withdotnet
out of the box (e.g. Xamarin). So they moved the stuff tomsbuild
and builddotnet
on top ofmsbuild
.dotnet
has some features that aren't inmsbuild
, likedotnet new
. In my opinion,dotnet
is easier to use thanmsbuild
, so I preferdotnet
.To make it more clear, I have added a comparison between
msbuild
anddotnet
at the end of my post.There is only one msbuild. dotnet CLI is using msbuild:
https://docs.microsoft.com/en-us/dotnet/articles/core/tools/extensibility
The older version of
msbuild
was lacking the .NET Core support. Maybe that's the other version ;)I agree it's confusing, as it was very different a few months ago.
I wasn't sure about this, but it was easy to test. I have removed all msbuild.exe and it still worked. Found out it's using the msbuild.dll in the SDK folder. e.g. "C:\Program Files\dotnet\sdk\1.0.3\MSBuild.dll"
If you remove that one, there is a proof:
msbuild.dll is actually msbuild.exe, as you can see in the properties:
Some code
If you look into the code of the dotnet CLI, you can see it's generating
msbuild
`commands.For example
dotnet restore
, is created by theRestoreCommand
class inside dotnet CLI.A stripped version:
You can see
dotnet restore
is just callingmsbuild /NoLogo /t:Restore /ConsoleLoggerParameters:Verbosity=Minimal
If you check
RestoreCommand
in the time ofdotnet v1.0.0 RC2
, it wasn't usingmsbuild
but was callingnuget
directly.Mapping between
dotnet
andmsbuild
I made a mapping between
dotnet
andmsbuild
. It's not complete, but the important commands are there.*
dotnet nuget: Adding/removing packages to csproj, also limited set of nuget.exe, see comparisonPS no markdown tables in SO :(