如何从 VS2013 .Net Framework 4.8 项目添加对 netstandard 2.0 Nuget 的引用

How to Add Reference to a netstandard 2.0 Nuget from VS2013 .Net Framework 4.8 Project

我有一个针对 .net Framework 4.8 的 vs 2013 项目。我需要添加对 Microsoft.Extensions.Hosting nuget 包的引用,但是当我这样做时,我在包管理器控制台上收到以下错误。

Error message:

PM> Install-Package Microsoft.Extensions.Hosting -Version 2.2.0

Installing 'Microsoft.Extensions.Hosting 2.2.0'.

You are downloading Microsoft.Extensions.Hosting from Microsoft, the license agreement to which is available at https://raw.githubusercontent.com/aspnet/AspNetCore/2.0.0/LICENSE.txt. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.

Successfully installed 'Microsoft.Extensions.Hosting 2.2.0'.

Adding 'Microsoft.Extensions.Hosting 2.2.0' to QuartzExample.

Uninstalling 'Microsoft.Extensions.Hosting 2.2.0'.

Successfully uninstalled 'Microsoft.Extensions.Hosting 2.2.0'.

Install failed. Rolling back...

Install-Package : Could not install package 'Microsoft.Extensions.Hosting 2.2.0'. You are trying to install this package into

a project that targets '.NETFramework,Version=v4.8', but the package does not contain any assembly references or content

files that are compatible with that framework. For more information, contact the package author.

At line:1 char:1

+ Install-Package Microsoft.Extensions.Hosting -Version 2.2.0

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException

    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

我的项目文件看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{07E02FE5-9E9B-434D-B6A2-D037DE7CE6CA}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>QuartzExample</RootNamespace>
    <AssemblyName>QuartzExample</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Quartz, Version=3.0.7.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
      <HintPath>..\packages\Quartz.3.0.7\lib\net452\Quartz.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Quartz.Jobs, Version=3.0.7.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
      <HintPath>..\packages\Quartz.Jobs.3.0.7\lib\net452\Quartz.Jobs.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="Quartz.Plugins, Version=3.0.7.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
      <HintPath>..\packages\Quartz.Plugins.3.0.7\lib\net452\Quartz.Plugins.dll</HintPath>
      <Private>True</Private>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
    <Reference Include="System.Runtime.Remoting" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MyJob.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config">
      <SubType>Designer</SubType>
    </None>
    <None Include="packages.config" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="quartz_jobs.xml">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

我的App.Config如下

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>

  <startup> 
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
  </startup>

  <quartz>    
    <add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins" />
    <add key="quartz.plugin.xml.fileNames" value="~/quartz_jobs.xml" />
  </quartz>
</configuration>

在不更新 Visual Studio 2013 的情况下,我可以添加对 .netstandard2 nuget 的引用,例如 Microsoft.Extensions.Hosting 吗?

你不能。 VS2013 有一个古老版本的 NuGet,它对 .NET Standard 一无所知,因此无法知道 .NET Standard 2.0 是否与 .NET Framework 4.8 兼容。

如果你真的不能升级到更新的 Visual Studio,也许你可以看看 .NET Core。 Visual Studio 代码是一个小型安装并提供良好的 .NET 开发体验,否则任何文本编辑器都可以,如果您不能使用支持 Omnisharp 的东西,您将失去智能感知。