0

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:

  • Build: dotnet build
  • Rebuild: dotnet build --no-incremental
  • Clean: dotnet clean

Msbuild:

  • Build: msbuild /t:build
  • Rebuild: msbuild /t:rebuild
  • Clean: msbuild /t:clean

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:

  • MSBuild project build output verbosity: tried both "Detailed" and "Diagnostics" options
  • MSBuild project build log file verbosity: tried both "Detailed" and "Diagnostics" 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.

xargs
  • 1,720
  • 2
  • 15
  • 22
  • Hi friend, any update for this issue? If you've found any discovery feel free to share here:) I will delete this comment later since it's just a reminder. – LoLance Jul 02 '19 at 06:35
  • Unfortunately no, but it seems that the exact commands that VS uses can not be found as you already mentioned in the answer. – xargs Jul 09 '19 at 19:31

1 Answers1

1

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).

LoLance
  • 18,434
  • 1
  • 12
  • 39
  • Thank you for your Answer. It answered some parts of my question but not all of them. Based on my research I also came to the conclusion that there is no way to find the exact command that Visual Studio produces. I up-voted your Answer as it provided Answers and clarification to some of the questions. :) Still lets wait and see maybe someone knows or has some other Idea or point of view on it. – xargs Jun 24 '19 at 20:09
  • 1
    @xargs-mkdir Glad to know it helps in some aspects. And maybe the answer is negative that there is no way supported by VS now to show the exact build command that VS produces. Check [this document](https://docs.microsoft.com/en-us/visualstudio/extensibility/creating-an-extension-with-a-menu-command?view=vs-2019) and you can find, the Build, Rebuild, Clean button is a menu command embedded in IDE, every time you click the button=> core code in the button-click event will do the build action for us. But how the code works to call the msbuild.exe and pass the parameter is unknown and invisible. – LoLance Jun 25 '19 at 02:56
  • Seems like it is not possible to find the exact msbuild commands from VS. If someone finds a way I would be happy to see it :). Your answer helped me understand some other points so thank you, I accepted it. – xargs Jul 09 '19 at 19:34