Nuget : Additional computed target framework(s) - nuget

In nuget.org, when you check any package there are 2 types of framework.
What is the difference between Compatible target framework and additional computed target framework?

A compatible target framework is directly derived from the Target Framework Monikers (TFMs) of a NuGet package. In your screenshot, the NuGet package targets net45 and netstandard2.0 - you will find these entries in the corresponding .csproj/.nuspec file.
The additional computed target frameworks are all kind of frameworks which are implicitly supported due API compatibility. For example every project targeting netstandard2.0 is compatible to netstandard2.1, as the APIs of .NET Standard 2.1 completely contain all APIs of .NET Standard 2.0.
The same is true for net45: an application/assembly targeting .NET Framework 4.5 will automatically be supported on .NET Framework 4.6, 4.7, etc.
Microsoft announced this here.

Related

NuGet Framework Targeting in Squirrel

I'm trying to better understand the proper use of .NET Framework version targeting in the project's NuSpec file, as relates to Squirrel.
For example:
<file src="bin\Release\*.dll" target="lib\net472\"></file>
Does the version specified here affect Squirrel's operations at all? Or is it a NuGet-specific construct only?
What does it mean when we say .NET 4.8 is now supported?
The behavior by NuGet is driven by the compatibility map of the frameworks.
.NET Framework is mostly backwards compatible, so NuGet has built on top of that, when your package declares that it targets net472, net48 as the next evolution is acceptable.
NuGet will allow this package to be consumed in .NET Framework 4.8 projects.
See more for .NET Framework version compatibility.
See more on cross platform targeting libraries, which talks about the multi targeting concept.

NuGet package not installing in .NET Framework

I have created .net standard library project and I have created nuget package for this library, Now I need to install this package in both application .Net Core and .Net Framework4.5. Working fine in .Net Core but while installing .Net framework project it was showing below exception.
You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Please let me know the right approach to resolve this.
The library that you have created targets .NET Standard 2.0, as stated in your tags. .NET Framework 4.5.2 does only implement .NET Standard up to version 1.2, that is why the assemblies are not compatible.
You should change your library to a .NET Standard version that is implemented by both .NET Core and .NET Framework or upgrade your .NET Framework version accordingly.
You can find the version mappings here, credits to #Matt Ward for providing the source.

System.Data.Entity is not available

I have added .Net Standard Library 2.0 and I have installed EntityFramework 6.4.0 via NuGet Package manager, But unable to inherit DbContext in my class because System.Data.Entity is not available. What should I do to use DbContext?
As #magicandre1981 said, you need to upgrade to .NET Standard 2.1.
I hate all these hidden version incompatibilities! We had EntityFramework 6.2 running in a .NET Standard 2.0 project. Updating EF produced no version incompatibility warnings, even though if you look closely from EF 6.3+ it requires .NET Standard 2.1.
Edit: And the calling project is Framework 4.8, which does NOT support .NET Standard 2.1. So it's back to EF 6.2 and .NET Standard 2.0 for me.

Is it possible to use Entity Framework 6.3.0 in a .NET Standard 2.0 class library?

Is it possible to use Entity Framework 6.3.0 in a .NET Standard 2.0 class library?
In Dependencies -> Packages I have a reference to Entity Framework 6.3.0
And I have code like this:
using System.Data.Entity;
public partial class AlertContext : DbContext
But I get the following errors:
The type or namespace name 'Entity' does not exist in the namespace
'System.Data' (are you missing an assembly reference?)
The type or namespace name 'DbContext' could not be found (are you
missing a using directive or an assembly reference?)
6.3.0 was the first version of Entity Framework 6 to target .NET Standard; it targets .NET Standard 2.1 along with .NET 4.0 and .NET 4.5, as can be seen in its Nuget listing. 6.2.0 only targeted .NET.
Note that .NET Standard 2.0 is still not a valid target.
Depending on your scenario, you might be able to get away with multi-targeting your library to .NET (in my example below, .NET 4.7.2) and .NET Standard 2.1:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;netstandard2.1</TargetFrameworks>
</PropertyGroup>
</Project>
Whether this is viable depends on 2 factors:
Your other references. The combination I offer above will be fine in most cases as .NET 4.7.2 and .NET Standard 2.1 can reference .NET Standard 2.0 packages, which covers most but by no means all modern packages.
The frameworks that you wish to consume your library from. The .NET target means, of course, that the library can be consumed by .NET Framework projects of the same .NET version or higher. The .NET Standard 2.1 target allows the library to be consumed by projects targeting .NET Standard 2.1, .NET Core 3.0, Mono 6.4, and higher, plus the latest versions of Xamarin. The notable omission is versions of .NET Core prior to 3.0. EF6 is not available to .NET Core 1 or 2. See the .NET Standard .NET implementation support table for the full list.
* I have used .NET 4.7.2 for my illustration because whilst .NET 4.6.1 officially supports .NET Standard 2.0, Microsoft recommend using 4.7.2 or higher. See my answer here for more information.
I found two alternatives:
downgrade EF to a lower version (6.2) or
Nuget install Microsoft.EntityFrameworkCore and use the following :
using Microsoft.EntityFrameworkCore;
public partial class AlertContext : DbContext

Support .net Core for a nuget package

I have created a nuget package implementing TinyEncryptionAlgorithm but it supports only .Net 4.6.1
Now I want to use this nuget into a .net core application NETStandard.Library and I don't know what I have to do.
Do I have to implement a completely new nuget package or I can include both assemplies in the same nuget package?
I have tried to create a NetStandard library and reference it from a .Net 4.6.1 but this is not working.
To support multiple version of .Net you must create portable libs.
Here is a tutorial of how to publish nuget for portable libs.
https://docs.nuget.org/ndocs/guides/create-net-standard-packages-vs2015