Get build errors if a solution is missing references #10780
Replies: 2 comments
-
|
Hi, The issue you’re hitting is because MSBuild at the command line will happily restore and build projects that are referenced in the solution file only if the .csproj exists, but Visual Studio performs more strict checks for design-time build and package resolution. That’s why you see NU1105 in VS when a project is missing from the solution. To get early alerts for missing projects, you have a few options:
MSBuild won’t fail by default for missing projects in the solution, so you need either a custom target or a CI-level check to enforce this. |
Beta Was this translation helpful? Give feedback.
-
For parsing sln files in C#, consider using https://github.com/microsoft/vs-solutionpersistence. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I need some advice. We have a monorepo with many .csproj files and solutions. Long story short, both scenarios involve the \bin\ and \obj\ folders being wiped from all projects.
If I build a solution with MSBuild, it builds fine:
msbuild.exe D:\Github\yyy\project\solution.sln /t:Restore;Build /m /p:Configuration=Release
However, when I build the same solution in Visual Studio 2022, I get the following error:
Severity: Error
Code: NU1105
Description: Unable to find project information for 'D:\GitHub\xxx\project\project.csproj'. If you are using Visual Studio, this may be because the project is unloaded or not part of the current solution, so try running a restore from the command line. Otherwise, the project file may be invalid or missing targets required for restore.
This error indicates that the .csproj file is missing from the solution, and someone needs to add the missing project. We would like to have a way to be alerted when a project is missing from a solution.
How would one go about making this happen?
My initial thought was to add some arguments to MSBuild that would cause it to fail if a solution is missing a reference, but I haven't been able to make MSBuild produce a build error in this case. Any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions