简体   繁体   中英

.NET 4.6.1 project referencing a .NET Standard 2.0 library - VSTS wont build

I am referencing a .NET Standard 2.0.0 project in a .NET 4.6.1 project.

Building the project locally works fine. Building it with a hosted agent on VSTS gives the following error:

The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

Adding the netstandard assembly in Web.config as described here , didnt work, same error:

<system.web> <compilation debug="true" targetFramework="4.6.1" > <assemblies> <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"/> </assemblies> </compilation> <httpRuntime targetFramework="4.6.1" />

Also tried adding the NETStandard.Library.NETFramework Nuget package. Got alot of errors like this:

CSC : error CS1703: Multiple assemblies with equivalent identity have been imported: 'D:\\a\\1\\s\\packages\\NETStandard.Library.NETFramework.2.0.0-preview2-25405-01\\build\\net461\\ref\\System.Xml.XmlSerializer.dll' and 'C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v4.6.1\\Facades\\System.Xml.XmlSerializer.dll'. Remove one of the duplicate references.

Used the latest NETStandard.Library.NETFramework package on Nuget.org - 2.0.0-preview2-25405-01. The description of the package says:

This package is deprecated. To consume .NET Standard libraries from .NET Framework in VS2017 15.3, you only need the .NET Core 2.0 SDK installed. For VS 2015, you'll need NuGet client 3.6 or higher.

Also tried adding the ".NET Core Tool Installer" for v. 2.0.0 as the first build step. No luck.

Here is my current build configuration. How do I make it work for a .NET 4.6.1 project referencing a .NET Standard 2.0 library?

在此处输入图片说明

I found lots of information online about installing NuGet packages, adding .NET Core tooling, restore, and build steps - but actually in the end I solved the issue by changing one item in a few places.

You need to ensure your build consistently asks for the right Visual Studio / VSTest version .

I had a build with one phase that contained a build and a test step (as well as things like NuGet restore, publishing etc - but they don't rely on any version of Visual Studio).

At the phase level, you need to select the "Hosted VS2017" agent queue.

For the build step, you need to set the Visual Studio Version to "Visual Studio 2017".

For the test step, you need to open Advanced Execution Options and set the VSTest version to "Latest".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM