2

Closed

NuGet package restore unnecessary error for project that does not have a .sln file

description

Repro steps:
  1. open attached project in visual studio, which does not have a .sln file on disk, also no packages installed.
  2. build project
Expected: no package restore error is shown on output pane.


Actual: below error is shown on output pane.




Error occurred while restoring NuGet packages: System.ArgumentException: The path is not of a legal form.
at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
at System.IO.Path.GetDirectoryName(String path)
at NuGet.VisualStudio.VsUtility.GetNuGetSolutionFolder(Solution solution)
at NuGet.VsEvents.PackageRestorer.UsingOldPackageRestore(Solution solution)
at NuGet.VsEvents.PackageRestorer.BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action).
1>------ Build started: Project: NugetSetup, Configuration: Debug Any CPU ------
1> NugetSetup -> C:\school\NugetsetupTest\bin\Debug\NugetSetupTest.dll
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

file attachments

Closed Dec 18, 2013 at 10:47 PM by danliu
verified using latest 2.8 VSIX.

Please note that NuGet requires the existence of the .sln file in order to perform package operations.

After the fix, the experience is like this:

The error below is given on output pane, and the build will continue. After click SaveAll button, the .sln file will be saved to disk. Then automatic package restore will work during build.

"Error occurred while restoring NuGet packages: Unable to locate the solution directory. Please ensure that the solution has been saved."

comments

Ncage1974 wrote Sep 10, 2013 at 1:21 PM

We are getting the same error too. We have a standard of not checking our solution files in so we are getting this error on almost every project.

deepakverma wrote Sep 30, 2013 at 5:47 PM

workaround for now is to add a sln file.

feiling wrote Oct 1, 2013 at 8:23 PM

Another workaround is to disable automatic package restore. In VS, go to Options -> PackageManager -> General, uncheck "Automatically check for missing packages during build in Visual Studio"

mtrigoboff wrote Nov 18, 2013 at 9:49 PM

I just tried the workaround of unchecking the item in the Package Manager. It didn’t work. I’m still getting the error message on a project that does not contain a .sln file.

danliu wrote Dec 13, 2013 at 9:20 PM

@mtrigoboff, did you restart VS after unchecking the option?

danliu wrote Dec 13, 2013 at 9:31 PM

reactivate this bug.

Here is what I see now using latest 2.8 build. Suggest to locate the packages.config and then perform restore, instead of forcing users to save the .sln.


Error occurred while restoring NuGet packages: System.InvalidOperationException: Unable to locate the solution directory. Please ensure that the solution has been saved.
at NuGet.VisualStudio.RepositorySettings.GetRepositoryPath()
at NuGet.VisualStudio.RepositorySettings.get_RepositoryPath()
at NuGet.VsEvents.PackageRestorer.PackageRestore(Solution solution)
at NuGet.VsEvents.PackageRestorer.RestorePackages()
at NuGet.VsEvents.PackageRestorer.RestorePackagesOrCheckForMissingPackages()
at NuGet.VsEvents.PackageRestorer.BuildEvents_OnBuildBegin(vsBuildScope Scope, vsBuildAction Action).
========== Build: 0 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

danliu wrote Dec 13, 2013 at 10:46 PM

The version of VS used for repro is 2013.

mtrigoboff wrote Dec 14, 2013 at 1:25 AM

I don’t remember if I restarted VS back then.

But I just opened a project without a .sln file, and I got the same error when I tried to build it.

I looked at the options and I had already unchecked “Automatically check…” I still had “Allow NuGet to download…” checked. I tried unchecking the “Allow…” checkbox, but it still gave me the same error, even after restarting VS.

mtrigoboff wrote Dec 14, 2013 at 1:44 AM

I used VS 2012 just now. Let me know if you need me to try it with VS 2013, which I am in the process of downloading.