From 3d83e2a447b9f1879ff8b8d2d5237f3f0fac98e5 Mon Sep 17 00:00:00 2001 From: helgereneurholm Date: Wed, 2 Sep 2026 18:12:14 +0200 Subject: [PATCH 1/2] [CLI] Reference output of projects that fail to load (e.g. F#) 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. --- CHANGELOG.md | 4 ++++ src/CommandLine/Commands/MSBuildWorkspaceCommand.cs | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a8f1332ef..1f7c00081f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- [CLI] Reference the compiled output of referenced projects that cannot be loaded into the workspace (for example F# projects), so their types are no longer reported as missing (`CS0103`/`CS0246`) during analysis + ## [5.0.0] - 2026-08-21 ### Added diff --git a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs index ac6d504cd9..fb6006cc87 100644 --- a/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs +++ b/src/CommandLine/Commands/MSBuildWorkspaceCommand.cs @@ -282,7 +282,15 @@ private static MSBuildWorkspace CreateMSBuildWorkspace(string msbuildPath, IEnum if (!properties.ContainsKey("AlwaysCompileMarkupFilesInSeparateDomain")) properties["AlwaysCompileMarkupFilesInSeparateDomain"] = bool.FalseString; - return MSBuildWorkspace.Create(properties); + MSBuildWorkspace workspace = MSBuildWorkspace.Create(properties); + + // Fall back to a referenced project's compiled output when the project itself cannot be + // loaded into the workspace (for example an F# project, which MSBuildWorkspace does not + // support). Without this, types defined in such a project are invisible to the C#/VB + // projects that reference it and surface as false CS0246/CS0103 errors during analysis. + workspace.LoadMetadataForReferencedProjects = true; + + return workspace; } private static bool TryGetVisualStudioInstance(out VisualStudioInstance result) From 4bb21d3b9d891401ba4867877f826802e0342ad2 Mon Sep 17 00:00:00 2001 From: helgereneurholm Date: Wed, 2 Sep 2026 18:16:00 +0200 Subject: [PATCH 2/2] [CLI] Reference PR in changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f7c00081f..9beca678ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- [CLI] Reference the compiled output of referenced projects that cannot be loaded into the workspace (for example F# projects), so their types are no longer reported as missing (`CS0103`/`CS0246`) during analysis +- [CLI] Reference the compiled output of referenced projects that cannot be loaded into the workspace (for example F# projects), so their types are no longer reported as missing (`CS0103`/`CS0246`) during analysis ([PR](https://github.com/dotnet/roslynator/pull/1833)) ## [5.0.0] - 2026-08-21