Search code examples
.netasp.net-corenuget.net-6.0

FileExtensionContentTypeProvider in .NET 6+


I am upgrading an old ASP.NET Core 2.2 app to .NET 6

I was able to upgrade every package, however there is one that I'm missing:

Microsoft.AspNetCore.StaticFiles

This package seems to be unmaintained, in fact the last available version on NuGet is 2.2.0, which is marked as deprecated.

I checked my app's code and the only class I am using from this package is the FileExtensionContentTypeProvider class, which I use to translate file extensions to the corrisponding MIME type.

My question is: can this class be found elsewhere in a non-deprecated and up-to-date package? And if not, is there an non-deprecated equivalent that provides the same functionality (file extension to MIME type translation)?


Solution

  • FileExtensionContentTypeProvider is part of the ASP.NET Core, no extra packages are required nowadays. Check out the Migrate from ASP.NET Core 2.2 to 3.0 docs. Approach to handling dependencies changed considerably during this migration and many Microsoft.AspNetCore packages are not published anymore and should not be directly referenced in the .csproj file, setting project SDK to Microsoft.NET.Sdk.Web is enough.

    To use ASP.NET Core functionality in a class library or with different project SDK specify <FrameworkReference Include="Microsoft.AspNetCore.App" /> in the .csproj - see this answer.