NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

Exception on package restore during build (project.json/vcxproj) #6259

Open iskiselev opened 6 years ago

iskiselev commented 6 years ago

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): VS UI NuGet version (x.x.x.xxx): 4.5.0 VS version (if appropriate): 15.5.0 OS version (i.e. win10 v1607 (14393.321)): win 10 v 1709 (16299.64) Worked before? If so, with which NuGet version: No

Detailed repro steps so we can see the same problem

When non-standart platform is used in vcxproj with project.json, Nuget crash throws exception on build:

Error occurred while restoring NuGet packages: System.IO.InvalidDataException: The BaseIntermediateOutputPath MSBuild property could not be found for project 'C:\projects\tmp\TestApp\ConsoleApplication1\ConsoleApplication1.vcxproj'.
   at NuGet.PackageManagement.VisualStudio.VsProjectJsonNuGetProject.<GetBaseIntermediatePathAsync>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 NuGet.ProjectManagement.Projects.ProjectJsonNuGetProject.<GetPackageSpecsAsync>d__15.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.<GetSolutionRestoreSpec>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.SolutionRestoreManager.SolutionRestoreJob.<RestorePackageSpecProjectsAsync>d__18.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.SolutionRestoreManager.SolutionRestoreJob.<RestoreAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at NuGet.SolutionRestoreManager.SolutionRestoreJob.<RestoreAsync>d__16.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.SolutionRestoreManager.SolutionRestoreJob.<ExecuteAsync>d__15.MoveNext()

Any project (PackageReference/projec.json based) that should be restored after exception are not restored.

Sample Project

https://github.com/iskiselev/NuGetIssueExample Problem is reproducible on AnyCPU build. A little background information: I'm trying to create CPP project with both x86/x64 compilation on same build. Additional notice: When this config loaded, if Solution Explorer switched to "Show All Files", it shows root of drive instead.

jainaashish commented 6 years ago

I looked in to your sample solution and found that you're using both project.json file and PackageReference in .vcxproj which is not supported. So you should manage all your NuGet dependencies through project.json file.

With only project.json file, I was able to restore via msbuild or VS.

iskiselev commented 6 years ago

Sorry for not fully correct example. I've just updated it - please check it from original repo. Looks like adding to solution any PackageReferencebased project is trigger for a problem. So, I've removed PackageReference from .vcxproj - it now use only project.json, but I've added SDK-based netstandard2.0 library, and problem is reproducible again.

iskiselev commented 6 years ago

BTW, I found that only "Any CPU" platform for .vcxproj results in issue. I've started using "All CPU" platform for .vcxproj and it solved problem for me - but still there is some bug in Nuget/Visual Studio.