简体   繁体   English

Visual Studio 2017 无法在 .NET 4.7 项目中安装 nuget 包

[英]Visual Studio 2017 failing to install nuget package in .NET 4.7 project

I'm getting the following error when attempting to install a nuget package into a standard .NET framework 4.7 project:尝试将 nuget 包安装到标准 .NET 框架 4.7 项目时出现以下错误:

The specified path, file name, or both are too long.指定的路径、文件名或两者都太长。 The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.完全限定的文件名必须少于 260 个字符,目录名必须少于 248 个字符。

I'm using Visual Studio 2017 15.3.3 Enterprise (latest and greatest).我使用的是 Visual Studio 2017 15.3.3 Enterprise(最新的和最好的)。

Given that this is my package, I have full control over the source code.鉴于这是我的包,我可以完全控制源代码。 The interesting part is that I have used this package in the past with no changes in the name, but for this go round, I rebuilt it to add a feature and am now getting this error.有趣的是,我过去使用过这个包,名称没有改变,但为此,我重建了它以添加一个功能,现在遇到了这个错误。

Even more interesting is that I have packages from the same library, with the same namespace conventions, with longer names, that work just fine and have installed into this same project with no problems at all.更有趣的是,我有来自同一个库的包,具有相同的命名空间约定,具有更长的名称,它们工作得很好,并且安装到同一个项目中没有任何问题。

I have already tried shrinking the package name, shrinking the class names within the package itself, cleaning out the build directory, cleaning out the package home from the nuget server (it's a local server with the latest nuget.server installed which otherwise works just fine), and even clearing out the bin directory of the project in question, clearing out ALL the bin directories of ALL the ancestors to the "offending" package, clearing out the package cache, rebooting the computer and rebuilding the entire nuget package chain from scratch, all to no avail.我已经尝试缩小包名称,缩小包本身中的类名,清理构建目录,从 nuget 服务器清理包主页(它是安装了最新 nuget.server 的本地服务器,否则工作正常),甚至清除有问题的项目的 bin 目录,清除所有祖先的所有 bin 目录到“违规”包,清除包缓存,重新启动计算机并从头开始重建整个 nuget 包链,都无济于事。 I was told by one of the MS MVP's that "they fixed that".一位 MS MVP 告诉我“他们解决了这个问题”。 Apparently not.显然不是。

Any help would be appreciated here, I'm at my wit's end and have run out of ideas to try.任何帮助将不胜感激,我已经无计可施并且没有任何想法可以尝试。

Thanks.谢谢。

OK, big Thank You @danmosemsft who suggested digging around with the SysInternals process monitor.好的,非常感谢@danmosemsft,他建议使用 SysInternals 进程监视器进行挖掘。 After fiddling with it for a bit, I finally figured out how to narrow the result set to just file activity.在摆弄了一下之后,我终于想出了如何将结果集缩小到仅文件活动。 What I noticed, and the nuget engineers should TAKE NOTE of this: The problem was NOT a too-long project name, rather, nuget was attempting to update a package that was no longer there.我注意到了什么,nuget 工程师应该注意这一点:问题不是太长的项目名称,而是 nuget 试图更新不再存在的包。 Why it went away is a mystery yet to be solved.为什么它消失是一个尚未解开的谜。 I normally stay out of the packages directory and do not fuss with the packages.config file.我通常不在包目录中,也不会对packages.config 文件大惊小怪。 I think that this might have to do with my impatience waiting for VS to start, load all the goodies and then allow me to perform a "Manage NuGet packages" - update all.认为这可能与我不耐烦等待 VS 启动、加载所有好东西然后让我执行“管理 NuGet 包” - 全部更新有关。 I remember seeing an update to either NUnit or FluentAssertions that wanted to perform some additional file activity aside from just installing the next version, a script I believe.我记得看到 NUnit 或 FluentAssertions 的更新,除了只安装下一个版本之外,还想执行一些额外的文件活动,我相信这是一个脚本。 Can't speak to it with assurance, I wasn't paying that much attention as third party updates usually "just work".不能肯定地说,我没有太多关注,因为第三方更新通常“正常工作”。 I didn't see the "finished" line from NuGet so I think that was the root of my problem.我没有看到 NuGet 的“完成”行,所以我认为这是我问题的根源。 Rather than wait until VS has settled down, I pushed it a bit (hey, the buttons responded so there shouldn't be any problems...).我没有等到 VS 稳定下来,而是将它推了一下(嘿,按钮响应了,所以应该没有任何问题......)。

As a result, the packages directory was absolutely chock full of old stuff that did NOT belong there.结果,包目录绝对塞满了不属于那里的旧东西。 So, I manually cleaned up all the cruft, manually cleaned up the packages.config file, restarted VS, waited for it to settle down, performed my NuGet updates and viola!所以,我手动清理了所有的 cruft,手动清理了 packages.config 文件,重新启动了 VS,等待它稳定下来,执行了我的 NuGet 更新和中提琴! no problem - HAVING NOT CHANGED ANY OF THE ANCESTRAL PACKAGE NAMES BY EVEN A SINGLE CHARACTER.没问题 - 甚至一个字符都没有改变任何祖先包的名称。

So, what do I conclude from this?那么,我从中得出什么结论? It is my belief, and the guys that actually build nuget and nuget.server should take a closer look at the errors being thrown, such that I think that the error is not so much a path too long error, rather it's a "hey, I didn't find the file I expected so the file name is full of junk (and probably too long now) so I'll throw an error that says it's too long and quit".这是我的信念,实际构建 nuget 和 nuget.server 的人应该仔细查看抛出的错误,这样我就认为错误不是路径太长的错误,而是“嘿,我没有找到我想要的文件,所以文件名全是垃圾(现在可能太长了),所以我会抛出一个错误,说它太长并退出”。 It's seemingly a failure to handle a missing package/package directory that is causing this particular problem处理导致此特定问题的丢失包/包目录似乎是失败的

I solved my problem by ensuring that all the package directories were clean of all junk and rebuilding from a clean source.我通过确保所有包目录都清除所有垃圾并从干净的源重建来解决我的问题。 My problem is now solved.我的问题现在解决了。

Thanks to all of you that responded.感谢大家的回应。

Update: While the above contributed to the solution, it was NOT the answer.更新:虽然上述内容有助于解决方案,但这不是答案。 Here is the sequence of events that led to this problem and it's ultimate resolution.以下是导致此问题的一系列事件及其最终解决方案。 The solution was created in the C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects directory with the specified name of AWE.Lib.ADO.MsSqlSvr.ServerEntityHandler.该解决方案是在 C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects 目录中创建的,指定名称为 AWE.Lib.ADO.MsSqlSvr.ServerEntityHandler。 This worked just fine, no errors.这工作得很好,没有错误。 However due to a change in naming scheme from on high, the root directory for this project was changed from "C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects" to "C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x".但是由于命名方案自上而下的更改,此项目的根目录从“C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects”更改为“C:\\User\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x”。 No problem, I thought - given that a co-worker who also happens to be a MS MVP had told me that all naming length restrictions had been removed in VS 2017. So...I moved the project from it's current home to the directory specified.没问题,我想 - 鉴于一位恰好也是 MS MVP 的同事告诉我,所有命名长度限制都已在 VS 2017 中删除。所以......我将项目从它当前的家移到了目录指定。 Compiles just fine, brings in UPDATED BUT ALREADY INSTALLED nuget packages just fine, etc.编译得很好,引入更新但已经安装好的 nuget 包,等等。

Or so I thought.或者我是这么想的。 When I needed to add a NEW (one that had not been a part of the solution before) nuget package to the mix, I received the above error.当我需要向混合中添加一个新的(以前不是解决方案的一部分)nuget 包时,我收到了上述错误。 Turns out that the new name of the receiving solution is a few characters longer than VS will accept - the naming length restrictions are STILL IN PLACE.事实证明,接收解决方案的新名称比 VS 接受的字符长几个字符——命名长度限制仍然存在。

How did I finally solve the problem: After struggling with this, I threw my hands up and decided to start all over again - a true File |我是如何最终解决问题的:在为此苦苦挣扎后,我举起了双手,决定从头再来——一个真正的文件 | New.新的。 So, I started with a new solution named as follows: "C:\\Users\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x\\AWE.Lib.ADO.MsSqlSvr.HndlrServerEntity" THIS GENERATES AN ERROR - name too long.所以,我开始使用一个名为如下的新解决方案:“C:\\Users\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x\\AWE.Lib.ADO.MsSqlSvr.HndlrServerEntity”这会产生一个错误 - 名称太长。 I wondered at Nuget's error in that it specifies that the name should be less than 248 characters in length or 260 maximum.我想知道 Nuget 的错误,因为它指定名称的长度应小于 248 个字符或最多 260 个字符。

What I am allowed to use iaw the new solution dialog is this: "C:\\Users\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x\\AWE.Lib.ADO.MsSqlSvr.HndlrServerEnt", for a total of 106 characters in length.我被允许使用新的解决方案对话框是这样的:“C:\\Users\\Sam\\Documents\\Visual Studio 2017\\Projects\\DotNet_4.7\\AWE 8.x\\AWE.Lib.ADO.MsSqlSvr.HndlrServerEnt”,总共 106 个字符的长度。 If the directory is shortened, I can add to the length of the name.如果目录被缩短,我可以增加名称的长度。 If I shorten the length of the actual solution name, again, VS'll accept it.如果我再次缩短实际解决方案名称的长度,VS 会接受它。 So long as the total length of directory plus solution name is less than or equal to 106 characters, there isn't a problem.只要目录加上解决方案名称的总长度小于或等于106个字符,就没有问题。

The nasty bit comes from creating the solution in one location and having it work in all respects just fine, moving said solution to a different directory, still having it function in all respects (I did NOT need to add any new nuget packages yet), then trying to add a new nuget package to the mix after the move.令人讨厌的一点来自于在一个位置创建解决方案并让它在所有方面都正常工作,将所述解决方案移动到不同的目录,仍然在所有方面都能正常工作(我还不需要添加任何新的 nuget 包),然后尝试在移动后向组合中添加一个新的 nuget 包。 THAT is what triggered the above nuget error.这就是触发上述 nuget 错误的原因。

So...the ultimate "fix", use a shorter name as it seems that 106 characters is the limit despite what the error messages are saying (and what the MS MVP was told/told me).所以......最终的“修复”,使用更短的名称,因为尽管错误消息说的是什么(以及MS MVP被告知/告诉我的内容),但似乎106个字符是限制。

There is another reason for this error message by the compiler.编译器出现此错误消息还有另一个原因。 While building , make sure the source code is placed at a folder location which is less than 260 characters long.在构建时,请确保将源代码放置在长度小于 260 个字符的文件夹位置。 For example, a path like C:\\Users\\User\\source\\Services\\Exp\\Sample-web-application-indot-net-displaying-RestAPI\\Sample-web-application-indot-net-displaying-RestAPI\\SportsStore is around 150 characters long but there are sub folders in the solution which in turn have source code files and so on.例如,像C:\\Users\\User\\source\\Services\\Exp\\Sample-web-application-indot-net-displaying-RestAPI\\Sample-web-application-indot-net-displaying-RestAPI\\SportsStore 150 个字符长,但解决方案中有子文件夹,这些子文件夹又包含源代码文件等。 Sometimes the overall length of the path of some files breaches the 260 character length.有时,某些文件的路径总长度会超过 260 个字符的长度。

I think the future versions of Visual Studio would have a bigger length allowance.我认为 Visual Studio 的未来版本会有更大的长度限制。 Until then, we can make sure that our file names are not too long.在此之前,我们可以确保我们的文件名不会太长。

I was running into the same issue after I moved a project to another folder.将项目移动到另一个文件夹后,我遇到了同样的问题。 In my case I closed VS renamed the .vs folder in root to 1.vs (effectively removing it) and re-opend my project.在我的情况下,我关闭了 VS 将根目录中的 .vs 文件夹重命名为 1.vs(有效地将其删除)并重新打开我的项目。

In my case, I was first trying to install a package using Manage Nuget Packages for Solutions and was getting this error.就我而言,我首先尝试使用Manage Nuget Packages for Solutions安装一个包,但遇到了这个错误。 Then I tried installing same package using Package Manager Console and it worked fine.然后我尝试使用Package Manager Console安装相同的包,它工作正常。 I again uninstalled that package and tried installing using Manage Nuget Packages for Solutions and this time it worked fine as well.我再次卸载了该软件包并尝试使用Manage Nuget Packages for Solutions安装,这次它也运行良好。

Well in my experience all i had to do is move the entire project to my c: drive, delete unnecessary folders to ensure the path would be shorter.根据我的经验,我所要做的就是将整个项目移动到我的 c: 驱动器,删除不必要的文件夹以确保路径更短。 Done deal.成交。

This error comes to me when I tried to copy the project folder to OneDrive and the problem is that OneDrive is not uploading long name files.当我尝试将项目文件夹复制到 OneDrive 时出现此错误,问题是 OneDrive 未上传长名称文件。

I've fixed this issue by just copying the project folder then paste it in the new laptop using USB.我通过复制项目文件夹然后使用 USB 将其粘贴到新笔记本电脑中来解决此问题。

I wish this could help我希望这可以帮助

Move the folder of the project to a folder within a few levels from the root dir.将项目的文件夹移动到根目录几级内的文件夹中。 For example the Desktop and voila.例如桌面和瞧。

Try to close Solution from File->Close Solution and opening it again.尝试从File->Close Solution并再次打开它。

For my case uninstalling, installing, or even updating NuGet packages, nothing was working but reopening(sometimes you can also close and open Visual Studio again) the Solution did the magic.对于我卸载、安装甚至更新 NuGet 包的情况,除了重新打开(有时您也可以关闭并再次打开 Visual Studio)外,没有其他任何工作,解决方案发挥了神奇作用。

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

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