-1

I have an ASP.NET MVC application that I am converting to ASP.NET Core.

It is composed of many base libraries and one library that provides the top-level Program.cs entry point.

I cannot set Microsoft.NET.Sdk.Web as the project type for my base libraries on the Microsoft.AspNet.Core framework, because then the compiler will error out with CS5001 Program does not contain a static 'Main' method suitable for an entry point. And of course, the base libraries should not be the ones to define an entry point.

The reason why this is a problem is because I can't find a way to reference a specific package from the ASP.NET Core framework (in my example, Microsoft.AspNetCore.StaticFiles) without declaring the project file as <Project Sdk="Microsoft.NET.Sdk.Web">. The version of this package on NuGet is outdated.

What is the correct way to reference the .NET 7.0 version of the Microsoft.AspNetCore.StaticFiles package?

  • 2
    You don't need `Microsoft.NET.Sdk.Web` in a class library. Just create a Class Library project, add the packages you need and use it. – Panagiotis Kanavos Aug 30 '23 at 12:48
  • Thanks, but there is no `Microsoft.AspNetCore.StaticFiles` package outside of `Microsoft.NET.Sdk.Web` . Only the very old deprecated version on NuGet. – Hanno Bunjes Aug 30 '23 at 12:50
  • 2
    What are you doing with these static files in this "base library"? Maybe there is something there that don't really belong in a class library. – topsail Aug 30 '23 at 12:55
  • @HannoBunjes: What is this "class library" doing that it needs static files for a web project? If the goal is to separate front-end-specific components into multiple front-ends (something like a micro-front-end architecture) then maybe it *should* be its own web application with its own entry point? It sounds like this is less a question of "how to create a class library" and more a question of what *specifically* you're trying to do. – David Aug 30 '23 at 12:57
  • Indeed, `Microsoft.AspNetCore.StaticFile` is an assembly that adds the StaticFile middleware through non-extensible extension methods on `IApplicationBuilder` and `IEndpointRouteBuilder`. There's little reason to use it outside `Program.cs` itself, or a configuration helper in the root application. – Panagiotis Kanavos Aug 30 '23 at 13:01
  • There is a valid use case where a class library can act as a plugin and add middleware. The StaticFile middleware could just be one example. – Hanno Bunjes Aug 30 '23 at 13:24
  • Additionally, `MIcrosoft.AspNetCore.StaticFiles` contains more than just the middleware! It also contains a `FileExtensionContentTypeProvider` that could be useful on its own. – Hanno Bunjes Aug 30 '23 at 13:27

0 Answers0