Skip to content

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

Draft
jjonescz wants to merge 6 commits intodotnet:release/10.0.3xxfrom
jjonescz:52532-ref-directive
Draft

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

Conversation

@jjonescz
Copy link
Member

@jjonescz jjonescz commented Mar 6, 2026

Add support for referencing one file-based app from another via the
#:ref directive. When a file uses #:ref lib.cs, the referenced file is
built as a library (OutputType=Library) using the existing virtual
project infrastructure, and the output DLL is referenced via a
item in the referencing app's virtual project.

Key changes:

  • Add CSharpDirective.Ref class with path resolution (similar to Project)
  • Register 'ref' in the directive parser switch
  • Handle Ref in VirtualProjectBuilder.EvaluateDirectives
  • Emit items in WriteProjectFile for evaluated #:ref directives
  • Build referenced apps before main app in VirtualProjectBuildingCommand
  • Disable CSC cache optimization when #:ref is present
  • Convert #:ref to #:project in dotnet project convert
  • Add integration tests for basic ref, subdirectory ref, and error cases
  • Add resource strings for #:ref error messages
  • Update InternalAPI.Unshipped.txt and xlf files

Related to #52532.

jjonescz and others added 2 commits March 5, 2026 16:40
Add support for referencing one file-based app from another via the
built as a library (OutputType=Library) using the existing virtual
project infrastructure, and the output DLL is referenced via a
<Reference HintPath=...> item in the referencing app's virtual project.

Key changes:
- Add CSharpDirective.Ref class with path resolution (similar to Project)
- Register 'ref' in the directive parser switch
- Handle Ref in VirtualProjectBuilder.EvaluateDirectives
- Emit <Reference> items in WriteProjectFile for evaluated #:ref directives
- Build referenced apps before main app in VirtualProjectBuildingCommand
- Disable CSC cache optimization when #:ref is present
- Convert #:ref to #:project in dotnet project convert
- Add integration tests for basic ref, subdirectory ref, and error cases
- Add resource strings for #:ref error messages
- Update InternalAPI.Unshipped.txt and xlf files

Related to dotnet#52532

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a script for fast incremental iteration on specific SDK projects.
Builds only specified projects and copies DLLs to the redist layout
(~30s vs ~5min full build). Mention it in copilot-instructions.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jjonescz jjonescz added the Area-run-file Items related to the "dotnet run <file>" effort label Mar 6, 2026
jjonescz and others added 4 commits March 5, 2026 16:56
Add RefDirective test in DotnetProjectConvertTests verifying that
#:ref lib.cs converts to a ProjectReference pointing to ../lib/lib.csproj.

Add CscOnly_AfterMSBuild_RefDirective test verifying that CSC-only
optimization is disabled when #:ref directives are present.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that internals from a #:ref'd file are not accessible,
confirming it produces a metadata (assembly) reference rather than
a source-level reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that app.cs -> lib1.cs -> lib2.cs transitive references work
correctly, with each level building its dependencies recursively.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify that app.cs using both #:ref lib.cs and #:project ProjectLib
works when both lib.cs and ProjectLib reference a common project.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

1 participant