框架4.7.2中的无法还原nuget软件包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了框架4.7.2中的无法还原nuget软件包相关的知识,希望对你有一定的参考价值。

我有一个WPF项目。它具有使用.Net Framework 4.7.2编写的三个库。我正在尝试为该解决方案还原nuget程序包,但我不能。

当我右键单击sln文件,然后选择Restore Nuget Packages时,一切似乎都正常:

enter image description here

但是我运行程序后,它仍然缺少所有引用:

enter image description hereenter image description here

在每个csproj packagaes.config文件中存在。例如:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Autofac" version="5.0.0" targetFramework="net472" />
  <package id="Caliburn.Micro" version="4.0.62-alpha" targetFramework="net472" />
  <package id="Caliburn.Micro.Core" version="4.0.62-alpha" targetFramework="net472" />
  <package id="LiveCharts" version="0.9.7" targetFramework="net472" />
  <package id="LiveCharts.Wpf" version="0.9.7" targetFramework="net472" />
  <package id="MaterialDesignColors" version="1.2.0" targetFramework="net472" />
  <package id="MaterialDesignExtensions" version="2.7.0" targetFramework="net472" />
  <package id="MaterialDesignThemes" version="2.6.0" targetFramework="net472" />
  <package id="Microsoft.Bcl.AsyncInterfaces" version="1.1.0" targetFramework="net472" />
  <package id="Microsoft.Xaml.Behaviors.Wpf" version="1.0.1" targetFramework="net472" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.2" targetFramework="net472" />
</packages>

我的问题是,如何从该项目中还原所有nuget包?我正在使用Visual Studio 2019。

编辑:

我的.csproj之一:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" 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>{07453180-4038-457C-81BB-7017A2890660}</ProjectGuid>
    <OutputType>WinExe</OutputType>
    <RootNamespace>Thinning.UI</RootNamespace>
    <AssemblyName>Thinning.UI</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <WarningLevel>4</WarningLevel>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>binDebug</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>binRelease</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Autofac, Version=4.9.4.0, Culture=neutral, PublicKeyToken=17863af14b0044da" />
    <Reference Include="Caliburn.Micro.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
      <HintPath>....packagesCaliburn.Micro.Core.4.0.62-alphalib
et45Caliburn.Micro.Core.dll</HintPath>
    </Reference>
    <Reference Include="Caliburn.Micro.Platform, Version=4.0.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL">
      <HintPath>....packagesCaliburn.Micro.4.0.62-alphalib
et45Caliburn.Micro.Platform.dll</HintPath>
    </Reference>
    <Reference Include="LiveCharts, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL">
      <HintPath>....packagesLiveCharts.0.9.7lib
et45LiveCharts.dll</HintPath>
    </Reference>
    <Reference Include="LiveCharts.Wpf, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL">
      <HintPath>....packagesLiveCharts.Wpf.0.9.7lib
et45LiveCharts.Wpf.dll</HintPath>
    </Reference>
    <Reference Include="MaterialDesignColors, Version=1.2.0.325, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>....packagesMaterialDesignColors.1.2.0lib
et45MaterialDesignColors.dll</HintPath>
    </Reference>
    <Reference Include="MaterialDesignExtensions, Version=2.7.0.0, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>....packagesMaterialDesignExtensions.2.7.0lib
et45MaterialDesignExtensions.dll</HintPath>
    </Reference>
    <Reference Include="MaterialDesignThemes.Wpf, Version=2.6.0.325, Culture=neutral, processorArchitecture=MSIL">
      <HintPath>....packagesMaterialDesignThemes.2.6.0lib
et45MaterialDesignThemes.Wpf.dll</HintPath>
    </Reference>
    <Reference Include="Microsoft.Xaml.Behaviors, Version=1.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
      <HintPath>....packagesMicrosoft.Xaml.Behaviors.Wpf.1.0.1lib
et45Microsoft.Xaml.Behaviors.dll</HintPath>
    </Reference>
    <Reference Include="System" />
    <Reference Include="System.Data" />
    <Reference Include="System.Drawing" />
    <Reference Include="System.Drawing.Design" />
    <Reference Include="System.Xml" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xaml">
      <RequiredTargetFramework>4.0</RequiredTargetFramework>
    </Reference>
    <Reference Include="WindowsBase" />
    <Reference Include="PresentationCore" />
    <Reference Include="PresentationFramework" />
  </ItemGroup>
  <ItemGroup>
    <ApplicationDefinition Include="App.xaml">
      <Generator>MSBuild:Compile</Generator>
      <SubType>Designer</SubType>
    </ApplicationDefinition>
    <Compile Include="App.xaml.cs">
      <DependentUpon>App.xaml</DependentUpon>
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="HelpersAlgorithmTest.cs" />
    <Compile Include="HelpersCardContent.cs" />
    <Compile Include="HelpersExtensionsSimpleContainerExtension.cs" />
    <Compile Include="HelpersFileDialog.cs" />
    <Compile Include="HelpersHardware.cs" />
    <Compile Include="HelpersImageLabelModel.cs" />
    <Compile Include="HelpersInterfacesIAlgorithmTest.cs" />
    <Compile Include="HelpersInterfacesICardContent.cs" />
    <Compile Include="HelpersInterfacesIFileDialog.cs" />
    <Compile Include="HelpersInterfacesIHardware.cs" />
    <Compile Include="HelpersInterfacesIMainWindowViewModelHelper.cs" />
    <Compile Include="HelpersInterfacesIPerformanceChartViewModelHelper.cs" />
    <Compile Include="HelpersInterfacesIViewModel.cs" />
    <Compile Include="HelpersMainWindowViewModelHelper.cs" />
    <Compile Include="HelpersPerformanceChartViewModelHelper.cs" />
    <Compile Include="ViewModelsMainWindowViewModel.cs" />
    <Compile Include="ViewModelsPerformanceChartViewModel.cs" />
    <Compile Include="ViewModelsProgressViewModel.cs" />
    <Compile Include="ViewsViewBoxTracking.cs" />
    <Compile Include="ViewsMainWindowView.xaml.cs">
      <DependentUpon>MainWindowView.xaml</DependentUpon>
    </Compile>
    <Compile Include="ViewsPerformanceChartView.xaml.cs">
      <DependentUpon>PerformanceChartView.xaml</DependentUpon>
    </Compile>
    <Compile Include="ViewsProgressView.xaml.cs">
      <DependentUpon>ProgressView.xaml</DependentUpon>
    </Compile>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Bootstrapper.cs" />
    <Compile Include="PropertiesAssemblyInfo.cs">
      <SubType>Code</SubType>
    </Compile>
    <Compile Include="PropertiesResources.Designer.cs">
      <AutoGen>True</AutoGen>
      <DesignTime>True</DesignTime>
      <DependentUpon>Resources.resx</DependentUpon>
    </Compile>
    <Compile Include="PropertiesSettings.Designer.cs">
      <AutoGen>True</AutoGen>
      <DependentUpon>Settings.settings</DependentUpon>
      <DesignTimeSharedInput>True</DesignTimeSharedInput>
    </Compile>
    <EmbeddedResource Include="PropertiesResources.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
    </EmbeddedResource>
    <AdditionalFiles Include="....Settings.stylecop">
      <Link>Settings.stylecop</Link>
    </AdditionalFiles>
    <None Include="packages.config" />
    <None Include="PropertiesSettings.settings">
      <Generator>SettingsSingleFileGenerator</Generator>
      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
    </None>
  </ItemGroup>
  <ItemGroup>
    <None Include="App.config" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..Thinning.AlgorithmThinning.Algorithm.csproj">
      <Project>{9bfb384e-ca70-407a-9e0e-b9ac235ed7d6}</Project>
      <Name>Thinning.Algorithm</Name>
    </ProjectReference>
    <ProjectReference Include="..Thinning.InfrastructureThinning.Infrastructure.csproj">
      <Project>{19B5AECE-CCE3-4312-AB19-D190AF1A1441}</Project>
      <Name>Thinning.Infrastructure</Name>
    </ProjectReference>
  </ItemGroup>
  <ItemGroup>
    <Page Include="ViewsMainWindowView.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="ViewsPerformanceChartView.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
    <Page Include="ViewsProgressView.xaml">
      <SubType>Designer</SubType>
      <Generator>MSBuild:Compile</Generator>
    </Page>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
</Project>

我有一个WPF项目。它具有使用.Net Framework 4.7.2编写的三个库。我正在尝试为该解决方案还原nuget程序包,但我不能。当我右键单击sln文件时,然后选择Restore ...

答案

有两种方法来管理nuget软件包:Packages.configPackageReference

以上是关于框架4.7.2中的无法还原nuget软件包的主要内容,如果未能解决你的问题,请参考以下文章

Nuget表示缺少软件包,Package Manager Restore表示已安装所有软件包

NuGet 还原无法看到未安装包

NuGet 安装中的框架版本不兼容

NuGet 锁定文件无法使用 --locked-mode 还原

NuGet 包安装失败“包还原失败。回滚 <xamarin.android> 的包更改”

Azure 构建管道 NuGet 还原错误 NETSDK1045