简体   繁体   中英

How do net451 assemblies work in a project.JSON on DNX?

I've been tinkering with learning DNX and .Net Core 5 lately. However I an confused as to why net451 is available in the project.Json.

The way I understand it is DNX compatible projects compile to be cross platform against .Net Core 5.

What happens if I add a reference to say "System.Configuration" in my DNX project causing it to show up in the net451 section in the Json.

Will it just fail to build cross platform? Or can I only use certain pieces of .Net 4.5.1 that are portable to Core 5?

Looking into it more, it looks like those are target frameworks, so while I could target 4.5.1 and use 4.5.1 dependencies, Am I correct in thinking it won't be compatible with DNX on say Linux?

Just trying to clear up how I would go about building something now that will be compatible with Core 5 later.

Should I just avoid using anything on the Full CLR's?

To answer the question, which while DNX is on it's way out, the new dotnet cli still behaves very similarly with project.json . The only thing that is changing drastically is how everything is built up around you (dnx compiled on the fly, dotnet cli is very similar to MSBuild).

What happens if I add a reference to say "System.Configuration" in my DNX project causing it to show up in the net451 section in the Json.

Will it just fail to build cross platform? Or can I only use certain pieces of .Net 4.5.1 that are portable to Core 5?

As with most things in programming... it depends.

If you add it specifically to the frameworkAssemblies under net451 .

Then if you make use a class in there, you will get a compiler error for dnxcore50 (soon to be netstandard1.5 ).

Now by default the compiler gives you some built in compilation symbols. So the way you handle that is to do something like...

#if NET451
using System.Configuration;
// your codehere
#else
// do something that supports `dnxcore50` or throw a not supported exception, etc.
#endif

Basically if you are looking to build something that is entirely cross platform, then something like System.Configuration is not something you'll be able to use.

If you're looking to build something that works for many platforms then, but you want higher fidelity when it's running inside net451 then you can use conditional compilation to get you there.

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