Nuget不会还原解决方案的软件包,但在为.csproj

时间:2019-06-06 07:54:27

标签: c# nuget

我有一个旧项目,其中使用的nuget包的配置有某种错误。

当我尝试使用解决方案(.sln)还原软件包时,还原不会还原任何内容。另外,nuget软件包管理器未显示该解决方案的已安装软件包。我尝试过的:

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"

但是,当我为每个项目(.csproj)还原软件包时,还原工作正常并且可以构建该项目。我为项目还原调用的命令是:

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"

每个.csproj的软件包配置如下:

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

.csproj文件如下:

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

.csproj中的RestoreProject样式设置为:

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

我不知道为什么我无法使用.sln文件进行nuget恢复。因此,非常感谢任何可能导致错误的提示。

1 个答案:

答案 0 :(得分:1)

您使用的是旧packages.config格式的软件包,但还原设置为新的packageReference格式。尝试删除此

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

然后在解决方案级别再次运行还原