NuGet 不会从包中解压程序集

NuGet does not unpack assemblies from package

环境:VS Enterprise 2015 Update 1,程序包管理器控制台主机版本 3.3.0.167

重现步骤:只需创建一个针对 .Net 4.5.2 的新项目(例如控制台应用程序)(但也尝试使用其他 .net 版本)。

当我安装一个 nuget 包时,该包被下载并且安装似乎没有错误。但是,nuget 不会添加对 dll 的引用。查看 packages 文件夹时,发现没有解压的 .dll,尽管 .nupkg 文件在那里并且没有损坏(我可以使用 nuget 包资源管理器打开它并查看 lib 文件夹的内容)。

知道是什么原因造成的吗?

包管理器控制台中的输出:

PM> install-package log4net -verbose
  Attempting to gather dependencies information for package 'log4net.2.0.5' with respect to project 'ConsoleApplication4', targeting '.NETFramework,Version=v4.5.2'
  Attempting to resolve dependencies for package 'log4net.2.0.5' with DependencyBehavior 'Lowest'
  Resolving actions to install package 'log4net.2.0.5'
  Resolved actions to install package 'log4net.2.0.5'
  For adding package 'log4net.2.0.5' to project 'ConsoleApplication4' that targets 'net452'.
  For adding package 'log4net.2.0.5' to project 'ConsoleApplication4' that targets 'net452'.
  Adding package 'log4net.2.0.5' to folder 'c:\Projects\ConsoleApplication4\packages'
  Added package 'log4net.2.0.5' to folder 'c:\Projects\ConsoleApplication4\packages'
  Added package 'log4net.2.0.5' to 'packages.config'
  Added file 'packages.config' to project 'ConsoleApplication4'.
  Successfully installed 'log4net 2.0.5' to ConsoleApplication4

包文件夹内容:

C:\Projects\ConsoleApplication4\packages\log4net.2.0.5>tree /f .
Folder PATH listing for volume OSDisk
Volume serial number is 8CE4-F2E5
C:\PROJECTS\CONSOLEAPPLICATION4\PACKAGES\LOG4NET.2.0.5
¦   log4net.2.0.5.nupkg
¦
+---lib
    +---net10-full
    ¦       log4net.xml
    ¦
    +---net11-full
    ¦       log4net.xml
    ¦
    +---net20-full
    ¦       log4net.xml
    ¦
    +---net35-client
    ¦       log4net.xml
    ¦
    +---net35-full
    ¦       log4net.xml
    ¦
    +---net40-client
    ¦       log4net.xml
    ¦
    +---net40-full
    ¦       log4net.xml
    ¦
    +---net45-full
            log4net.xml

更新:发生在一些,但不是所有的 nuget 包中

此页面上概述的解决方法似乎有效 - https://connect.microsoft.com/VisualStudio/feedback/details/1656768/installing-certain-nuget-packages-fails-to-actually-extract-the-dll-files-to-the-relevant-lib-folder-and-fails-to-add-an-assembly-reference-to-the-csproj-file

Posted by Miles Rush on 11/25/2015 at 12:16 PM

Just fixed this on my > system. Went in to the user profile NuGet cache (C:\Users\.nuget\packages), and deleted everything in there. I think during the restore process my cache was cleared of all DLL files, and when I tried to install a package it was using the cache instead of the files off of NuGet. Now that I've cleared the cache, I can now install the NuGet packages.

我刚遇到这个问题 (VS2017 Enterprise),虽然上面的答案没有解决问题,但删除了解决方案的包文件夹中的所有内容。

在我们的构建代理上有类似的行为。原因:.nupkg 文件已添加到存储库! 在这种情况下,nuget 假定包已经存在并且不会解压 .nupkg 文件。

已从存储库中删除文件,构建已通过。