.net Nuget包安装失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34991703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:45:23  来源:igfitidea点击:

Nuget package installation failure

.netnuget

提问by MrBliz

When trying to install a package from our newly created private Nuget Feed i get the following error.

尝试从我们新创建的私有 Nuget Feed 安装软件包时,出现以下错误。

Could not install package 'GC.Timecode 1.0.0.3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework.

无法安装包“GC.Timecode 1.0.0.3”。您正在尝试将此包安装到以“.NETFramework,Version=v4.5.1”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。

The Nuget package also targets 4.5.1. (Screenshot take from Nuget Package Explorer)

Nuget 包也面向 4.5.1。(截图来自 Nuget Package Explorer)

The Nuget Package is created by Octopack via On premises TFS, and then published to a private Proget Server

Nuget 包由 Octopack 通过本地 TFS 创建,然后发布到私有 Proget 服务器

enter image description here

在此处输入图片说明

Nuspec file looks like this

Nuspec 文件看起来像这样

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>GC.Timecode</id>
<version>1.0.0.3</version>
<authors>user</authors>
<owners>user</owners>
<licenseUrl>http://example.com</licenseUrl>
<projectUrl>http://example.com</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>The GC.Timecode deployment package, built on 25/01/2016</description>
<releaseNotes />
</metadata>
</package>

Contents of Package

包装内容

enter image description here

在此处输入图片说明

What's going on here?

这里发生了什么?

采纳答案by MrBliz

The problem was that Octopack will by default just replicate the existing folder structure, whereas Nuget will package your dll into a lib folder.

问题是 Octopack 默认只会复制现有的文件夹结构,而 Nuget 会将您的 dll 打包到 lib 文件夹中。

For the lazy, you can use this package in order to Get a nuget package built on every build

对于懒惰的人,您可以使用此包来获取在每个构建上构建的 nuget 包

https://www.nuget.org/packages/CreateNewNuGetPackageFromProjectAfterEachBuild/

https://www.nuget.org/packages/CreateNewNuGetPackageFromProjectAfterEachBuild/

回答by Tim Hobbs

Slippery Pete fixed this problem for me.

Slippery Pete 为我解决了这个问题。

The first time I tried to install my Assembly I got:

我第一次尝试安装我的程序集时得到:

Could not install package 'Package Name'. You are trying to install this >package into a project that targets '.NETFramework,Version=v4.6.1', but the >package does not contain any assembly references or content files that are >compatible with that framework. For more information, contact the package >author.

无法安装软件包“软件包名称”。您正在尝试将此 > 包安装到以“.NETFramework,Version=v4.6.1”为目标的项目中,但该 > 包不包含与该框架 > 兼容的任何程序集引用或内容文件。有关更多信息,请联系包>作者。

After ensuring my Assembly within the Nuget package was in the 'lib\net45' folder, I still got the error!

在确保 Nuget 包中的程序集位于“lib\net45”文件夹中后,我仍然收到错误消息!

However after going to Tools->Options->Nuget->General and clearing the cache, the problem was solved.

但是在转到工具->选项-> Nuget->常规并清除缓存后,问题就解决了。

回答by Kris

Make sure your nuspec file contains a 'lib/net45' target

确保您的 nuspec 文件包含“lib/net45”目标

<package>
  <metadata>
    ...
  </metadata>
  <files>
    <file src="bin\Release\*.*" target="lib/net45" />
  </files>
</package>

回答by Slippery Pete

This happened to me and I didn't find my solution posted to any of these sites, so hopefully this helps someone else.

这发生在我身上,我没有找到发布到任何这些网站的解决方案,所以希望这可以帮助其他人。

The message I was getting was:

我得到的消息是:

Could not install package 'Package Name'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

无法安装软件包“软件包名称”。您正在尝试将此包安装到以“.NETFramework,Version=v4.6.1”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。有关更多信息,请联系软件包作者。

I had a Nuget package that was built for all 4.x versions so it shouldn't matter that it didn't specify version 4.6.1 specifically. I tried changing the class library build to 4.0, 4.5, 4.5.2, 4.6, 4.6.1, and 4.6.2 but nothing fixed this problem. I also added multiple versions of the DLL to the package in individual /lib/Net4(5,51,52,6,61,62) folders and the error was still there.

我有一个为所有 4.x 版本构建的 Nuget 包,所以它没有特别指定版本 4.6.1 应该无关紧要。我尝试将类库构建更改为 4.0、4.5、4.5.2、4.6、4.6.1 和 4.6.2,但没有解决此问题。我还在单独的 /lib/Net4(5,51,52,6,61,62) 文件夹中将多个版本的 DLL 添加到包中,但错误仍然存​​在。

Eventually, I found out the reason for my problem was the initial private Nuget package I created was a "bad" package and that bad package was cached to my local machine.

最终,我发现我的问题的原因是我创建的初始私有 Nuget 包是一个“坏”包,而这个坏包被缓存到我的本地机器上。

I fixed the package problem and pushed the new package to our Nuget server (leaving the version name the same), but Nuget inside Visual Studio wasn't pulling down the new package but instead referenced the bad package cached on my local machine at. Package Manager showed the package was updated and displayed the information correctly from our Nuget server but it was never fetching the new package. It was always retrieving the cached package at:

我修复了包问题并将新包推送到我们的 Nuget 服务器(保留版本名称相同),但 Visual Studio 中的 Nuget 并没有拉下新包,而是引用了我本地机器上缓存的坏包。包管理器显示包已更新并从我们的 Nuget 服务器正确显示信息,但它从未获取新包。它总是在以下位置检索缓存的包:

C:\Users\your_user_account\.Nuget\packages\

C:\Users\your_user_account\.Nuget\packages\

Simply deleting the package in question under your local user account forced Package Manager to pull down the new package from the server.

只需删除本地用户帐户下的相关包,包管理器就会从服务器上拉下新包。

回答by Rob

If you're using nuspec make sure that all installed packages are noted as "dependencies" in the metadata.

如果您使用 nuspec,请确保所有已安装的软件包在元数据中都标记为“依赖项”。

<dependencies>
      <dependency id="MyIncludedPackage" version="1.13.0" />
    </dependencies>
  </metadata>

Adding all the packages solved this issue for me.

添加所有软件包为我解决了这个问题。

回答by Onin

I was also getting the following message.

我也收到了以下消息。

Could not install package 'Package Name'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

无法安装软件包“软件包名称”。您正在尝试将此包安装到以“.NETFramework,Version=v4.6.1”为目标的项目中,但该包不包含任何与该框架兼容的程序集引用或内容文件。有关更多信息,请联系软件包作者。

In my case, changing the package management format from packages.config to PackageReferencesolved the problem.

就我而言,将包管理格式从 packages.config 更改为 PackageReference解决了该问题。

回答by UuDdLrLrSs

Another possibility which I just worked through was that local Nuget tools can be too old.

我刚刚解决的另一种可能性是本地 Nuget 工具可能太旧了

I was trying to install https://github.com/alastairtree/LazyCachewhich is a .Net standard 2.0 project. My local project was .NET framework 4.7.2, which iscompatible. And yet I got the error cited in the question.

我试图安装https://github.com/alastairtree/LazyCache,这是一个 .Net 标准 2.0 项目。我的本地项目是 .NET framework 4.7.2,它兼容的。然而我得到了问题中引用的错误。

The problem was that my VS2015 installation of Nuget was not the latest. Although under Tools > Extensions it did NOT show any available updates, there was in fact a much newer Nuget available at https://www.nuget.org/downloads(3.6x vs 3.4x I believe).

问题是我的 VS2015 安装的 Nuget 不是最新的。尽管在 Tools > Extensions 下它没有显示任何可用更新,但实际上在https://www.nuget.org/downloads 上有一个更新的 Nuget 可用(我相信是 3.6x vs 3.4x)。

I installed that and the problem was resolved. Apparently the old Nuget did not understand what .NET Standard was.

我安装了它,问题解决了。显然,旧的 Nuget 不明白 .NET Standard 是什么。