简体   繁体   中英

Nuget doesn't restore packages for solution, but works when executed for .csproj

I've got a legacy project with a somehow faulty configuration for the used nuget packages.

When I try to restore packages with the solution (.sln) the restore doesn't restore anything. Also, the nuget package manager shows no installed packages for the solution. What I tried:

nuget restore the_solution.sln -MSBuildPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" -Verbosity detailed -ConfigFile "C:\Users\jenkins\AppData\Roaming\NuGet\NuGet.Config"

But when I restore the packages for each project (.csproj) the restore works fine and the project can be built. The command I call for the project restore is:

nuget restore path_to_project\packages.config -MSBuildPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" -Verbosity detailed  -OutputDirectory "Packages" -ConfigFile "C:\Users\jenkins\AppData\Roaming\NuGet\NuGet.Config"

The packages config for each .csproj looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Autofac" version="4.7.0" targetFramework="net461" />
  <!- many other packages -->
</packages>

The .csproj file looks like this:

  <ItemGroup>
    <Reference Include="Autofac, Version=4.7.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
      <HintPath>..\packages\Autofac.4.7.0\lib\net45\Autofac.dll</HintPath>
    </Reference>
<!- many other packages -->

The RestoreProject Style in the .csproj is set to:

  <PropertyGroup>
      <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>

I have no clue, why I can't use the .sln file for the nuget restore. So, any hint what might causes the error is highly appreciated.

You are using packages in old packages.config format, but restore is set to new packageReference format. Try to remove this line from csproj file

<PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

and run restore again at solution level

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM