Pregunta

.Net Standard is specification.

  1. There are two popular implementation of the .net standard specification. ie .Net Core & .Net Framework
  2. When I create .Net Standard library, I am allowed to refer this in .Net core project as well as .Net Framework project. This makes absolute sense to me.
  3. I am allowed to reference a .Net Framework library in a .Net Standard library. When I do this I am no more able to refer the .Net Standard library in any .Net Core applications. Why are we permitted to reference a .Net framework library in .Net standard?

This is defeating the purpose on .Net standard in my understanding. Or am I getting it wrong?

¿Fue útil?

Solución

I read your question as "what is a real-world use case for referencing a .Net framework library from a .Net standard library", since it defeats the purpose of .Net standard to be compatible with .Net Core.

The main use case I can think of where this szenario makes sense is "easier porting" / "porting in parallel". Let us say one wants to develop a .Net standard library S which needs another library F which is currently only available as a .Net framework implementation. F is planned be ported to .Net standard within the next 3 months. So S can be developed and tested now, using the current version of F, whilst F is ported to .Net standard in parallel. When F will be available then as a .Net standard version, the only thing which ideally remains is to change the reference from S to the new version of F, which makes S compatible with .Net core.

Otros consejos

The other way to look at it is that .NET standard, being a specification, is like an interface. Whenever you add a reference to a .NET standard library, as long as the reference meets the specification definition, then the library doesn't care what type it is. Implementation is separate from specification.

As you said, if you add a .NET framework library to a .NET standard library, then you can no longer run it on .NET Core, but this is a runtime issue rather than an edit time or compile time issue.

Licenciado bajo: CC-BY-SA con atribución
scroll top