When creating an ASP.NET Core 6 application with separate assembly-based app parts, it's crucial to reference the appropriate NuGet packages for successful compilation.
As mentioned in the question, the Microsoft.AspNetCore.App and Microsoft.AspNetCore.App.Refs packages are not suitable for ASP.NET Core 6. Instead, you should add the following reference to your library project .csproj file:
<ItemGroup> <FrameworkReference Include="Microsoft.AspNetCore.App" /> </ItemGroup>
This FrameworkReference ensures that your library project is compatible with the ASP.NET Core 6 application. By adding it, you can enjoy the benefits of app parts without encountering the previously mentioned build error.
Defining an Entry Point for Library Projects
It is important to note that if you use the Microsoft.NET.Sdk SDK for your library project, you need to provide an entry point for compilation. To satisfy this requirement, you can create an internal Program class with a Main method, as shown in the question:
internal static class Program { public static void Main() => throw new NotImplementedException(); }
This step ensures that your library project compiles successfully even though it's not a standalone application.
The above is the detailed content of How to Properly Reference NuGet Packages for ASP.NET Core 6 App Parts?. For more information, please follow other related articles on the PHP Chinese website!