I have a PackageReference in my csproj. (XYZ.csproj)
When I try nuget restore XYZ.csproj -MSBuildPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin" everything works fine and the packages are restored.
However if I try nuget restore XYZ.csproj -MSBuildPath "Z:\Microsoft\Current\Bin" (msbuild from a custom path), I get the following error -
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'.
It's the exact same csproj and the exact same version of nuget.exe.
What's happening here?
NuGet product used: NuGet.exe
NuGet version: 5.6.0.6591
dotnet.exe --version: 3.1.101
VS version (if appropriate): NA
OS version: Win10 v1901 (18363.959)
Worked before? If so, with which NuGet version: Not sure.
Copy contents from "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\bin" to "Z:\Microsoft\Current\Bin"
Add a PackageReference in my csproj. (XYZ.csproj)
Run nuget restore XYZ.csproj -MSBuildPath "Z:\Microsoft\Current\Bin"
Z:\dev\git\delpire-ni-analyzers>nuget.exe restore Z:\dev\git\ni-central\src\if_applications\RFmxSFPDistribution\RFmxSFPApplication\RFmxSFPApplication.csproj -MSBuildPath "z:/helix/p4v/Perforce/build/targets/ms/cs/15.0/export/15.0/15.0.0f7/tools/win32/i386/msnet" -verbosity detailed
Using Msbuild from 'z:/helix/p4v/Perforce/build/targets/ms/cs/15.0/export/15.0/15.0.0f7/tools/win32/i386/msnet'.
NuGet Version: 5.6.0.6591
MSBuild P2P timeout [ms]: 120000
z:/helix/p4v/Perforce/build/targets/ms/cs/15.0/export/15.0/15.0.0f7/tools/win32/i386/msnet\msbuild.exe "C:\Users\tsharma\AppData\Local\Temp\NuGetScratch\yew55qev.mih.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\tsharma\AppData\Local\Temp\NuGetScratch\upk4rctp.dmg.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="Z:\dev\git\delpire-ni-analyzers\nuget.exe" /p:RestoreBuildInParallel="False" /p:RestoreUseSkipNonexistentTargets="False"
Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: Z:\dev\git\ni-central\src\if_applications\RFmxSFPDistribution\RFmxSFPApplication\RFmxSFPApplication.csproj.
NuGet.Commands.RestoreSpecException: Invalid restore input. Missing required property 'OutputPath' for project type 'PackageReference'. Input files: Z:\dev\git\ni-central\src\if_applications\RFmxSFPDistribution\RFmxSFPApplication\RFmxSFPApplication.csproj.
at NuGet.Commands.SpecValidationUtility.ValidateProjectSpecPackageReference(PackageSpec spec, IEnumerable`1 files)
at NuGet.Commands.SpecValidationUtility.ValidateProjectSpec(PackageSpec spec)
at NuGet.Commands.SpecValidationUtility.ValidateDependencySpec(DependencyGraphSpec spec, HashSet`1 projectsToSkip)
at NuGet.Commands.DependencyGraphSpecRequestProvider.GetRequestsFromItems(RestoreArgs restoreContext, DependencyGraphSpec dgFile)
at NuGet.Commands.DependencyGraphSpecRequestProvider.CreateRequests(RestoreArgs restoreContext)
at NuGet.Commands.RestoreRunner.<CreatePreLoadedRequests>d__11.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.Commands.RestoreRunner.<GetRequests>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.Commands.RestoreRunner.<RunAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.Commands.RestoreRunner.<RunAsync>d__1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.CommandLine.RestoreCommand.<ExecuteCommandAsync>d__52.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at NuGet.CommandLine.Command.Execute()
at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
NA.
I would also appreciate if there are any workarounds. This is blocking my progress as of now.
/cc @nkolev92 & @zivkan
@tushardevsharma
We need some additional information to understand this issue.
What version of msbuild are you using? Is that a full VS install install or the build tools?
Would you be able to provide a repro?
Have you tried msbuild /t:restore?
What version of msbuild are you using? Is that a full VS install install or the build tools?
I have VS 2017 and VS 2019 Professional installed on my system. I just checked my msbuild versions from the VS developer command prompts and I see msbuild 15.9.21+g9802d43bc3 from VS 2017 cmd prompt and msbuild 16.4.0+e901037fe from VS 2019 cmd prompt.
Would you be able to provide a repro?
nuget.exe 5.6.0.6591 onto Z:\msbuildNuGetRestoreRepro (project zipped & attached) at C:\Users\tsharma\source\repos and added a PackageReference by manually editing the csproj file - <ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118"/>
</ItemGroup>
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin to Z:\msbuild\Bin2017.cmd at Z:\msbuild. Check cmd session here where the error surfaces. Works great when no -MSBuildPath is specified. But fails with the said error when I specify the -MSBuildPath as Z:\msbuild\Bin2017.The exact same thing happens if I try with the VS 2019 msbuild as well.
Have you tried msbuild /t:restore?
I tried that. It did not even seem to restore packages.
@tushardevsharma
The one unusual thing in your set-up is the 3rd step.
When you copy the contents of the msbuild folder, you are copying targets file such as Microsoft.Common.CurrentVersion.targets and those rely on relative paths to work correctly. See https://github.com/dotnet/msbuild/blob/f2c4bfd563f559daca27ea1cd8ae40db24e2e7cd/src/Tasks/Microsoft.Common.CurrentVersion.targets#L6182-L6184.
Works great when no -MSBuildPath is specified. But fails with the said error when I specify the -MSBuildPath as Z:msbuild\Bin2017.
I think my above explanation covers that.
Given that the default works I think you are running into an unsupported scenario.
I tried that. It did not even seem to restore packages.
We need the NuGet.targets to restore, but they don't exist.
@nkolev92
Given that the default works I think you are running into an unsupported scenario.
Okay, I understand. Thanks for the explanation.
Would you kindly suggest a workaround to get this working? I tried copying the NuGet.targets file over to the custom $(MSBuildToolsPath) location (i.e. into Z:\msbuild\Bin2017) but that did not work. Do you suspect a workaround might not be trivial or be even possible?
One more question - so it looks like I need to use the default installation location for nuget restore to work correctly. Is installation of VS build tools sufficient or do I need to have the full VS installed?
so it looks like I need to use the default installation location for nuget restore to work correctly.
Technically NuGet needs a "working msbuild", which is not just msbuild.exe, but also all the props and targets file that it, and NuGet, ships. It doesn't have to be in a default location, but it has to evaluate all the expected properties and items that get evaluated in an official installation.
Is installation of VS build tools sufficient or do I need to have the full VS installed?
Yes it's sufficient. It's what is expected to be installed on CI machines, so a full Visual Studio install is not needed. For what it's worth, https://visualstudio.microsoft.com/downloads/ has a description for "Build Tools for Visual Studio 2019" that says: These Build Tools allow you to build Visual Studio projects from a command-line interface.
Would you kindly suggest a workaround to get this working?
I don't speak for the entire team, but my position is that this is too far outside the NuGet team's area of ownership. If you wish to continue your path of manually copying msbuild, I'd ask github.com/dotnet/msbuild.
If you wish to investigate yourself, the two most useful tips I have are:
-bl option with MSBuild to generate a msbuild.binlog file that you can open with the MSBuild Binary and Structured Log Viewer. For example msbuild -t:restore -bl.-pp option with MSBuild to generate an MSBuild project file with all imports expanded. For example msbuild -pp:pp.txt my.csproj, then open pp.txt in your favourite text/xml editor.Although I guess that the only reason you were trying this was to avoid a large VS install, which the build tools gives you, so you probably don't need to continue down this path of trying to copy msbuild manually.
Most helpful comment
Technically NuGet needs a "working msbuild", which is not just msbuild.exe, but also all the props and targets file that it, and NuGet, ships. It doesn't have to be in a default location, but it has to evaluate all the expected properties and items that get evaluated in an official installation.
Yes it's sufficient. It's what is expected to be installed on CI machines, so a full Visual Studio install is not needed. For what it's worth, https://visualstudio.microsoft.com/downloads/ has a description for "Build Tools for Visual Studio 2019" that says: These Build Tools allow you to build Visual Studio projects from a command-line interface.
I don't speak for the entire team, but my position is that this is too far outside the NuGet team's area of ownership. If you wish to continue your path of manually copying msbuild, I'd ask github.com/dotnet/msbuild.
If you wish to investigate yourself, the two most useful tips I have are:
-bloption with MSBuild to generate amsbuild.binlogfile that you can open with the MSBuild Binary and Structured Log Viewer. For examplemsbuild -t:restore -bl.-ppoption with MSBuild to generate an MSBuild project file with all imports expanded. For examplemsbuild -pp:pp.txt my.csproj, then open pp.txt in your favourite text/xml editor.Although I guess that the only reason you were trying this was to avoid a large VS install, which the build tools gives you, so you probably don't need to continue down this path of trying to copy msbuild manually.