0
votes

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?

enter image description here

1
Your error message says "preview2". Are you sure you are referencing the correct (release) .NET Standard?nvoigt
@nvoigt see updated answerKenci
What does your solution look like? Are both projects yours? Or is one an external dll?nvoigt
Both projects are mine but the standard2.0 project is an external dll from a private nuget repositoryKenci
Have you tried installing the .NET Core 2.0 SDK on the build server as the message on that deprecated NuGet package says?NightOwl888

1 Answers

2
votes

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