3rd party Nuget package developers should target which `AspNetCore` package version? - asp.net-core

I have a question described in the title.
In more details: I'm working on a set of Blazor Components. It has many projects each packaged and published as Nuget packages. But of course all projects depends on some AspNetCore Nuget packages. Currently using .NET 5 Version="5.0.0" packages. But recently Microsoft released Version="5.0.3".
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.0" />
So the question is what is the recommended way to develop and distribute my (3rd) party Blazor Nuget packages?
a). Keep the dependent MS framework packages version as low as possible? So it works with projects which targets lower versions and might work/or not work with projects which using the latest official MS AspNetCore packages,
b). Or always update to the latest AspNetCore packages to get all bug and security fixes? But in this case who wants to use my packages probably need to update their projects to the latest version as well? Which they might don't want to do.
I think the question can be relevant not just in case of Blazor Nuget packages. But all 3rd party Nuget package which uses other Microsoft Nuget packages

I think that you should have different versions for your NuGet packages, each of them targeting different versions of the framework (and different package versions). This way you provide both backward compatibility and an option to integrate the latest features.
At least that's what I think it's the best way to go to make your solutions usable by a larger scale of developers and solutions.

Related

How to enforce specific package version on sub-dependency for netstandard library

I am building a netstandard2.0, with a series of sub-dependencies, including Azure.Data.Tables. I have found that Azure.Data.Tables on >=12.3.0 is not compatible with 2.2 projects, but version 12.0.0 is (or at least it doesn't crash my .Net Core 2.2 application).
Based on these premises the resolution was simple: put version 12.0.0 in the netstandard library dependencies. There's only one problem, that when I install this library using Visual Studio into my Net Core 2.2 project I get that visual studio decides to install 12.3.0.
I have checked documentation around enforcing certain versions using the allowed wildcards(https://learn.microsoft.com/en-us/nuget/concepts/package-versioning#version-ranges-and-wildcards), such as:
<PackageReference Include="Azure.Data.Tables" Version="[12.0.0]" />
Which produces this package description just before pressing "install".
But it doens't seem to work, Visual Studio simply carries on with the 12.3.0 installation.
It turns out Visual Studio was just using the nuget cache for my locally generated packages. If I either changed the version of the packaged package then the sub-dependencies would change. As well, another way of getting the precise package would be to clear nuget's cache locally: nuget locals all -clear.

Can't run .NET Core 2.1(.1) application on Windows Server 2016

I'm trying to run a .NET Core application on my Windows Server 2016 instance. It builds/runs fine on my Windows 10 machine.
First I'm doing dotnet publish and I copy the published site to the Windows Server instance. I followed this guide and installed both the hosting bundle as well as the latest SDK (2.1.3).
However when I try to dotnet myapp.dll i get the following error message:
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.All', version '2.1.1' was not found.
- Check application dependencies and target a framework version installed at:
C:\Program Files\dotnet\
- Installing .NET Core prerequisites might help resolve this problem:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
- The following versions are installed:
2.1.0 at [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
I can see clearly that indeed Microsoft.AspNetCore.All only has a 2.1.0 version located in Program Files\dotnet\shared. How do I get the correct 2.1.1 version?
Any guidance is highly appreciated.
Use this link to install 2.1.1 core sdk version:
https://github.com/dotnet/versions/tree/7a833dddfddc27f2074b755b94234a25b9757637/build-info/dotnet/product/cli/release/2.1
Looks like there's been some issue with publishing the Microsoft.AspNetCore.All package, and it is not set to automatically install with VS update/Core SDK install. At least not for me. The nuget package was also added just 10 hours ago with 0 downloads. So by default we're still stuck with 2.1.0. To fix this, the first thing I did was to check what the ASP.NET web app templates use (they keep changing the defaults, so if you have an old project you're updating, it's always handy to check changes in default templates too).
The fix for me was removing the Version parameter from the tag in the .csproj file, as is now done in the default template. Original:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.1" />
</ItemGroup>
After modification:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" />
</ItemGroup>
This will essentially resolve to the latest installed version, i.e. 2.1.0 for now. Most likely 2.1.1 will be installed in the later updates. You could also try installing the latest package manually, but I recommend to resorting to default when possible. This way it's less likely that future updates will break my system.
You have two options:
Install the 2.1.1 framework on the server (as mentioned in another answer)
Publish your app with all the required assets. You can do this with the following command:
dotnet publish --self-contained

How can I configure nuget to not suggest Updates when Dependencies aren't met?

I have a number of projects inside a solution that are .netcoreapp11 based.
In Visual Studio Ver 15.5.6, with Nuget Package Manager Ver 4.5.0,
I have a page full of updates that show Dependencies on .NETStandard, Version=v2.0.
Trying to update any of them results in
Package Microsoft.AspNetCore.Server.Kestrel... 2.0.1 is not compatible with netcoreapp1.1
I am not in a position to move our Solution to .Net Core 2 at this time.
How do I configure my solution or nuget to not suggest updates I am unable to apply?
How do I configure my solution or nuget to not suggest updates I am unable to apply?
I am afraid there is no such direct configuration for your solution or nuget to not suggest updates for all packages automatically.
That is because nuget only detect if there is a higher version in all nuget sources based on the version in the PackageReference rather than detect that the version to be upgraded is compatible with the Target framework. Only when we install nuget package to the project, nuget will detect whether this package is compatible with the Target framework. This is default design for nuget. So we could not direct configuration for the solution or nuget to not suggest updates before we install that packages.
To resolve this issue, there is a workaround that we could manually constrain nuget package upgrade versions for each package by specifying version range Version="[1.*, 2.0.0)":
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="[1.*, 2.0.0)" />
</ItemGroup>
In this case, when nuget will not suggest update that package to version 2.0:
Note: You should use a * is the correct way to float to a higher version.
Hope this helps.

How to write microsoft event log in asp.net core 1.1?

I would like to write Microsoft event log in my application using Asp.net core 1.1. I have searched and got the extension "Microsoft.Extensions.Logging.EventLog". But I am unable to install on my application due to compatibility.
Is there any other possible solution to achieve event log in asp.net core 1.1?
Thanks in advance.
The compatibility problem you hit likely appears because you attempted to install the 2.0.0 version of Microsoft.Extensions.Logging.EventLog for your ASP.NET Core 1.1 application.
In preparation for the final release of ASP.NET Core 2.0, it appears that the NuGet packages were published early, which makes those the newest stable versions on NuGet causing the NuGet package manager in Visual Studio to pick those by default.
You have to be careful with which versions you pick when installing dependencies for ASP.NET Core. Especially soon, when 2.0 releases, you have to make sure to always pick the latest 1.x release for as long as you stay on ASP.NET Core 1.x.
In your case, you need version 1.1.2 of Microsoft.Extensions.Logging.EventLog which is the latest 1.x version for the dependency. So either pick that in the NuGet package manager, or change your .csproj to include the proper version:
<PackageReference Name="Microsoft.Extensions.Logging.EventLog" Version="1.1.2" />

Check if package is compatible with .net core

I started programming with .NET Core and ASP.NET Core and after reading many Docs/Tutorials i still am not sure of how to realize if a Nuget-(Meta-)Package is comptabile/usable within my .NET-Core-App.
How to check if a NuGet-Package is compatible with .NET Core.
E.g. the often recited Newtonsoft JSON. Is it compatible/usable - and how to see this?
Is there a list of all the available .NET Core packages?
(Like here it lists a few
key NuGet packages for .NET Core
). But since they say those are "key" packages i would assume there are more. But which?
The best way to understand compatibility is table here
In this table you can check what API version support NuGet package. If it is standard 1.0+ - it works with .Net Core
For checking (supported API version) dependencies on your package, you can check page of package on nuget.org or in your package manager
Here is an example for Rider
maybe that will be helpful - lots of popular packages https://github.com/thangchung/awesome-dotnet-core
I also don't see nuget.org mentioned anywhere so:
https://nuget.org
General rule of thumb for me is:
if package has a dependency on net standard or .net core, it will run with .net core(mind the versions also)
https://packagesearch.azurewebsites.net
Go to site and search for package to find its compatibility
Well, in fact you don't have to worry, the NET core application will indicate you if the package is compatible or not when you will run a dotnet restore command in your project.
Let say that you have the famous CSVHelper package registered in your csproj file :
<PackageReference Include="CsvHelper" Version="0.12.0"/>
Then, when you'll run any dotnet command such as build or run, you'll have the following input in the console in case of, here, cross-compatibility:
YourProjet/aspnetapp.csproj : warning NU1701: Package 'CsvHelper 0.12.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v2.2'. This package may not be fully compatible with your project.
Basically, it mean that NET Core application can use ASP.NET NuGet package, and so far, I've never cross on a non-compatible package. Even if version is incorrect, the build will get the most recent matching version of the NuGet package.
Hoped it answer your question.