Combine Microsoft nuget with lower dotnet core version - .net-core

I have a dotnet core 2.1 lts docker image and I need to have a timestamp in the log. The Microsoft.Extensions.Logging preview for dotnet core 3.0 has this feature. Of course this package will not have long term support.
Can I combine a nuget package, which share the version of dotnet core, with a lower version of the dotnet core framework or does that result into in unsupported setup?

You didn't specify what your applications uses, so I need to write a somewhat generic answer.
The package Microsoft.Extensions.Logging targets netstandard 2.0, which means it will work on dotnet core 2.1
This issue you will have, is that it will force the dependencies it uses to upgrade too:
Microsoft.Extensions.Configuration.Binder (>= 3.0.0-preview4.19216.2)
Microsoft.Extensions.DependencyInjection (>= 3.0.0-preview4.19216.2)
Microsoft.Extensions.Logging.Abstractions (>= 3.0.0-preview4.19216.2)
Microsoft.Extensions.Options (>= 3.0.0-preview4.19216.2)
And those have dependencies too... in the end it might upgrade quite a lot of your project dependencies with packages which are in preview. (thus not supported)
I would not advice you to do this, but in the end it simply depends on what functionality you are using in your application. If only your code depends on the Microsoft.Extensions.Logging functionality you should be okay, although currently not supported. As soon as you use other packages which use one of the upgrade Microsoft.Extensions package the major version change should tell you that this might cause issues.

Related

EntityFrameworkCore nuget packages confusion in Asp.net Core

I'm trying to create a web application / api using the dot net core.
for the database I choose Microsoft SqlServer, and EntityFrameworkCore as ORM
in previous versions like Asp.Net MVC 5 i used like this:
Install-Package EntityFramework
and i was able to work with Migrations, DbContexts ...
but now with dot net core I saw that I have to install multiple EntityFramework nuget packages, I saw this in multiple tutorials and also in real world.
developers installing the following packages without explaining why:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Design
Microsoft.EntityFrameworkCore.Relational
Microsoft.EntityFrameworkCore.SqlServer
Microsoft.EntityFrameworkCore.Tools
I googled it so it turns out that I need only these:
Microsoft.EntityFrameworkCore
Microsoft.EntityFrameworkCore.Sqlserver
Microsoft.EntityFrameworkCore.Tools
because the Tools package brings up the Design package from this post : Purpose of package "Microsoft.EntityFrameworkCore.Design"
the question is which packages do we need in dot net core to use entityframeworkcore in our project?
You only need:
Microsoft.EntityFrameworkCore.Sqlserver
(It depends on .Relational)
If you need to run EF Core commands in VS Package Manger console install:
Microsoft.EntityFrameworkCore.Tools
If you want the dotnet CLI EF Core tools run:
dotnet tool install --global dotnet-ef
If you are using .net 5 you need to specify the version that the package is for.
But first you need to open the package manager console. That is from View->Other Windows->Package Manager Console. There you need to make sure that the default project is the project you want to work with.
Like this
Then run these commands in the package manager console:
1.
Install-Package Microsoft.EntityFrameworkCore.Tools -Version 5.0
Install-Package Microsoft.EntityFrameworkCore.SqlServer -Version 5.0
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
(for the SqlServer.Design you don't need to specify the version)
(if you are using .net 6 just remove the "-Version 5.0" from the commands)

.net core packages and dependency to the .net runtimes

Assuming I'm already using the NuGet Package
Microsoft.AspNetCore.Components 5.0.3
Can I upgrade it to 5.0.5 without having the 5.0.5 runtime installed (dotnet --list-runtimes)?
If I look at the dependencies in Nuget it just states:
net5.0 (no specific sdk, nor runtime)
-> Microsoft.AspNetCore.Components.Analyzers (>= 5.0.5)
-> Microsoft.AspNetCore.Authorization (>= 5.0.5)
Is there a specific reason to upgrade to 5.0.5 from 5.0.3? If its because you need something specific added in 5.0.5, then, while it might work, chances are it wont, as Andy says

Using a nuget package with a reference to a 2.2 shared framework package in 3.1

We are currently upgrading some of our applications from dotnet core 2.X to core 3.1 and I have come across an interesting conundrum. We have a shared nuget package which references Microsoft.AspNetCore.Http.Abstractions 2.2.0 and when we are building our new 3.1 version with docker and the 3.1 sdk we are getting errors about being unable to resolve the assembly reference.
I can fix this by adding an explicit reference to Microsoft.AspNetCore.Http.Abstractions 2.2.0 to the project but I am interested in the "correct" way approach this problem. It feels like there should be a way to have the package reference either assembly depending on what is installed on the host. Meaning our package can be shared between 2.1 and 3.1.
We could create a new package that references the 3.1 shared framework but then we would need some way to distinguish which package to use 2.2 or 3.1 - we would like to avoid pinning our package versions to dotnet core versions because we use our own semver numbering for the packages.
The crux of the question is - what is the best way to manage a package that has a dependency on a previous version of AspNetCore.App?
So this seems strange to me but the fix works. It turns out if I reference the Microsoft.AspNetCore.Http.Abstractions 2.0.2 dependency in my nuget package then any consumers of that package work both on 2.x projects and 3.x ones. It's like the core 3.x runtime understands how to deal with a 2.0.2 package but not a 2.1 or a 2.2 one!
I am sure there is a jolly good reason for this but im not clear on what that is!

Which version of Microsoft.AspNet.Mvc is supported by .NETCoreApp v2.2?

I am working on a Ubuntu 18.04 environment using Visual Studio Code and .NET Core v2.2.
After including a few existing projects into a solution that I'm working on, I ran into errors when I tried to compile stating that the namespace "Microsoft.AspNet.Mvc" could not be found.
So, I added a package reference for the projects that were complaining by using the dotnet CLI:
dotnet add package Microsoft.AspNet.Mvc --version 3.0.20105.1
But now when I try to dotnet restore or dotnet msbuild the solution file, I'm getting warnings reporting that:
warning NU1701: Package 'Microsoft.AspNet.Mvc 3.0.20105.1' was
restored using '.NETFramework,Version=v4.6.1' instead of the project
target framework '.NETCoreApp,Version=v2.2'.
This package may not be fully compatible with your project.
I would like to figure out which package version of Microsoft.AspNet.Mvc I need to install in order to be compatible with .NET Core v2.2.
I realize that this is just a warning and using the .NETFramework v4.6.1 may be okay, but I have been debugging a very strange issue that is only happening on a Ubuntu environment, so I would like to determine whether package versioning is a problem.
I have tried Google searching to determine which version of MVC is compatible with .NET Core 2.2, but I have yielded any useful results.
Does anyone know the answer to this question? Or would you be able to point me in the direction of a source that can answer it?

Could not install package 'Splat 2.0.0'

Trying to install Splat 2.0.0 into Xamarin Forms project results with error:
Could not install package 'Splat 2.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', 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.
How to resolve this issue please?
Thanks,
AG
I found this on the GitHub of your tool:
Please use Splat 1.6.2 when targeting PCL projects. v2.0 and onwards is netstandard only. There will be no updates to the 1.6.x series so if you need to patch the release then please fork and maintain your own copy/build from source.
It seems they stopped supporting PCL. So as a solution I suggest using Splat 1.6.2 as that seems to support ¨PCL. Good luck

Resources