2

Whenever I'm creating a new solution with VS2017 I'm usually choosing one of the newer Frameworks as a target (most often currently 4.6.1).

Now though when I create a .dll Subproject within the solution it sets the target Framework for that subproject to .NET Standard 2.0. With that being the most "modern" target Framework that can be set.

This though has the Problem that I can't use some things I'm used to like "Resources.MyResource" (which works fine with Framework 4.6.1).

Now I'm wondering is there any way to rectify this Problem? Either by increasing the .NET Standard, or by enabling one to choose the .NET Framework also for These .dll Projects (aside from creating the .DLL Project outside the solution and then importing it into the solution)?

Thomas
  • 2,886
  • 3
  • 34
  • 78
  • 2
    .NET Standard is meant to create class libraries that will run on multiple operating systems. It's *not* a newer version of 4.6.1. The newest version of the full framework is 4.7.1 – Panagiotis Kanavos Mar 08 '18 at 14:52
  • @PanagiotisKanavos tnx that cleared a few things up. – Thomas Mar 08 '18 at 15:03

2 Answers2

2

.Net Standard is a specification of the .NET API's that are available on all implementations of .NET.

What does this mean? - Calling an API in .Net Standard will run on all .Net versions that have implemented that version of the Standard.

SO what does that mean? - .Net Core introduces cross platform development. The need to now possibly share code between a Windows machine and a Linux box require a "standard" that can be implemented across all equally.

Think of it as a contract. If a version of .Net implements .Net Standard 2.0, it is saying that it will have a version of the API's in that standard available for use on all platforms.

So, back to your original question. .Net Standard 2.0 is not a "new" version of the framework. It is the contract that your subproject, assuming it's a class library is going to abide by. If an API appears to be missing it is because it doesn't have it as part of it's contract (maybe). I say maybe because it's not the easiest to find.

**** Start Revised ****

Here is a table of the versions of .Net that support the versions of .Net Standard.

In your case 4.6.1 doesn't even support 2.0. The last version of the Standard that 4.6.1 supported is 1.4.

I thought 4.6.1 supported .Net standard 2.0 after I wrote the above and upon further reading found a more up to date chart along with this post stating it is supported in 4.6.1. sigh

**** End Revised ****

This SO answer seems to indicate that 1.4 does have Resources in it but it was preview versions and things change. I don't see it in the APIs supported list but I could have missed it. The SO answer seems to indicate it was a tooling issue and could be worked around. That could be fixed by now....

Here's where you can look to see what each Standard supports for APIs.

HOWEVER, I don't think this is actually what you want.

I think what you really want is to simply change your sub project's target to 4.6.1 as is your main app since I highly suspect you have no need/desire to run cross platform.

Additionally, prior to .Net Standard 2.0, thousands of API's were not in the Standard. IMO, prior to 2.0, the Standard is a hard sell especially for users on the .Net Full Framework.

Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
  • the Revision has an error in it I think (did you think it Supported or it did not Support 2.0?) – Thomas Mar 09 '18 at 06:27
  • The sentences struck out were my original. On the links it showed that 4.6.1 did not support 2.0. It felt "wrong" to me so I kept digging and found a revised chart & blog post (not struck out part) that indicated 4.6.1 does support 2.0. – Kevin LaBranche Mar 09 '18 at 14:45
0

From what I can tell the Project Template to use is under "Windows Classic Desktop > Class Library (.Net Framework)"

EDIT

That said, you can add a .resx file to a .Net Standard project and use it in exactly the same way.

kͩeͣmͮpͥ ͩ
  • 7,783
  • 26
  • 40
  • how can I tell it to be used that way? as for the .resx file I tried it. I can't use Resources.MyResource though. I Need to use a method where I put the MyResource as Name in and then let it return the value of it that way. – Thomas Mar 08 '18 at 15:06
  • @Thomas How can you tell what to be used that way? I just tried adding a ".resx" file (I had to cheat and add a text file and then manually change the extension to .resx) called `Resources.resx`. I added a string called "MyResource" (using the editor in VS). I could then use Resources.MyResource in the .Net Standard project. – kͩeͣmͮpͥ ͩ Mar 08 '18 at 15:10