Visual Studio 2017 MSBuild任务开发

通过使用Visual Studio 2017 RC开发自定义MSBuild任务,我遇到以下问题:只要添加其他依赖项而不仅仅是Microsoft.Build.Utilities.Core(使用v15.1.0-preview-000458-02进行.NET核心支持) ),我无法将任务加载到另一个.csproj MSBuild项目中,因为找不到依赖项.

有没有办法自动将所有依赖项复制到Debug文件夹?
或者每次我想测试它时是否必须发布它?

UPDATE1:
发布的问题是我的环境本地的问题,并已得到修复.

UPDATE2:
看来,只要我将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)不兼容.

如果您需要netstandard1.4中不具备的API,则需要交叉编译.NET Framework和.NET Standard的任务,这要复杂得多,但可以完成.

点赞