简体   繁体   English

为 .NET Core 类库项目选择框架版本 - Visual Studio 2019

[英]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.

相关问题 如何在 Visual Studio 2019 中调试 .NET 5 WinForms 应用程序,该应用程序引用 .NET Framework 4.8 class 库 - Howto debug .NET 5 WinForms application that references .NET Framework 4.8 class library in Visual Studio 2019 如何在 Visual Studio 2019 中创建 .NET framework 4.6 版本的 XUnit 项目? - How do I create .NET framework 4.6 version of XUnit project in Visual Studio 2019? 如何将 Visual Studio 2019 中的 .NET 版本更改为 .NET Framework 4.7.2? - How to change .NET version in Visual Studio 2019 to .NET Framework 4.7.2? 在 Visual Studio 2019 / .NET Framework 4.8 中确定 C# 版本 - Determine C# version in Visual Studio 2019 / .NET Framework 4.8 如何在 Visual Studio 2019 16.8.1 中创建 .Net 5.0 类库项目? - How to create .Net 5.0 Class Library project in Visual Studio 2019 16.8.1? 如何将 .Net 框架添加到 Visual Studio preview 2019 项目 - How to add .Net framework to Visual Studio preview 2019 project Class 库(.NET 标准)模板在 Visual Studio 2019 中不起作用 - Class Library (.NET Standard) Template Not working in Visual Studio 2019 Visual Studio 2019 中的 .Net Standard 1.0 class 库 - .Net Standard 1.0 class library in Visual Studio 2019 我可以在版本4.6.2的Visual Studio项目中使用针对4.5.1 .net框架的库吗? - Can I use a library which is targeted to 4.5.1 .net framework in a visual studio project of version 4.6.2 如何在.NET核心类库中引用Visual Studio共享项目 - How do I reference a Visual Studio Shared Project in a .NET Core Class Library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM