Which nuget package contains MediaTypeNames? - asp.net-core

I have two projects:
an ASP.NET Core 2.2 project (<Project Sdk="Microsoft.NET.Sdk.Web">), which references the Microsoft.AspNetCore.App metapackage
a supporting "utils" project (<Project Sdk="Microsoft.NET.Sdk">), which references various nuget packages that I need in that project (I can't just reference the metapackage as it's not a web project type)
In the utils project I need to reference MediaTypeNames.Application.Json. I discovered it is in the System.Net.Mime namespace, which is in the System.Net.Mail assembly.
But that is in a beta nuget package, which was surprising. Also, the Microsoft.AspNetCore.App metapackage doesn't reference it, which was also surprising and confusing.
So which nuget package should I reference in my utils project, so I can use MediaTypeNames.Application.Json?

The package you linked to has a description that says "This is an untested port of System.Net.Mail" and if you look at the owner, it's not Microsoft. This is certainly not an official package.
Looking at the docs for MediaTypeNames.Application.Json, it says it's available for netcoreapp2.1 and netcoreapp2.2 and the previews of netcoreapp3.0 and netstandard2.1. It doesn't say anything about a pacakge being available for other TFMs.

Related

.NET 7 dependencies and nuget packages managing

I've started a new .NET 7 project in Visual Studio 2022. The template I used was "ASP.NET Core WebAPI". The project turned out to look like this in the solution explorer:
I can see that there is a dependency upon a series of DLLs in the folder "C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\7.0.2\ref\net7.0". When I browse to this folder and grab, for instance, the "Microsoft.AspNetCore.Http.Abstractions.dll" assembly I see its version as 7.0.22..... which makes sense.
What is weird is that when I click "Manage NuGet Packages" on this project I see absolutely no NuGet package already installed. It looks like this dependency mechanism is something independent of NuGet.
Now I want to create a class library that will encapsulate some common functionality I'd like to share across the projects but it needs to read data from the HttpContext class, which is defined in the "Microsoft.AspNetCore.Http.Abstractions.dll" file. So how should I add this dependency?
Adding it through "dotnet add package Microsoft.AspNetCore.App" command on the class library projects seems like a waste of resources as it adds the entire bundle of dlls and I only care about .Http.Abstractons.dll and it's direct dependencies.
Plus, when I ran the command Visual Studio complained with the warning:
NETSDK1080 A PackageReference to Microsoft.AspNetCore.App is not necessary when targeting .NET Core 3.0 or higher. If Microsoft.NET.Sdk.Web is used, the shared framework will be referenced automatically. Otherwise, the PackageReference should be replaced with a FrameworkReference".
Adding the dll through NuGet worked as Visual Studio was not complaining any more but the version of assembly added was 2.2.0 and not 7.0.2 as in the dotnet package. So technically, the HttpContext referenced in one projects is a different thing to the HttpContext referenced in the other project.
Please help me understand this mechanism and how should I add the dll of interest to my project to be able to access HttpContext in my library.
When should I use dotnet add package and when should I use NuGet packages management? Any good reading on this subject to bring me up to speed from .NET Framework 4.+ to .NET 7 in this area?
As .NET user for the last 10 years or so I feel so lost in the recent developments and find official docs I can find on the web of little use.
I tried adding the Microsoft.AspNetCore.App package through the "dotnet add package" command - Visual Studio complained, plus it pulled the entire bundle of assemblies but I care about only "Microsoft.AspNetCore.Http.Abstractions.dll".
I tried adding the "Microsoft.AspNetCore.Http.Abstractions" NuGet package but the version of assembly added was completely different to the one referenced in the WebAPI project.
What is weird is that when I click "Manage NuGet Packages" on this project I see absolutely no NuGet package already installed.
Those dependencies are determined by the project SDK which can be found in the root element of .csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
...
</Project>
So how should I add this dependency?
For latest versions of .NET you should reference corresponding SDK via FrameworkReference, for example to reference ASP.NET Core components you should add <FrameworkReference Include="Microsoft.AspNetCore.App"/> to library projects .csproj file as mentioned in the docs (and in the warning):
<Project Sdk="Microsoft.NET.Sdk">
<!--... rest of file-->
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<!--... rest of file-->
</Project>

Esri.ArcGISRuntime nuget package is not supported for netcoreapp2.2

I'm trying to use the following classes CredentialRequestInfo and Credential.
And as mentioned in ArcGIS Developers, in order to use the classes we need to install Esri.ArcGISRuntime nuget package.
But when installing the package, I get the following error:
The 'Esri.ArcGISRuntime' nuget package is not supported for the Target Framework 'netcoreapp2.2'
Is there a work-around we can do in order to use this nuget package? Or is there any updates or what?
After searching and talking with developers in esri. Found out that to use this nuget package I have to use .net core 3.1.
Esri.ArcGISRuntime will not work with .net core 2.2.

What am I missing to upgrade asp.net mvc .net core 2.2.0 apps to .net core 2.2.1

I have the latest version of visual studio, the sdk and runtimes for x64 and x86 version 2.2.1, but my asp.net mvc .net core applications will only recognize being 2.2.0. I can install 2.2.1 into .net core libraries.
What do I need to change to allow my web projects to be 2.2.1 instead of 2.2.0?
(It can't be done through nuget, it provides the statement: Implicitly refrenced by an SDK. To update the package, update the SDK to which it belongs
Since the project is referencing a library with 2.2.1, I see the error: Error NU1605 Detected package downgrade: Microsoft.AspNetCore.App from 2.2.1 to 2.2.0. Reference the package directly from the project to select a different version.)
According to Microsoft documentation packages Microsoft.AspNetCore.App and Microsoft.NETCore.App have special versioning semantics which is handled outside of NuGet.
Also note that specifying a version number on Microsoft.AspNetCore.App package does not guarantee that desired version will be chosen. In general, you should not explicitly specify Microsoft.AspNetCore.App version unless you have a good reason to do so (applies to .NET Core 2.1 and later).
You can read more about that here: Microsoft.AspNetCore.App metapackage
If you want to target specific SDK used in your project or solution, add global.json file to project folder (if you want to target only that specific project) or solution folder if you want to target all projects in the solution.
global.json example:
{
"sdk": {
"version": "2.2.103"
}
}

Can build and run on Visual Studio but cannot Publish

I am having a weird situation where I cannot publish my final Web project. Here is the project structure:
Foo.Services.Common: this is shared library: .NET Standard 2.0.3, Microsoft.AspNetCore.Mvc.Core 2.1.0 with the class DefaultWebSettings defined.
Foo.Services.Common.Razor: Razor Class Library, has reference back to Foo.Services.Common and uses DefaultWebSettings: NETStandard.Library 2.0.3, Microsoft.AspNetCore.Mvc 2.1.0 and some other ASP.NET Core related package (static files, Configuration)
Foo.Services.Api: ASP.NET Core API only (no View, no Razor), has reference back to Foo.Services.Common. Publish well. Uses: Microsoft.AspNetCore.App 2.1.0, Microsoft.NETCore.App 2.1.0.
Foo.Services.Web: front end project. This one is the one I cannot publish! This one has references to both Common projects. Uses: Microsoft.AspNetCore.App 2.1.0, Microsoft.NETCore.App 2.1.0
However, upon publish, this one shows up:
The type or namespace name 'DefaultWebSettings' could not be found
(are you missing a using directive or an assembly reference?)
The error location is in a file of Foo.Services.Common.Razor project, NOT the Web project.
Funnily, Visual Studio perfectly works even with IntelliSense and Go to Definition:
I can build in both Debug/Release mode, run with/without debug any project in the solution well. Moreover, publishing Foo.Services.Common.Razor works without any problem!
In short: I cannot publish my Web project and have no idea what is the problem. I have tried:
Clean/Build.
Delete/Re-add references.
Manually delete all obj and bin folders.
Please show me what I may missing.
In the end, I had to remove Reference of the Common from Common.Razor and Web projects. I guess they could not build because of some conflict between .NET Standard and .NET Core. Had to copy all code of Common into Common.Razor.

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.