Visual Studio 2017 MSBuild 任务开发

Visual Studio 2017 MSBuild Task Development

使用 Visual Studio 2017 RC 开发自定义 MSBuild 任务时,我遇到了以下问题:一旦我添加了 Microsoft.Build.Utilities.Core 之外的其他依赖项(使用 v15.1.0-preview-000458- 02 for .NET Core Support),我无法将任务加载到另一个 .csproj MSBuild 项目中,因为找不到依赖项。

有没有办法自动将所有依赖复制到Debug文件夹中? 还是每次要测试都要发布?

更新1:
发布问题是我环境的本地问题,已修复。

更新2:
似乎一旦我将 TargetFramework 从 netstandard1.4 更改为 netstandard1.6,它甚至根本无法加载任务。一旦我使用 netstandard 1.6,它就会抛出一个异常:

The task could not be loaded from the assembly.
Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its
dependencies.

Is there a way to automatically copy all dependencies to the Debug folder? Or do I have to publish it every time I want to test it?

默认情况下,出于充分的理由,.NET Core 和 .NET Standard 项目不会将引用的程序集复制到构建文件夹中。相反,它们是从 NuGet 缓存中解析的。

但如果您确实需要它,可以通过使用 CopyLocalLockFileAssemblies 设置覆盖默认值来更改此行为。

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

Cref: https://github.com/dotnet/sdk/blob/d20405f91a2959fa91fea6285d9a896286727f2a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Sdk.BeforeCommon.targets#L55-L56

第二题

It seems that as soon as I change the TargetFramework from netstandard1.4 to netstandard1.6

要构建适用于 "MSBuild.exe" 和 "dotnet.exe msbuild" 的任务程序集,您应该以 netstandard1.4 或更低版本为目标。 netstandard1.6 与 .NET Framework 4.6.1 不兼容(MSBuild.exe 在其上运行。)

如果您需要 API 在 netstandard1.4 中不可用,您将需要 cross-compile .NET Framework 和 .NET Standard 的任务,这要复杂得多,但可以完成。