项目成功构建 "Visual Studio 2019 -> Build" 但失败 "MSBuild"

Project successfully built with "Visual Studio 2019 -> Build" but failed with "MSBuild"

我有一个项目文件 (*.fsproj)。它可以通过“构建”菜单使用 Visual Studio 2019 成功构建。

但是在使用以下命令调用“Visual Studio 2019 构建工具”(link) 时:

"C:\Program Files (x86)\Microsoft Visual Studio19\BuildTools\MSBuild\Current\Bin\MSBuild.exe" ".\src\[ProjectFolder]\[ProjectName].fsproj" /t:Build /p:Configuration=Release /p:Platform="Any CPU"

它引发了一个错误 error MSB4057: The target "Build" does not exist in the project.

项目文件:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <Version>2.0.0.0</Version>
    <FileVersion>2.0.0.0</FileVersion>
    <Configurations>Debug;Release;[...]</Configurations>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="[File1].fs" />
    <Compile Include="[File2].fs" />
    <Compile Include="[File3].fs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="paket.references" />
  </ItemGroup>
  <Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>

注意:为了保密,我将它们替换为 []。

问题:有没有办法让 MSBuild 的行为与 Visual Studio 中的行为完全一样?我正在尝试构建 *.SLN(由许多 *.fsproj 和 *.csproj 组成),没有 Visual Studio IDE.

我可以强制 Visual Studio 在构建时吐出更多日志信息(如下所示),但是日志信息太多了,我不知道要查找什么。

我的解决方案文件 (*.SLN) 包含许多 sub-project 文件(*.fsproj、*.csproj)。有些项目是用.NET Standard 2.0编写的;其他的在 .NET Core 3.1 中。 (又名。目标框架)

感谢 and 的回答,不应使用 MSBuild,因为我的一些项目是针对 .NET Core 的。正确的编译工具是dotnet SDK,命令如下:

dotnet build --configuration Release "[MySolution].sln"

dotnet 建立在 MSBuild 之上。它添加了一些 MSBuild 中不可用的功能,例如 dotnet new。另外,要dotnet编译,必须安装.NET Core SDK(例如v3.1:link);无需单独安装 MSBuild。