Skip to content

Implement #:ref directive for file-based apps#53480

Open
jjonescz wants to merge 12 commits intodotnet:release/10.0.3xxfrom
jjonescz:52532-ref-directive-2
Open

Implement #:ref directive for file-based apps#53480
jjonescz wants to merge 12 commits intodotnet:release/10.0.3xxfrom
jjonescz:52532-ref-directive-2

Conversation

@jjonescz
Copy link
Copy Markdown
Member

@jjonescz jjonescz commented Mar 16, 2026

Resolves #53478.
Needs dotnet/msbuild#13389.

@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Mar 16, 2026
@jjonescz jjonescz changed the base branch from main to release/10.0.3xx March 16, 2026 13:05
@jjonescz jjonescz marked this pull request as ready for review March 26, 2026 13:57
@jjonescz jjonescz requested review from a team and Copilot March 26, 2026 13:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Ref parsing, validation/feature-flag gating, path expansion/resolution, and project-file emission via injected <ProjectReference>.
  • Update dotnet run virtual project construction to pre-create/register referenced virtual projects, and update caching decisions to avoid #:ref scenarios.
  • Extend dotnet project convert and tests/docs/resources to support converting #:ref graphs 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-run-file Items related to the "dotnet run <file>" effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File-based apps should be able to reference other file-based libraries via #:ref

2 participants