project-system
project-system copied to clipboard
Incorrect restore in Visual Studio when a dependency to a C# project is flowed through a C++/CLI project
Visual Studio 2022 17.3 Preview
Summary
The project.assets.json
file is incomplete for a C# project when it transitively depends on another C# project through a C++/CLI project. This problem seems to only occur in Visual Studio 2022 17.3 (tested with Preview 4.0 to 6.0) and not previous versions.
Lets say we have three projects: ProjectA
(C#), ProjectB
(C++/CLI) and ProjectC
(C#); so that ProjectA
references ProjectB
which references ProjectC
:
ProjectA (C#) --(depends on)--> ProjectB (C++/CLI) --> ProjectC (C#)
If the ProjectReference
from ProjectB
to ProjectC
does not contain the metadata Project
(e.g. <Project>{e5599aee-f39e-4613-b48d-7824eca526e5}</Project>
), MSBuild (through command line) and Visual Studio restore won't behave the same way. Typically, the transitive reference to ProjectC
is missing from ProjectA
's asset file when performing NuGet restore in Visual Studio:
(...)
"targets": {
".NETFramework,Version=v4.8": {
"ProjectB/1.0.0": {
"type": "project",
- "dependencies": {
- "ProjectC": "1.0.0"
- },
"compile": {
"bin/placeholder/ProjectB.dll": {}
},
"runtime": {
"bin/placeholder/ProjectB.dll": {}
}
},
- "ProjectC/1.0.0": {
- "type": "project",
- "framework": ".NETFramework,Version=v4.8",
- "compile": {
- "bin/placeholder/ProjectC.dll": {}
- },
- "runtime": {
- "bin/placeholder/ProjectC.dll": {}
- }
- }
}
}
(...)
Steps to Reproduce
-
Create three projects as described in the summary
-
Remove
<Project>
metadata in the reference fromProjectB
toProjectC
:- <ProjectReference Include="..\ProjectC\ProjectC.csproj"> - <Project>{e5599aee-f39e-4613-b48d-7824eca526e5}</Project> - </ProjectReference> + <ProjectReference Include="..\ProjectC\ProjectC.csproj" />
-
Perform a restore on
ProjectA
using MSBuild and check the contain of.\ProjectA\obj\project.assets.json
:msbuild -v:m -t:Restore .\ProjectA\ProjectA.csproj
-
Open the solution in Visual Studio 2022 17.3 Preview, force a restore if needed, and check the content of
.\ProjectA\obj\project.assets.json
again; you will notice the changes mentioned in the summary
See this repository: joeltankam/restore-cli-sample
Expected Behavior
MSBuild CLI and Visual Studio should have the same behavior, which means the restore should not be performed when opening the solution in Visual Studio. Package Manage log should be:
All packages are already installed and there is nothing to restore.
Actual Behavior
The restore is performed again in Visual Studio for ProjectA
:
Restored (...)\ProjectA\ProjectA.csproj (in 0.9 ms). NuGet package restore finished.
Changing .\ProjectA\obj\project.assets.json
as described in the summary; creating incremental compilation issues when switching from command-line to VS (e.g. some projects are unnecessarily re-restored and recompiled).
User Impact
We have a 950+ projects repository (~85% C#, ~10% C++, ~5% C++/CLI), with an average solution size of around 280 projects.
When switching the .NET SDK project file format, we removed <Project>
metadata on all project references, including C++ projects. This used to work perfectly until Visual Studio 2022 17.3. Now that it does not, it has some significant impacts considering the size of our repository and solutions (it's standard practice for us first to compile the whole repository through command-line, and then open a specific solution in Visual Studio, thus the issue).
On a side note, the Project
metadata is supposed to be the ProjectGuid
property of the referenced project; where does that value come from in this scenario since C# projects don't have that property anymore?
Any update on this please ?
Any update on this please ?
On a side note, the
Project
metadata is supposed to be theProjectGuid
property of the referenced project; where does that value come from in this scenario since C# projects don't have that property anymore?
Can you please give an answer to this ? @kvenkatrajan @drewnoakes
cc: @nkolev92 It seems that this belong to the NuGet team
Moved to https://github.com/NuGet/Home/issues/12170