[CLI] Reference output of projects that fail to load (e.g. F#) - #1833
Merged
josefpihrt merged 2 commits intoSep 2, 2026
Merged
Conversation
MSBuildWorkspace cannot load F# (and other unsupported-language) projects, so a C#/VB project that references one loses access to its types and reports them as missing (CS0103/CS0246) during analyze/fix. Set MSBuildWorkspace.LoadMetadataForReferencedProjects so the referenced project's compiled output is used as a metadata reference when the project itself cannot be loaded.
josefpihrt
approved these changes
Sep 2, 2026
Collaborator
|
@helgeu Thanks for the contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
net8.0,net9.0andnet10.0Summary
When a C#/VB project references a project in a language
MSBuildWorkspacecannot load — most commonly F# — the reference is dropped, and every type defined in that project is reported as missing duringanalyze/fix:These are false positives; the solution compiles fine with
dotnet build.Cause
MSBuildWorkspacedoes not support F#, so the referenced project is not added to the workspace and its project-to-project reference is lost, leaving the referencing project unable to see its types.Fix
Set
MSBuildWorkspace.LoadMetadataForReferencedProjects = true. When a referenced project cannot be loaded as a source project, the workspace then falls back to its compiled output as a metadata reference, so the types resolve. Projects that can be loaded are still loaded as source (project-to-project), so there is no change for ordinary C#/VB-only solutions. The referenced project must have been built.Verification
net10.0solution with a C# project referencing an F#.fsproj. Before:roslynator analyzereportsCS0103/CS0246for the F# types. After (with the F# project built): those are gone.net10.0solution: 112 false diagnostics (44×CS0103 'StatusRules'plusCS0246for other F# rule modules) drop to 0; total goes 1671 → 1558 real diagnostics.net8.0,net9.0andnet10.0.Note on tests
This is
MSBuildWorkspaceload behaviour with no natural home in the existing test projects, and there is no CLI test project (the analogous CLI infrastructure fix #1783 shipped without one). Verified end to end as above; happy to add a test if you would like one.Related issue
Fixes #1832
Investigated and implemented with AI assistance (opencode).