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

时间:2019-06-19 07:54:34

标签: visual-studio-2013 nuget nuget-package csproj .net-standard-2.0

我有一个vs 2013项目,目标是.net Framework 4.8。我需要添加对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)的引用吗?

1 个答案:

答案 0 :(得分:1)

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

如果您真的不能升级到较新的Visual Studio,也许可以考虑使用.NET Core。 Visual Studio Code是一个很小的安装,并且提供了良好的.NET开发经验,否则,任何文本编辑器都可以,如果您不能使用支持Omnisharp的软件,就会失去智能感知。