.net-coremsbuildvisual-studio-2017asp.net-core-cli

What dotnet core cli command(or msbuild commands) does Visual Studio use when Building, Rebuilding and Cleaning the Solution?


I want to know the exact dotnet cli commands that Visual Studio uses when I Build/Rebuild and Clean solution in my dotnet core application?

I know that the dotnet core cli was build on top of msbuild so when you run Build/Rebuild or Clean Solution Visual Studio uses msbuild commands directly and not the ones from dotnet core cli?

Is that correct?

If this is correct I would like to know which msbuild command or commands it uses with the three actions:

  1. Build Solution
  2. Rebuild Solution
  3. Clean Solution

And which dotnet core cli commands would be equivalent to that?

I know from this post(Relationship between the dotnet cli and the new vs2017 msbuild) that the following commands do the build, rebuild and clean in dotnet and msbuild.

Dotnet cli:

Msbuild:

I guess this is not all? This is fine but I would like to see what Visual Studio produces for the actions?

And I am wondering if Visual Studio behavior can be changed so it runs dotnet cli commands instead of msbuid?

Research:

I was building a asp.net core web api project in Visual Studio(Visual Studio 2017 Enterprise Version 15.9.11)

I was looking in Visual Studio Output when I Build/Rebuild and Clean the solution but I could not find anything related to dotnet core cli or msbuild. Then I went to VisualStudio Tools/Option/"Project and Solution"/"Build and Run" and changed the options:

The outcome was that the log that was produced in the Output window of Visual Studio was huge and it was difficult to find the exact command which would be used for the actions. I can see msbuild used in many places in the output but it is a little confusing to find the exact command.

I also saw this question (Does Visual Studio use MSBuild internally, and what is the exact command?)

This answer says that:

Quote:

"It appears that the MSBuild command line options are not specified, but rather the MSBuild APIs are called within Visual Studio. Unless you have the Visual Studio source code to reverse engineer, you cannot get an equivalent command line."

Is that the same case for dotnet core cli msbuild as well?

Any help or clarification on this is appreciated.


Solution

  • I know that the dotnet core cli was build on top of msbuild so when you run Build/Rebuild or Clean Solution Visual Studio uses msbuild commands directly and not the ones from dotnet core cli?

    For VS2017, I would think the VS IDE calls msbuild.exe directly when Clean, Build and Rebuild.You can easily check this point by Task Manager or Process Monitor.

    As for what you mentioned above:It appears that the MSBuild command line options are not specified, but rather the MSBuild APIs are called within Visual Studio.

    I think it's right but only for the eariler vs versions(2010,2013). I've tested with VS2010, when doing building-related actions in VS, it doesn't call MSBuild.exe. So the msbuild in VS2010 is not executed as a separate process.

    But for VS2017, when I create projects which target .net core, when doing building-related actions(click the build, clean, rebuild button), it obviously calls the msbuild.exe like below: enter image description here

    About what msbuild commands VS actually executes:

    Since now the VS2017 calls msbuild.exe to build .net core or .net fx projects.

    In my opinion:

    For the solution which only contains a project:

    Build the Solution=> msbuild xxx.sln /t:build /p:Configuration=xxx;Platform=xxx

    Rebuild the Solution=>msbuild xxx.sln /t:rebuild /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean;build /p:Configuration=xxx;Platform=xxx

    Clean the Solution=>msbuild xxx.sln /t:clean /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean

    I think every time when we click Build button in VS, it will pick the value of Configuration and Platform from this box, because these two parameters are sure to be passed to MSBuild.exe.

    enter image description here

    Also, one thing we can discover is that IDE has a check process before start build: It will check if the file is out-of-date and then determine if it need to build or not. But this is not what you ask in your issue and it not affects the command you want, so I skip it.

    Also, see this page we can find there are some msbuild-related settings here: enter image description here

    So actually I think the command above should add some parameters like:msbuild ... -m:8 -v:M.

    In addition: Though I find building-related action in VS will call msbuild.exe directly. I'm not certainly sure that my command above is 100% correct. I'm afraid no one can ensure that except the guys who develop the menu command in VS IDE. So if i misunderstand anything please feel free to correct me:)

    And if you just want to get the exactly same thing like what in VS, you can also have a try devenv.exe. This is the only place in official document which confirms the build switch performs the same function as the Build Solution menu command within the integrated development environment (IDE).