2

I am using Unity 2018.2.6f1 (just updated a few days ago) and prior to that, I was using Unity 2018.2.5. I am trying to import a .Net Standard 2.0 class library, and I get the error

Project ... targets 'netstandard2.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v3.5'.

I can't figure out how to change my Unity project to target .Net Standard 2.0.

This question seems to ask the same thing, but I can't follow the accepted answer because the newer options don't show up in Player Settings for Scripting Runtime Version or Api Compatibility Level. In my version of Unity, my only options for Scripting Runtime Version are .NET 3.5 Equivalent or .NET 4.x Equivalent, and my only options for Api Compatibility Level are .NET 2.0 and .NET 2.0 Subset.

The Unity documentation also references options that I don't see - if I can set the project to .Net Standard 2.0, it says I should be able to reference the class library with no additional steps, but again, I'm stuck on how to change my project to that. I should see the new .NET4.6 option as well as .Net Standard 2.0 according to the links I posted, but I must be missing something in my installation. Any help on changing the target is appreciated!

Dave Smash
  • 2,941
  • 1
  • 18
  • 38

3 Answers3

5

I finally figured it out. With the Scripting Runtime Version set to .NET 3.5 Equivalent, the options for Api Compatibility Level are .NET 2.0 Subset and .NET 2.0. After changing the Scripting Runtime Version to .NET 4.x Equivalent and restarting the editor, you can see new Api Compatibility Level options of .Net 4.x and .Net Standard 2.0 and the other options disappear.

Dave Smash
  • 2,941
  • 1
  • 18
  • 38
1

From the blog, Updated script runtime:

You can choose the .NET profile for your player build via the “Api Compatibility Level” option in the Player Settings. The two .NET profiles Unity supports are

  • .NET Standard 2.0
  • .NET 4.x.

In the editor, you need to open the Player Settings (File -> Build Settings -> Player Settings). Then under Other Settings you can find the runtime and API level.

Player Settings Other Settings

  • That's where I am looking. The two options that I see in the editor are .NET 2.0 Subset and .NET 2.0. Based on the documentation you are posting, I am expecting to see .NET Standard 2.0, but it is not an option. – Dave Smash Sep 04 '18 at 21:32
  • I haven't downloaded 2018.2.6 yet, nor do I frequently try to use external dlls I didn't get from the asset store. – Draco18s no longer trusts SE Sep 05 '18 at 01:35
0

Under Other Settings -> Configuration change Scripting Backend to IL2CPP. This scripting backend offers a bigger .NET surface.

slaphshot33324
  • 618
  • 1
  • 8
  • 23
  • Thanks for your help! I'll keep this in mind, and it set me on the right track. Changing the scripting runtime version is actually what solved the problem - the options in the Api level dropdown change depending on which runtime version is in use. The IL2CPP didn't seem to make a difference, but might open up some other possibilities. – Dave Smash Sep 04 '18 at 21:45