Open
Description
NuGet Product Used
MSBuild.exe
Product Version
msbuild 17
Worked before?
No
Impact
It's more difficult to complete my work
Repro Steps & Context
Dep\Dep.csproj
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net472;net5.0</TargetFrameworks>
</PropertyGroup>
</Project>
Broken\Broken.csproj
:
<Project>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Dep\Dep.csproj">
<SetTargetFramework>TargetFramework=net472</SetTargetFramework>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Do a static graph restore on Broken\Broken.csproj
. The output looks like:
Microsoft (R) Build Engine version 17.2.0-dev-22166-01+719247ede for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
C:\Program Files\Microsoft Visual Studio\2022\IntPreview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.RestoreEx.targets(19,5): error : Object reference not set to an instance of an object. [C:\Code\tmp\GraphRestoreRepro\Broken\Broken.csproj]
Build FAILED.
C:\Program Files\Microsoft Visual Studio\2022\IntPreview\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.RestoreEx.targets(19,5): error : Object reference not set to an instance of an object. [C:\Code\tmp\GraphRestoreRepro\Broken\Broken.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:06.70
The NRE specifically is in MSBuildStaticGraphRestore.GetPackageSpec
. The caller iterates each ProjectWithInnerNodes
and calls GetPackageSpec(project.OuterProject)
, but project.OuterProject
is null for the Dep\Dep.csproj
entry.
If any of the following is changed, it works:
- Non-static graph restore
- Remove the
SetTargetFramework
metadata fromBroken\Broken.csproj
- Migrate
Broken\Broken.csproj
to SDK-style
Verbose Logs
No response