7
votes

We have an existing .NET Solution with a lot of projects. I've recently added a new ASP.NET core project to the solution. When I try to add a Nuget package to the solution, the add fails and I get the following error in the Package Manager output window. If I create a new solution and add the same project to the solution then I'm able to add Nuget packages so it seems to be an issue with adding new .NET core projects to an existing solution. Can anyone help me get past this without needing to recreate the solution?

System.ArgumentException: '$(NETStandardImplicitPackageVersion)' is not a valid version string. at NuGet.Versioning.VersionRange.Parse(String value, Boolean allowFloating) at
NuGet.PackageManagement.VisualStudio.VsManagedLanguagesProjectSystemServices.ToPackageLibraryDependency(PackageReference reference) at System.Linq.Enumerable.WhereSelectEnumerableIterator2.MoveNext()
at System.Collections.Generic.List
1..ctor(IEnumerable1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable
1 source) at NuGet.PackageManagement.VisualStudio.VsManagedLanguagesProjectSystemServices.d__23.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at NuGet.PackageManagement.VisualStudio.LegacyPackageReferenceProject.d__27.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.VisualStudio.LegacyPackageReferenceProject.d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.DependencyGraphRestoreUtility.d__6.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at NuGet.PackageManagement.DependencyGraphRestoreUtility.d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at NuGet.PackageManagement.NuGetPackageManager.d__75.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)

1
Well.. while trying to rebuild my solution, I've narrowed it down to a specific project. I have a standard c# console project that has references to both .NET standard 1 and .NET standard 2. If I remove this project from the solution then I can add nuget packages to the asp.net core project. I'm adding this as a comment in hopes that somone will be able to explain what's happening. If there are no replies then I'll add this as an answer so hopefully I can help anyone else that runs into this issue.Buddy J
This occurs if you haven't installed NET Standard SDKs in you machine. You can verify if your SDKs are available by right clicking on the relevant project, then go to Properties. Then under Application tab, check whether you can see .NET Standard <version> under Target framework. If it's not found you have to install NET Standard.Rizan Zaky

1 Answers

3
votes

Not sure if this is the same issue as the one I encountered, but, for me, what fixed it was making sure the GUIDs I had in my sln file matched.

For example:

Project("{PROJECT-GUID}") = "ProjectA", "ProjectA\ProjectA.csproj", "{GUID-PROJECT-A}"
EndProject
Project("{PROJECT-GUID}") = "ProjectB", "ProjectB\ProjectB.csproj", "{GUID-PROJECT-B}"
EndProject
Project("{SOME-OTHER-GUID}") = "ProjectC", "ProjectC\ProjectC.csproj", "{GUID-PROJECT-C}"
EndProject

I had to replace SOME-OTHER-GUID with PROJECT-GUID.