【问题标题】:Nuget doesn't restore packages for solution, but works when executed for .csprojNuget 不会为解决方案恢复包,但在为 .csproj 执行时有效
【发布时间】:2019-10-21 17:05:29
【问题描述】:

我有一个遗留项目,其使用的 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 还原。因此,非常感谢任何可能导致错误的提示。

【问题讨论】:

    标签: c# msbuild nuget


    【解决方案1】:

    您正在使用旧的 packages.config 格式的包,但恢复设置为新的 packageReference 格式。尝试从csproj 文件中删除这一行

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

    并在解决方案级别再次运行恢复

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      相关资源
      最近更新 更多