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

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

问题描述

在使用Visual Studio 2017 RC开发自定义MSBuild任务时,出现以下问题:一旦添加了除Microsoft.Build.Utilities.Core以外的其他依赖项(使用v15.1.0-preview-000458-02获得.NET Core支持) ,因为找不到依赖项,所以无法将任务加载到另一个.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.

Update2 :
看来,只要将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项目不会将引用的程序集复制到build文件夹中.而是从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>

参考: 第二个问题

似乎我将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与运行MSBuild.exe的.NET Framework 4.6.1不兼容.

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.)

如果需要netstandard1.4中不可用的API,则需要交叉编译.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天全站免登陆