Closed devlead closed 1 year ago
@devlead - would love that repro solution, minimal as you can get it. thx.
Repro attached TestSolutionA.zip
λ .\v4.7.1_nuget.exe restore .\TestSolutionA\TestSolution.sln
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
Restoring NuGet package Newtonsoft.Json.12.0.1.
Adding package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
Added package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
Restoring packages for C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\MultiTargetLibrary.csproj...
GET https://api.nuget.org/v3-flatcontainer/system.net.http/index.json
OK https://api.nuget.org/v3-flatcontainer/system.net.http/index.json 617ms
GET https://api.nuget.org/v3-flatcontainer/system.net.http/4.3.3/system.net.http.4.3.3.nupkg
OK https://api.nuget.org/v3-flatcontainer/system.net.http/4.3.3/system.net.http.4.3.3.nupkg 16ms
Installing System.Net.Http 4.3.3.
Committing restore...
Generating MSBuild file C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\obj\MultiTargetLibrary.csproj.nuget.g.props.
Generating MSBuild file C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\obj\MultiTargetLibrary.csproj.nuget.g.targets.
Writing lock file to disk. Path: C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\obj\project.assets.json
Restore completed in 5,01 sec for C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\MultiTargetLibrary.csproj.
NuGet Config files used:
C:\Users\MattiasKarlsson\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\MattiasKarlsson\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
1 package(s) to packages.config projects
1 package(s) to C:\temp\priv\nuget\repro\TestSolutionA\MultiTargetLibrary\MultiTargetLibrary.csproj
λ .\v4.8.1_nuget.exe restore .\TestSolutionA\TestSolution.sln
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'.
C:\temp\priv\nuget\repro\TestSolutionA\TestProjectInstaller\TestProjectInstaller.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
Restoring NuGet package Newtonsoft.Json.12.0.1.
Adding package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
Added package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
NuGet Config files used:
C:\Users\MattiasKarlsson\AppData\Roaming\NuGet\NuGet.Config
C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.Offline.config
Feeds used:
C:\Users\MattiasKarlsson\.nuget\packages\
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installed:
1 package(s) to packages.config projects
λ .\v4.9.3_nuget.exe restore .\TestSolutionA\TestSolution.sln -Verbosity Detailed
NuGet Version: 4.9.3.5777
MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\msbuild.exe "C:\Users\MattiasKarlsson\AppData\Local\Temp\NuGetScratch\ifozcrwc.u1i.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\MattiasKarlsson\AppData\Local\Temp\NuGetScratch\r21mghmk.g1z.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\temp\priv\nuget\repro\v4.9.3_nuget.exe" /p:RestoreSolutionDirectory="C:\temp\priv\nuget\repro\TestSolutionA\\" /p:SolutionDir="C:\temp\priv\nuget\repro\TestSolutionA\\" /p:SolutionName="TestSolution"
C:\temp\priv\nuget\repro\TestSolutionA\TestProjectInstaller\TestProjectInstaller.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.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.<GetDependencyGraphSpecAsync>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.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__47.MoveNext()
WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
Restoring NuGet package Newtonsoft.Json.12.0.1.
Missing C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\newtonsoft.json\12.0.1\newtonsoft.json.12.0.1.nupkg
Adding package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
PackageSignatureVerificationLog: PackageIdentity: Newtonsoft.Json.12.0.1 Source: C:\Users\MattiasKarlsson\.nuget\packages\ PackageSignatureValidity: True
Added package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages'
Added package 'Newtonsoft.Json.12.0.1' to folder 'C:\temp\priv\nuget\repro\TestSolutionA\packages' from source 'C:\Users\MattiasKarlsson\.nuget\packages\'
Interestingly even though it's an failure exit code is still 0
I'd imagine this is a fall out from the perf work with SkipNonExistentTargets.
The issue here is that these projects likely have non-existing imports. Projects like take a toll on the msbuild evaluation and make it significantly slower.
Can you try setting RestoreUseSkipNonexistentTargets="false" ? |
You can do that through https://docs.microsoft.com/en-us/nuget/tools/cli-ref-environment-variables, NUGET_RESTORE_MSBUILD_ARGS or just setting is as a regular MSBuild property.
The reason for the non-zero exit code also seems to be deliberate as the warning indicates:
WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
@nkolev92 yes if I for the above attached repro solution execute
$env:RestoreUseSkipNonexistentTargets='false'
nuget restore .\TestSolution.sln
nuget.exe doesn't produce any warnings and following MSBuild succeeds 👍 , so that sorts the issue, but still feels like a regression.
The reason for the non-zero exit code also seems to be deliberate as the warning indicates:
WARNING: Error reading msbuild project information, ensure that your input solution or project file is > valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
Sure but if you see log above I also get an error
- TestProjectInstaller.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
- NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
- at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.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.<GetDependencyGraphSpecAsync>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.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__47.MoveNext()
Also is there a way to treat warnings as errors? Setting TreatWarningsAsErrors=true
didn't have any affect. A failed restore just means it'll fail later in the build process, I rather when possible fail earlier and not waste build minutes.
I overlooked the full log message, my bad. That probably needs further analysis to understand if we tried to have an exit code of 0 or it was deliberate. The exception suggests maybe that's not the case. //cc @heng-liu
WarningsAsErrors is respected only for the Package Reference based projects. Since all restores are individually run, one failure won't stop the complete operation. Note that most warnings are generated toward the end of the operation so it'd end up running the full restore regardless.
This is certainly a different kind of failure though.
Any update? I have a same issue when building with AppVeyor
Build started
git clone -q --branch=develop https://github.com/d2phap/ImageGlass.git C:\projects\imageglass
git checkout -qf 8e0a114f45f70af6fbb8085c028da3f3ca5938da
cd Source
"ImageGlass/resources.bat"
nuget restore
ImageGlass/resources.bat
MSBuild auto-detection: using msbuild version '16.0.360.33175' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\MSBuild\Current\bin'.
nuget : C:\projects\imageglass\Source\Setup\MSI\ImageGlass\ImageGlass.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
At line:3 char:1
+ nuget restore
+ ~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (C:\projects\ima... 1, position 1.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
@d2phap Refer to https://github.com/NuGet/Home/issues/7796#issuecomment-465369065 for more help. It's a balancing act, we're either fast or we're lax with the msbuild evaluations.
@nkolev92 - this is also apparently ignoring if a project is included in the build configuration or not for a solution. I've got a pair of dtproj files in a solution that are not expected to be built in addition to a web site project thats also should not be getting built, but nuget restore task craps on reading the proj file and doesnt restore and create the project.assets,.json for projects that are in the solution that didn't have any errors.
2019-08-07T16:23:55.3675752Z [command]C:\hostedtoolcache\windows\NuGet\4.9.4\x64\nuget.exe restore D:\a\3\s\Program1\.sln -Verbosity Detailed -NonInteractive -ConfigFile D:\a\3\Nuget\tempNuGet_9201.config
2019-08-07T16:24:25.0813025Z D:\a\3\s\Program1 Integration Services\Program1\ Integration Services.dtproj(3,3): error MSB4067: The element <DeploymentModel> beneath element <Project> is unrecognized.
2019-08-07T16:24:25.0813246Z D:\a\3\s\Program2 Integration Services\Program2 Integration Services.dtproj(3,3): error MSB4067: The element <DeploymentModel> beneath element <Project> is unrecognized.
2019-08-07T16:24:25.0813277Z
2019-08-07T16:24:25.0813344Z NuGet Version: 4.9.4.5839
2019-08-07T16:24:25.0813397Z MSBuild auto-detection: using msbuild version '15.9.21.664' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
2019-08-07T16:24:25.0813481Z WARNING: Project file D:\a\3\s\Program1\DBApp\client cannot be found.
2019-08-07T16:24:25.0813519Z MSBuild P2P timeout [ms]: 120000
2019-08-07T16:24:25.0813603Z C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\vlwntotk.vyj.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\ktckdjxx.vgm.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\4.9.4\x64\nuget.exe" /p:RestoreSolutionDirectory="D:\a\3\s\\" /p:RestoreConfigFile="D:\a\3\Nuget\tempNuGet_9201.config" /p:SolutionDir="D:\a\3\s\\" /p:SolutionName="Program1\"
2019-08-07T16:24:25.0813667Z NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
2019-08-07T16:24:25.0813717Z at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
2019-08-07T16:24:25.0813777Z --- End of stack trace from previous location where exception was thrown ---
2019-08-07T16:24:25.0813815Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2019-08-07T16:24:25.0813856Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2019-08-07T16:24:25.0813914Z at NuGet.CommandLine.RestoreCommand.<GetDependencyGraphSpecAsync>d__52.MoveNext()
2019-08-07T16:24:25.0813953Z --- End of stack trace from previous location where exception was thrown ---
2019-08-07T16:24:25.0813990Z at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
2019-08-07T16:24:25.0814212Z at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
2019-08-07T16:24:25.0814273Z at NuGet.CommandLine.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__47.MoveNext()
2019-08-07T16:24:25.0814551Z WARNING: Error reading msbuild project information, ensure that your input solution or project file is valid. NETCore and UAP projects will be skipped, only packages.config files will be restored.
2019-08-07T16:24:25.0814592Z Restoring NuGet package EntityFramework.6.1.3.
@StingyJack Yeah, that's the same scenario as the OP. Import failure throw a wrench into the MSBuild evaluation.
The same suggestions apply here. You can set the property in a Directory.Build.Props at the root of your repo and it should work.
I forgot to mention that we are using the workaround specified as part of https://github.com/Microsoft/msbuild/issues/2064 and the nuget restore is also ignoring that exclusion attempt. Not sure if that matters but something else to consider when fixing this.
Yesterday we updated our build server and see the error from our nuget restore in SSIS project related builds.
"The element
We updated Visual Studio 2019 from 16.4.4 to 16.5.2. The SSIS extension was updated to Microsoft SQL Server Integration Services Designer Version 15.0.2000.93.
Fortunately this solution doesn't use any nuGet packages. So, the quick solution for us was to simply remove the nuGet restore from this particular build.
Any update?
How to exclude vdproj projects in
msbuild -restore
Setting RestoreUseSkipNonexistentTargets=false before running nuget.exe restore MySolution.sln
with a dtproj
in the sln caused nuget.exe to return a successful exit code (0).
However, after updating Visual Studio 2019 to 16.9, MSBuild version 16.9.0.11203, nuget.exe now returns a non successful exit code (-1).
@soroshsabz, see this issue and comment for workarounds: https://github.com/dotnet/msbuild/issues/2064#issuecomment-315875143
What a mission this issue is, and neither of the workarounds (neither setting environment variable nor having the "after.{solution}.sln.targets" works.
It still keeps failing with
Installer.vdproj(1,1): error
MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
Any suggestions? This is causing my builds to fail... seems it won't cause a failure, as long as at least one other project in the solution was restored successfully. But now that I'm gradually upgrading my projects to .NET 5.0, some of my solutions don't have any projects affected by this restore, and in that case the MSB4025 error causes a non-zero return code and the entire build fails.
I can reproduce the issue on the sample repro attached https://github.com/NuGet/Home/issues/7796#issuecomment-463713760 comment. I learnt from https://github.com/NuGet/NuGet.Client/blob/dev/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets#L251 that if RestoreProjectFilterMode
property is set to inclusionlist
then only the standard MSBuild projects are considered for restore. The following steps resulted in nuget.exe restore
to be successful.
The only downside I see in this approach is there is no warning in the log that says .vdproj
project has been excluded from restore because the extension is not included in the allow list of projects.
I also verified that msbuild /t:restore TestSolutionA\TestSolutionA\TestSolution.sln /p:RestoreProjectFilterMode="inclusionlist"
works successfully.
Is this an acceptable work around? Happy to learn from the feedback and improve the product.
From the data below, it looks like something changed in the MsBuild after 15.9*
versions in the way how it handles RestoreBuildInParallel, RestoreUseSkipNonexistentTargets, ContinueOnError
properties.
nuget.exe version | msbuild.exe version | error raised | Additional environment variables | restore result |
---|---|---|---|---|
4.7.3 | 15.9.21.664 | MsBuild raised errors but returned 0 exit code and hence the restore succeeded. \TestSolutionA-4732017\TestSolutionA\TestProjectInstaller\TestProjectInstaller.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1. C:\Users\kapenaga\Downloads\TestSolutionA-4732017\TestSolutionA\TestProjectInstaller\TestProjectInstaller.vdproj : warning NU1503: Skipping restore for project 'C:\Users\kapenaga\Downloads\TestSolutionA-4732017\TestSolutionA\TestProjectInstaller\TestProjectInstaller.vdproj'. The project file may be invalid or missing targets required for restore. | RestoreBuildInParallel and RestoreUseSkipNonexistentTargets properties set to false through code. ContinueOnError set to "WarnAndContinue" in NuGet.targets file | Success |
4.7.3 | 16.11.2.50704 or 17.2.0.16512 | MsBuild raised error and returned non-zero exit code and hence restore failed with an exception. | RestoreBuildInParallel and RestoreUseSkipNonexistentTargets properties set to false through code. ContinueOnError set to "WarnAndContinue" in NuGet.targets file | Failed |
6.1.0 | 15.9.21.664 | MsBuild raised errors but returned 0 exit code and hence the restore succeeded. | set NUGET_RESTORE_MSBUILD_ARGS=/p:RestoreBuildInParallel="False" /p:RestoreUseSkipNonexistentTargets="False" to match NuGet.exe 4.7.3 version behavior | Success |
6.1.0 | 16.11.2.50704 or 17.2.0.16512 | MsBuild raised error and returned non-zero exit code and hence restore failed with an exception. | set NUGET_RESTORE_MSBUILD_ARGS=/p:RestoreBuildInParallel="False" /p:RestoreUseSkipNonexistentTargets="False" to match NuGet.exe 4.7.3 version behavior | Failed |
6.1.0 | 15.9.21.664 or 16.11.2.50704 or 17.2.0.16512 | MsBuild raised error and returned non-zero exit code and hence restore failed with an exception. | RestoreBuildInParallel and RestoreUseSkipNonexistentTargets properties set to true in NuGet.targets file | Failed |
NuGet 4.7.3 version passes RestoreBuildInParallel, RestoreUseSkipNonexistentTargets
through code is when RestoreBuildInParallel and RestoreUseSkipNonexistentTargets properties set to false
. All the next versions of nuget.exe set these properties only when the toolset version is below 15.5 version.
https://github.com/NuGet/NuGet.Client/compare/release-4.7.3...release-4.8.2
We are leaning towards closing this issue because there is not much we can do on the NuGet side. As per my above comment, it looks like MsBuild version greater than 15.9 started returning a failure exit code which further results in restore failures. Related https://github.com/dotnet/msbuild/issues/2064#issuecomment-1074674458.
FYI.. @marcpopMSFT @dotnet/msbuild team this issue has 23 upvotes from the community and hence @aortiz-msft prioritized this work item for the current sprint. The fix appears to be on the MSBuild side especially https://github.com/dotnet/msbuild/issues/2064. In summary, NuGet.exe
invokes msbuild.exe
during restore
to identify the project references
for a project. As per my analysis https://github.com/NuGet/Home/issues/7796#issuecomment-1076622574, it looks like something changed in msbuild version after 15.9 where msbuild.exe started returning a failure exit code when trying to read project references for a custom project (for example vdproj in this case). This happens even when ContinueOnError
is set to WarnAndContinue
(new behavior after 15.9 version). NuGet raises an exception in this case causing restore failures. I don't have great knowledge about the internals of msbuild but asked a question in https://github.com/dotnet/msbuild/issues/2064#issuecomment-1074674458 comment if we can add SkipUnsupportedProjects
like SkipNonexistentProjects to MSBuild task?
cc @jeffkl @nkolev92
Let's keep this issue open as we continue to follow up with the partner.
I got the same problem over last view days. For the first, only with one pipepline. But since today also with another pipeline. The pipeline worked and then stopped working without any changes made on it. I then deleted many older builds ... and what should I say ... after deleting the old builds, pipeline works well. Is it possible, that there some "leftovers" of earlier builds, that Leasing to this behavior?
I stumbled on this when trying to build a legacy application via AzDO with a custom NuGet feed. Adding a task for NuGet restore
started to cause the build to fail.
Framework 4.8.2 msbuild: 17.4.1
I manually set the NuGet version to 4.7.1 and it worked. While this is not ideal, it did unblock the build.
steps:
- task: NuGetToolInstaller@1
displayName: 'Use NuGet 4.7.1'
inputs:
versionSpec: 4.7.1
running this command produces the same error
dotnet build solution.sln -c Release /p:Platform=x64
but running it without the /p:Platform=x64 like this:
dotnet build solution.sln -c Release
works as expected. This does not make any sense...
Solutions with legacy Visual Studio installer projects ( vdproj) have started failing.
It would seem it doesn't result in a non zero exit code, but also doesn't restore all project properly as we MSBuild later fails with 'project.assets.json' not found. Run a NuGet package restore to generate this file.
Details about Problem
NuGet product used: NuGet.exe
NuGet version (x.x.x.xxx): 4.9.3
Worked before? If so, with which NuGet version: 4.7.1
Detailed repro steps so we can see the same problem
Verbose Logs
TestProjectInstaller\TestProjectInstaller.vdproj(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
Sample Project
Commuting right now, but will see if I can get a minimal repo project.
But the project causing issues has