Visual Studio 在构建、重建和清理解决方案时使用什么 dotnet core cli 命令(或 msbuild 命令)?

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

我想知道 Visual Studio 在我的 dotnet 核心应用程序中 Build/Rebuild 和 Clean 解决方案时使用的确切 dotnet cli 命令?

我知道 dotnet 核心 cli 是在 msbuild 之上构建的,所以当您 运行 Build/Rebuild 或 Clean Solution Visual Studio 使用 msbuild 直接命令而不是来自 dotnet core cli 的命令?

对吗?

如果这是正确的,我想知道它在三个操作中使用了哪个或哪些 msbuild 命令:

  1. 构建解决方案
  2. 重建解决方案
  3. 清洁解决方案

哪些 dotnet core cli 命令等同于此?

我从这个知道post() 以下命令在 dotnet 和 msbuild 中执行构建、重建和清理。

Dotnet 客户端:

Msbuild:

我想这还不是全部?这很好,但我想看看 Visual Studio 为操作产生了什么?

而且我想知道是否可以更改 Visual Studio 行为以便 运行s dotnet cli 命令而不是 msbuid?

研究:

我在 Visual Studio(Visual Studio 2017 企业版 15.9.11)

中构建了一个 asp.net 核心网络 api 项目

当我 Build/Rebuild 和清理解决方案时,我正在查看 Visual Studio 输出,但我找不到任何与 dotnet 核心 cli 或 msbuild。然后我去了 VisualStudio Tools/Option/"Project and Solution"/"Build and Run" 并更改了选项:

结果是 Visual Studio 的 Output window 中产生的日志很大,很难找到 将用于操作的确切命令。我可以看到输出中的许多地方都使用了 msbuild,但有点令人困惑 找到确切的命令。

我也看到了这个问题(Does Visual Studio use MSBuild internally, and what is the exact command?)

这个答案是这样说的:

引用:

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

dotnet core cli msbuild 也是这样吗?

如有任何帮助或澄清,我们将不胜感激。

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?

对于VS2017,我认为VS IDE在Clean, Build and Rebuild时直接调用msbuild.exe。您可以通过任务管理器或Process Monitor轻松查看这一点。

至于你上面提到的:It appears that the MSBuild command line options are not specified, but rather the MSBuild APIs are called within Visual Studio.

我认为这是正确的,但仅适用于早期版本(2010、2013)。我已经用 VS2010 测试过,在 VS 中执行 building-related 操作时,它不会调用 MSBuild.exe。所以 VS2010 中的 msbuild 不会作为 separate process.

执行

但是对于 VS2017,当我创建以 .net 核心为目标的项目时,在执行 building-related 操作(单击构建、清理、重建按钮)时,它显然会调用 msbuild.exe,如下所示:

About what msbuild commands VS actually executes:

从现在开始,VS2017 调用 msbuild.exe 来构建 .net core 或 .net fx 项目。

我认为:

对于只包含一个项目的解决方案:

构建解决方案=> msbuild xxx.sln /t:build /p:Configuration=xxx;Platform=xxx

重建解决方案=>msbuild xxx.sln /t:rebuild /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean;build /p:Configuration=xxx;Platform=xxx

清洁解决方案=>msbuild xxx.sln /t:clean /p:Configuration=xxx;Platform=xxx=>msbuild xxx.sln /t:clean

我想每次我们点击VS中的Build按钮时,它都会从这个框中选择Configuration和Platform的值,因为这两个参数肯定会传递给MSBuild.exe。

此外,我们还可以发现,IDE在开始构建之前有一个检查过程:它会检查文件是否为out-of-date,然后确定是否需要构建。但这不是你在问题中要求的,它不会影响你想要的命令,所以我跳过它。

此外,查看此页面我们可以发现这里有一些 msbuild-related 设置:

所以实际上我认为上面的命令应该添加一些参数,例如:msbuild ... -m:8 -v:M.

此外:虽然我发现VS中的building-related动作会直接调用msbuild.exe。我不确定我上面的命令是否 100% 正确。恐怕没有人能保证除了用VS开发菜单命令的人IDE。因此,如果我有任何误解,请随时纠正我:)

如果你只是想获得与 VS 中完全相同的东西,你也可以在官方文档中尝试 devenv.exe. This is the only place 确认构建开关执行与 [=19= 相同的功能] 在集成开发环境中(IDE).