无法通过 cmd 发布 Dotnet

Dotnet publishing via cmd not possible

我通过 Visual Studio 成功发布了 .NET Core 应用程序,但无法通过命令行(或使用 VS 2019 的开发人员命令提示符)执行相同操作。

我正在使用 VS2019 生成的发布配置文件并执行:

dotnet publish -p:PublishProfile=Properties\PublishProfiles\MyProfile.pubxml

其中 MyProfile 是:

<?xml version="1.0" encoding="utf-8"?>

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
   <PublishProtocol>FileSystem</PublishProtocol>
   <Configuration>Release</Configuration>
   <Platform>Any CPU</Platform>
   <TargetFramework>netcoreapp3.1</TargetFramework>
   <PublishDir>..\Build\Release\publish\</PublishDir>
   <RuntimeIdentifier>win-x64</RuntimeIdentifier>
   <SelfContained>true</SelfContained>
   <PublishSingleFile>False</PublishSingleFile>
   <PublishReadyToRun>False</PublishReadyToRun>
   <PublishTrimmed>False</PublishTrimmed>
 </PropertyGroup>
</Project>

我总是得到的错误是:

MyCustom.dll. Could not load type 'Microsoft.Build.Utilities.AppDomainIsolatedTask' from assembly 'Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

我错过了什么?

我找到了解决方法,而不是修复方法。

如果我们使用 msbuild 发布,我可以得到与 dotnet publish 相同的结果,并且它在命令行中成功运行:

msbuild /restore /t:Publish /p:RuntimeIdentifier=win-x64 /p:configuration=Release