Visual Studio 2017 MSBuild 任务开发 [英] Visual Studio 2017 MSBuild Task Development

查看:27
本文介绍了Visual Studio 2017 MSBuild 任务开发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With developing an custom MSBuild Task with Visual Studio 2017 RC, I have the following problem: As soon as I add other dependencies than just Microsoft.Build.Utilities.Core (using v15.1.0-preview-000458-02 for .NET Core Support), I cannot load the task into another .csproj MSBuild project as the dependencies are not found.

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

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?

更新 1:
发布的问题是我的环境的局部问题,已修复.

Update1:
The problem with publish was something local to my environment and has been fixed.

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

Update2:
It seems that as soon as I change the TargetFramework from netstandard1.4 to netstandard1.6 it isn't even able to load the task at all. As soon as I use netstandard 1.6 it throws a an exception:

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.

推荐答案

有没有办法自动将所有依赖项复制到 Debug 文件夹?或者做每次想测试都得发布?

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 缓存中解析出来的.

By default and for good reasons, .NET Core and .NET Standard projects do not copy referenced assemblies into the build folder. Instead, they are resolved them from the NuGet cache.

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

But if you really need it, this behavior can be changed by overriding the default with the CopyLocalLockFileAssemblies setting.

<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

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

第二个问题

似乎只要我将 TargetFramework 从 netstandard1.4 更改为 netstandard1.6

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)不兼容.

To build a task assembly that works on both "MSBuild.exe" and "dotnet.exe msbuild", you should target netstandard1.4 or lower. netstandard1.6 is not compatible with .NET Framework 4.6.1 (which MSBuild.exe runs on.)

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

If you need API not available in netstandard1.4, you will need to cross-compile your task for .NET Framework and .NET Standard, which is considerably more complex but can be done.

这篇关于Visual Studio 2017 MSBuild 任务开发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆