Implement #:ref directive for file-based apps#53480
Open
jjonescz wants to merge 12 commits intodotnet:release/10.0.3xxfrom
Open
Implement #:ref directive for file-based apps#53480jjonescz wants to merge 12 commits intodotnet:release/10.0.3xxfrom
#:ref directive for file-based apps#53480jjonescz wants to merge 12 commits intodotnet:release/10.0.3xxfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds support for #:ref in file-based apps so a .cs file can reference another file-based .cs as a compiled library (via virtual MSBuild projects), including conversion behavior and documentation.
Changes:
- Introduce
CSharpDirective.Refparsing, validation/feature-flag gating, path expansion/resolution, and project-file emission via injected<ProjectReference>. - Update
dotnet runvirtual project construction to pre-create/register referenced virtual projects, and update caching decisions to avoid#:refscenarios. - Extend
dotnet project convertand tests/docs/resources to support converting#:refgraphs into sibling library projects with appropriate project references.
Reviewed changes
Copilot reviewed 36 out of 36 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Run/RunFileTests.cs | Adds end-to-end tests for #:ref (path handling, transitive refs, feature flag gating, and optimization interactions). |
| test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs | Adds conversion tests validating #:ref becomes project references and detects output folder conflicts. |
| src/Microsoft.DotNet.ProjectTools/VirtualProjectBuilder.cs | Adds OutputType configurability, evaluates #:ref, gates it via feature flag, and emits ProjectReference entries for refs. |
| src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs | Disables cache save/compute for #:ref and recursively creates referenced virtual projects so MSBuild can resolve them. |
| src/Cli/dotnet/Commands/Project/Convert/ProjectConvertCommand.cs | Implements recursive conversion of #:ref files into library projects and validates duplicate target directories. |
| src/Cli/dotnet/Commands/CliCommandStrings.resx | Adds new CLI string for duplicate ref folder-name conversion error. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf | Localizes the new duplicate-folder conversion error string. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/FileLevelDirectiveHelpers.cs | Implements the #:ref directive model, parsing, and file-path resolution/validation. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/FileBasedProgramsResources.resx | Adds #:ref-specific error strings (invalid directive, missing file). |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/InternalAPI.Unshipped.txt | Updates internal API surface to include the new Ref directive types/consts. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.zh-Hant.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.zh-Hans.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.tr.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.ru.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.pt-BR.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.pl.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.ko.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.ja.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.it.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.fr.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.es.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.de.xlf | Localizes new #:ref-related error strings. |
| src/Cli/Microsoft.DotNet.FileBasedPrograms/xlf/FileBasedProgramsResources.cs.xlf | Localizes new #:ref-related error strings. |
| documentation/general/dotnet-run-file.md | Documents #:ref behavior, path resolution rules, feature flag, and grow-up/conversion behavior. |
This was referenced Mar 27, 2026
Open
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.
Resolves #53478.
Needs dotnet/msbuild#13389.