1

I have a WPF project. It have three libraries written with .Net Framework 4.7.2. I'm trying to restore nuget packages for this solution but i cant.

When i rightclick on sln file, then choose Restore Nuget Packages everything seems to works fine:

enter image description here

But after i run program, it still missing all references:

enter image description here enter image description here

In every csproj packagaes.config file exist. For example:

<?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> 

My question is, how to restore all nuget packages from this project? I'm working on Visual Studio 2019.

EDIT:

one of my .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>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="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>..\..\packages\Caliburn.Micro.Core.4.0.62-alpha\lib\net45\Caliburn.Micro.Core.dll</HintPath> </Reference> <Reference Include="Caliburn.Micro.Platform, Version=4.0.0.0, Culture=neutral, PublicKeyToken=8e5891231f2ed21f, processorArchitecture=MSIL"> <HintPath>..\..\packages\Caliburn.Micro.4.0.62-alpha\lib\net45\Caliburn.Micro.Platform.dll</HintPath> </Reference> <Reference Include="LiveCharts, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL"> <HintPath>..\..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll</HintPath> </Reference> <Reference Include="LiveCharts.Wpf, Version=0.9.7.0, Culture=neutral, PublicKeyToken=0bc1f845d1ebb8df, processorArchitecture=MSIL"> <HintPath>..\..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll</HintPath> </Reference> <Reference Include="MaterialDesignColors, Version=1.2.0.325, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\MaterialDesignColors.1.2.0\lib\net45\MaterialDesignColors.dll</HintPath> </Reference> <Reference Include="MaterialDesignExtensions, Version=2.7.0.0, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\MaterialDesignExtensions.2.7.0\lib\net45\MaterialDesignExtensions.dll</HintPath> </Reference> <Reference Include="MaterialDesignThemes.Wpf, Version=2.6.0.325, Culture=neutral, processorArchitecture=MSIL"> <HintPath>..\..\packages\MaterialDesignThemes.2.6.0\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath> </Reference> <Reference Include="Microsoft.Xaml.Behaviors, Version=1.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> <HintPath>..\..\packages\Microsoft.Xaml.Behaviors.Wpf.1.0.1\lib\net45\Microsoft.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="Helpers\AlgorithmTest.cs" /> <Compile Include="Helpers\CardContent.cs" /> <Compile Include="Helpers\Extensions\SimpleContainerExtension.cs" /> <Compile Include="Helpers\FileDialog.cs" /> <Compile Include="Helpers\Hardware.cs" /> <Compile Include="Helpers\ImageLabelModel.cs" /> <Compile Include="Helpers\Interfaces\IAlgorithmTest.cs" /> <Compile Include="Helpers\Interfaces\ICardContent.cs" /> <Compile Include="Helpers\Interfaces\IFileDialog.cs" /> <Compile Include="Helpers\Interfaces\IHardware.cs" /> <Compile Include="Helpers\Interfaces\IMainWindowViewModelHelper.cs" /> <Compile Include="Helpers\Interfaces\IPerformanceChartViewModelHelper.cs" /> <Compile Include="Helpers\Interfaces\IViewModel.cs" /> <Compile Include="Helpers\MainWindowViewModelHelper.cs" /> <Compile Include="Helpers\PerformanceChartViewModelHelper.cs" /> <Compile Include="ViewModels\MainWindowViewModel.cs" /> <Compile Include="ViewModels\PerformanceChartViewModel.cs" /> <Compile Include="ViewModels\ProgressViewModel.cs" /> <Compile Include="Views\ViewBoxTracking.cs" /> <Compile Include="Views\MainWindowView.xaml.cs"> <DependentUpon>MainWindowView.xaml</DependentUpon> </Compile> <Compile Include="Views\PerformanceChartView.xaml.cs"> <DependentUpon>PerformanceChartView.xaml</DependentUpon> </Compile> <Compile Include="Views\ProgressView.xaml.cs"> <DependentUpon>ProgressView.xaml</DependentUpon> </Compile> </ItemGroup> <ItemGroup> <Compile Include="Bootstrapper.cs" /> <Compile Include="Properties\AssemblyInfo.cs"> <SubType>Code</SubType> </Compile> <Compile Include="Properties\Resources.Designer.cs"> <AutoGen>True</AutoGen> <DesignTime>True</DesignTime> <DependentUpon>Resources.resx</DependentUpon> </Compile> <Compile Include="Properties\Settings.Designer.cs"> <AutoGen>True</AutoGen> <DependentUpon>Settings.settings</DependentUpon> <DesignTimeSharedInput>True</DesignTimeSharedInput> </Compile> <EmbeddedResource Include="Properties\Resources.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="Properties\Settings.settings"> <Generator>SettingsSingleFileGenerator</Generator> <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> </ItemGroup> <ItemGroup> <None Include="App.config" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\Thinning.Algorithm\Thinning.Algorithm.csproj"> <Project>{9bfb384e-ca70-407a-9e0e-b9ac235ed7d6}</Project> <Name>Thinning.Algorithm</Name> </ProjectReference> <ProjectReference Include="..\Thinning.Infrastructure\Thinning.Infrastructure.csproj"> <Project>{19B5AECE-CCE3-4312-AB19-D190AF1A1441}</Project> <Name>Thinning.Infrastructure</Name> </ProjectReference> </ItemGroup> <ItemGroup> <Page Include="Views\MainWindowView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="Views\PerformanceChartView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> <Page Include="Views\ProgressView.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> 
5
  • 1
    I assume this issue occurs when you use both packages.config and PackageReference in same project, which mess up the restore process. To work around it, just edit your project file to only use one format. Commented Feb 6, 2020 at 10:56
  • Hi friend, is there any update for this issue? Maybe you can try deleting the .vs folder in solution directory and reload the project if it persists. Commented Feb 15, 2020 at 14:52
  • @LanceLi-MSFT thanks for your attention, i didnt checked it yet because its my personal project and i do other things right now but i will back to it soon and if your answer will work i will mark your answer as goof one (i already upvoted it) Commented Feb 17, 2020 at 7:28
  • 1
    Sure, feel free to let me know if there's any update. And in my opinion, when one old project's settings are messed up, another direction is to create a new one and move the source files there. Commented Feb 26, 2020 at 10:28
  • I remember, i just dont have much time to investigate the problem Commented Feb 26, 2020 at 18:46

1 Answer 1

4

There're two ways to manage nuget packages: Packages.config and PackageReference.

According to your pic we can see that you used both these two formats in your project, which is cause of the unknown restore issue.

enter image description here

(Yellow ones indicate Packages.config while blue one is PackageReference format)

We shouldn't use both formats in one project, so the workaround for your issue is to force your project to only use one format. Since your three projects all use packages.config, you can consider removing the PackageReference definitions in your project file.

Workaround:

Edit your project file and delete the definitions like <PackageReference Include="StyleCop.Analyzers">xxx</PackageReference> and <RestoreProjectStyle>PackageReference</RestoreProjectStyle> if they exist.

Sign up to request clarification or add additional context in comments.

2 Comments

I deleted pakcages.confid, deleted Include... from .csproj and still its not restoring nugets. I edited my answer with my example csproj
A temporary workaround is to download the nuget.exe manually, add it to System Path variable and use nuget restore command with packages.config file to restore packages. Not a good idea, but for temporary usage, you can give it a try. Confused about why the issue persists after the answer above, please check which format if now you consume a new package in your current project! I want to know how VS IDE now recognize your project, Packages.config or PackageReference?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.