[英]Select framework version for .NET Core Class Library project - Visual Studio 2019
In Visual Studio 2019 if I try to create an ASP.NET Core web application project, I get to select the framework version in the following screen -在 Visual Studio 2019 中,如果我尝试创建 ASP.NET Core Web 应用程序项目,我将在以下屏幕中选择框架版本 -
But when I try to create a .NET Core class library project I am prompted with the following screen which does not provide any option for selecting the framework version -但是,当我尝试创建 .NET Core 类库项目时,系统会提示我以下屏幕,该屏幕不提供任何用于选择框架版本的选项 -
Clicking the Create button always creates the project right away taking the latest .NET Core version installed on my machine.单击“创建”按钮始终会立即使用我机器上安装的最新 .NET Core 版本创建项目。
So, how can I select the framework version while creating the class library project?那么,如何在创建类库项目时选择框架版本呢? Or do I have to change it manually every time after creation ?
还是每次创建后都必须手动更改它?
The ASP.NET project creation dialog providing a framework selection seems to be an exception in .NET Core / Standard projects to me.提供框架选择的 ASP.NET 项目创建对话框对我来说似乎是 .NET Core / Standard 项目中的一个例外。 At least since VS2019 with the new "New Project" dialog, you have the following options after creating the project with this dialog.
至少从带有新“新建项目”对话框的 VS2019 开始,使用此对话框创建项目后,您有以下选项。
"Normally" (to my experience), you right-click the project file in the Solution Explorer, choose "Edit Project File" and modify the <TargetFramework>
element by naming one of the valid target framework monikers. “通常”(根据我的经验),您在解决方案资源管理器中右键单击项目文件,选择“编辑项目文件”并通过命名有效的目标框架名称之一来修改
<TargetFramework>
元素。 See MSDN about them . 请参阅有关它们的 MSDN 。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>
You can also rename the element to TargetFrameworks
(note the pluralized name) to build against multiple frameworks at the same time, which are ;
您还可以将元素重命名为
TargetFrameworks
(注意复数名称)以同时针对多个框架进行构建,它们是;
separated:分开:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net451;netstandard2.0;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>
</Project>
Alternatively, you can also choose "Properties" from the project right-click menu and select a framework via a slightly dated UI not supporting all of the new csproj features, like said multi targeting:或者,您也可以从项目右键单击菜单中选择“属性”,然后通过不支持所有新 csproj 功能的稍微过时的 UI 选择框架,例如上述多目标:
If you need many new projects building against a specific framework, create a template csproj and just copy and rename it.如果您需要针对特定框架构建许多新项目,请创建一个模板 csproj 并复制并重命名它。
Also, if you want to build against preview versions of .NET Core in non-preview versions of VS, ensure you allow usage of them in Tools > Options > Environment > Preview Features
.此外,如果您想在 VS 的非预览版本中针对 .NET Core 的预览版本进行构建,请确保您允许在
Tools > Options > Environment > Preview Features
使用它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.