You need to add a FrameworkReference
to your project file instead of a PackageReference
as described here.
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Right-click your project in the Solution Explorer and select “Edit Project File” to open the file and look for the <ItemGroup>
section, creating a new one if it does not exist.