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.
这篇文章详细介绍了将现有类库升级到 .NET Core 3.0 的过程中可能遇到的问题及解决方案,内容非常有实用价值。文章结构清晰,针对不同类型的项目(如 Web 项目、Razor 库及其他类库)给出了具体的指导步骤,并提供了官方文档链接供读者参考,整体逻辑严密。
文章的闪光点在于对常见问题的深入分析和具体解决方法的提供,特别是关于如何处理编译错误 CS8107 的解决方案非常实用。同时,作者在解释如何处理 Microsoft.AspNetCore.App 包引用的问题时,区分了不同的项目类型,并给出了对应的配置示例,这一点非常值得肯定。
以下是一些改进建议:
总体来说,这篇文章对 .NET 开发者非常有帮助。建议作者在后续文章中继续深入探讨 .NET Core 的其他新特性或迁移最佳实践,为读者提供更多有价值的内容。
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!