When we are upgrading our existing class library to the latest .NET Core, like this:
<TargetFramework>netcoreapp3.0</TargetFramework>
On doing so, you may get the following warning:
C:\Program Files\dotnet\sdk\3.0.000\Sdks\Microsoft.NET.Sdk\targets
Microsoft.NET.Sdk.DefaultItems.targets(149,5): 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.
To fix this, if you are building a web project, please make sure the first line of your project file is:
<Project Sdk="Microsoft.NET.Sdk.Web">
In this case, it is automaticly included framework: Microsoft.AspNetCore.App
. You don't have to include it again.
If you are building a razor library not a web project, please make sure the first line of your project file is:
<Project Sdk="Microsoft.NET.Sdk.Razor">
In this case, your library might dependend on some class in ASP.NET Core
. You have to add this:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
Don't forget to add:
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
to <PropertyGroup>
If you are not building a razor library nor a web project, typically you don't need Microsoft.AspNetCore.App
. If you can really make sure what you are doing and really need it , consider adding:
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
And for possible error:
error CS8107: Feature 'default literal' is not available in C# 7.0. Please use language version 7.1 or greater.
This error is very strange. From the official Microsoft's document:
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
The latest .NET Core 3.0 is supporting the latest C# (C# 8.0). Which already supports the latest language features. This issue may occur if you are not using the latest Visual Studio.
To solve this, consider adding:
<LangVersion>latest</LangVersion>
Clean and rebuild the project. And the error disappears.
I appreciate your detailed explanation on upgrading an existing class library to .NET Core 3.0. Your blog post effectively highlights the possible warning and errors that one might encounter during the process, and provides clear solutions to address them. The inclusion of relevant links to the official Microsoft documentation also adds credibility to your explanations.
One of the key points you've mentioned is the importance of specifying the correct Sdk attribute in the Project element, depending on whether the project is a web project, a Razor library, or neither. You've also provided guidance on when and how to include the Microsoft.AspNetCore.App framework reference.
Your discussion on the error related to the default literal feature being unavailable in C# 7.0 is particularly interesting. It's great that you've pointed out that this issue might occur if the latest Visual Studio is not being used, and provided a solution by adding the LangVersion element with the value "latest" to the project file.
As a suggestion for improvement, it would be helpful to provide a brief introduction to the .NET Core 3.0 and its benefits, to give readers a better understanding of why they should consider upgrading their class libraries. Additionally, providing a step-by-step guide or a checklist for the entire upgrading process might be beneficial for readers who are new to this topic.
Overall, your blog post is informative and well-structured, making it easy for readers to follow and understand the solutions to potential issues during the upgrading process. Keep up the great work!