Document #:include support in file-based apps#53350
Conversation
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/27329bc4-87c0-469b-b146-55d906707455 Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
#:include support in file-based apps
|
@copilot Please respond to feedback. |
Reordered the list of supported directives for clarity and moved the `#:project` section to a new position.
Removed duplicate section for the `#:include` directive in the documentation.
There was a problem hiding this comment.
Pull request overview
Updates the file-based apps documentation to cover the newly supported #:include directive so developers can split a file-based app across multiple source files.
Changes:
- Adds
#:includeto the supported directives list. - Adds a new
#:includesubsection with examples and an availability note.
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/a2dfc33b-80ca-4bce-a649-cb0f6ef97058 Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/a2dfc33b-80ca-4bce-a649-cb0f6ef97058 Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/a2dfc33b-80ca-4bce-a649-cb0f6ef97058 Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/docs/sessions/a2dfc33b-80ca-4bce-a649-cb0f6ef97058 Co-authored-by: gewarren <24882762+gewarren@users.noreply.github.com>
| #:include models/customer.cs | ||
| ``` | ||
|
|
||
| The `#:include` directive is available in .NET 11 Preview 3 and .NET SDK 10.0.3xx and later. |
There was a problem hiding this comment.
We should wait for this to actually land in 3xx. It might not, you never know.
Do you think it's a good idea to put this up front? Someone may get here, try it, find it not working, never see that paragraph and complain it doesn't work.
There was a problem hiding this comment.
I think we should put this up front, yeah, immediately under the heading.
|
Feature PR is closed, so abandoning this PR. |
|
This feature landed in 10.0.300 last week so reopening. |
|
|
||
| Includes another C# source file in the file-based app. | ||
|
|
||
| Included files compile as part of the same app. They can add types, top-level statements, and other declarations. |
There was a problem hiding this comment.
included files can't add top-level statements, only the entry-point file can have top-level statements
|
|
||
| ### `#:include` | ||
|
|
||
| Includes another C# source file in the file-based app. |
There was a problem hiding this comment.
#:include supports other file types, not just .cs. In .NET 10.0.300 it supports .cs, .resx, .json, and .razor, with each being mapped to the appropriate item type:
- .cs ->
Compile - .resx ->
EmbeddedResource - .json ->
None - .razor ->
Content
|
|
||
| ```csharp | ||
| #:include helpers.cs | ||
| #:include models/customer.cs |
There was a problem hiding this comment.
The path also supports globs, e.g. #:include shared/**/*.cs, but it's worth noting that globs will disable the build caching currently. Also you can use MSBuild properties too, e.g. #:include $(MSBuildProjectName).*.cs in an app.cs file will result in app.helpers.cs, etc. being included (maybe worth a link to https://learn.microsoft.com/visualstudio/msbuild/msbuild-reserved-and-well-known-properties).
The file-based apps article was missing the new
#:includedirective introduced with .NET 11 Preview 3 and backported to .NET SDK 10.0.3xx. This update adds directive coverage and clarifies how included source files participate in compilation.Supported directives
#:includeto the top-level list of supported file-based app directives.New
#:includedirective section#:include.Default included items clarification
#:includeare included in compilation.Internal previews