After converting a fully working .NET 6 repo to .NET 7 and VS 17.4.2, command line builds started failing with exceptions from NuGet.BuildTasks. This occurs on Windows only, and only within .vcxproj projects. The repo uses Directory.Packages.props global packages. It does not occur if dotnet restore is used (see below), just when restoring with msbuild /t:Restore. It usually does not happen in Visual Studio. Our ADO based build pipeline does not repro this, but it uses dotnet restore.
Repro sequence in our repo:
git clean -xfd at root
msbuild /t:Restore (works successfully)
msbuild /p:Configuration=Debug
Interestingly, with the same exact machine, dotnet restore instead of msbuild /t:Restore does not reproduce the problem.
Exact MSBuild version from console output:
msbuild /t:Restore
MSBuild version 17.4.0+18d5aef85 for .NET Framework
The exception stack:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : Sequence contains no elements [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at System.Linq.Enumerable.First[TSource](IEnumerable`1 source) [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets.GiveErrorForMissingFramework() [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets.GetTargetOrAttemptFallback(JObject lockFile, Boolean needsRuntimeIdentifier) [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets.GetReferences(JObject lockFile) [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets.ExecuteCore() [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\NuGet\17.0\Microsoft.NuGet.targets(198,5): error : at Microsoft.NuGet.Build.Tasks.ResolveNuGetPackageAssets.Execute() [C:\myrepo\src\\MyUnmanaged\exe\MyUnmanaged.vcxproj]
After converting a fully working .NET 6 repo to .NET 7 and VS 17.4.2, command line builds started failing with exceptions from NuGet.BuildTasks. This occurs on Windows only, and only within .vcxproj projects. The repo uses
Directory.Packages.propsglobal packages. It does not occur ifdotnet restoreis used (see below), just when restoring withmsbuild /t:Restore. It usually does not happen in Visual Studio. Our ADO based build pipeline does not repro this, but it usesdotnet restore.Repro sequence in our repo:
git clean -xfdat rootmsbuild /t:Restore(works successfully)msbuild /p:Configuration=DebugInterestingly, with the same exact machine,
dotnet restoreinstead ofmsbuild /t:Restoredoes not reproduce the problem.Exact MSBuild version from console output:
The exception stack: