Visual Studio cannot restore valid NoTargets projects because the MSBuild project cache loses inherited ProjectReference metadata
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 141
Description
### Issue Description
## Impact
Valid solutions fail NuGet restore in Visual Studio with NU1201, while command-line MSBuild restores the same projects successfully. This blocks Visual Studio use for repositories containing NoTargets build-order references to projects with incompatible framework identities, such as native C++ projects.
My team in Azure Storage is hitting this after migrating from CoreXT to retail. In our repository, 161 references across 31 NoTargets projects are exposed to this behavior.
## Issue description
The NoTargets SDK sets inherited metadata on every `ProjectReference`:
```xml
false
true
```
Visual Studio restore uses the MSBuild project cache. The cached item loses this inherited metadata. NuGet receives an empty `ReferenceOutputAssembly` value, treats it as true, and incorrectly adds the referenced project to the restore graph.
### Steps to Reproduce
Minimal reproduction:
```xml
net472
```
Open a clean solution containing this project and `NativeProject.vcxproj`, then restore it in Visual Studio.
### Expected Behavior
Visual Studio preserves the SDK-provided metadata and excludes the native build-order reference from the NuGet restore graph.
### Actual Behavior
Visual Studio reports:
```text
NU1201: Project NativeProject is not compatible with net472. Project NativeProject supports: native,Version=v0.0
```
Command-line MSBuild restore succeeds.
### Analysis
Visual Studio's CPS restore reads evaluated `ProjectReference` items through MSBuild's project-cache API. That API does not preserve metadata inherited from an `ItemDefinitionGroup`, so CPS receives an empty `ReferenceOutputAssembly` value and passes it to NuGet. The information is lost at the MSBuild API boundary, which is why this issue is filed against MSBuild rather than Visual Studio or NuGet.
```text
NoTargets SDK sets ROA=false
-> normal MSBuild evaluation has ROA=false
-> MSBuild project-cache representation loses it
-> CPS receives ROA=""
-> NuGet treats empty as true
-> NU1201
```
### Versions & Configurations
Observed with Visual Studio 18.8.2 and `Microsoft.Build.NoTargets/3.7.134`.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.