简体   繁体   English

Nuget软件包未添加软件包参考

[英]Nuget-package not adding package reference

I am trying to install MySql.Data and MySql.Data.Entity to my class lib. 我正在尝试将MySql.DataMySql.Data.Entity安装到我的类库中。

Somehow there is no reference added to the project. 不知何故没有向项目添加参考。

Things I've tried: 我尝试过的事情:

  1. Update-Package -reinstall (does not help) Update-Package -reinstall (无济于事)
  2. packages.config contains the correct entries packages.config包含正确的条目
  3. *.csproj also has the correct entries *.csproj也具有正确的条目
  4. Cleared NuGet-Cache 已清除NuGet缓存

This is the output: 这是输出:

Package 'MySql.Data.6.10.6' already exists in folder 
'C:\Users\MYUSERNAME\Documents\Repositories\XXXXXXX\packages'
Added package 'MySql.Data.6.10.6' to 'packages.config'
Successfully installed 'MySql.Data 6.10.6' to XXXXXXXX.Persistence
Executing nuget actions took 1,6 sec

在此处输入图片说明

Strange thing is that NuGet creates that \\docs in my project which is part of MySql 奇怪的是, NuGet在我的项目中创建了\\docs ,这是MySql一部分

Nuget-package not adding package reference Nuget软件包未添加软件包参考

I agree with Matt`s comment. 我同意马特的评论。 You project targets framework should be .NET 4.5.1 or below. 您的项目目标框架应为.NET 4.5.1或更低版本。 Because the package MySql.Data only contain assembly reference to .NET framework 4.5.2 for .NET framework: 因为包MySql.Data 包含对.NET Framework的.NET Framework 4.5.2的程序集引用,所以:

在此处输入图片说明

However, this package also have the content files, which are compatible with .net framework. 但是,此程序包还具有与.net框架兼容的内容文件。 So when you add this package to the project(target framework 4.5.1 or below), nuget will install this nuget package without any error, just add the content file ( \\docs ) but not add any reference to the project . 因此,当您将此软件包添加到项目(目标框架4.5.1或更低版本)时,nuget会安装此nuget软件包而不会出现任何错误, 只需添加内容文件( \\docs ),而不添加对项目的任何引用

To resolve this issue, you can change the target framework to 4.5.2 and above of this project or you should use the nuget package MySql.Data with the version 6.9.11 , which contain assembly reference to .NET framework 4.0 and 4.5 : 要解决此问题,可以将目标框架更改为该项目的4.5.2及更高版本,或者应使用版本为6.9.11的nuget包MySql.Data ,其中包含对.NET Framework 4.0和4.5的程序集引用:

在此处输入图片说明

Note: If you change the target framework to the .net framework 4.5.2 and above, you may get the error " The package 'MySql.Data' tried to add a framework reference to 'System.ComponentModel' which was not found in the GAC. ", please add a manually reference to missed library: 注意:如果将目标框架更改为.net Framework 4.5.2及更高版本,则可能会收到错误“ The package 'MySql.Data' tried to add a framework reference to 'System.ComponentModel' which was not found in the GAC. ”,请为缺少的库添加手动引用:

Package tried to add reference to System.Runtime which was not found in the GAC 程序包尝试添加对GAC中找不到的System.Runtime的引用

Hope this helps. 希望这可以帮助。

I experienced this problem even though I had the correct Framework. 即使我有正确的框架,我也遇到了这个问题。 It was solved by Migrating the Nuget Format to Package References 通过将Nuget格式迁移到程序包引用可以解决此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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