-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Fix open issues on the file-based apps tutorial #50568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
BillWagner
merged 4 commits into
dotnet:main
from
BillWagner:move-file-based-apps-tutorial
Dec 16, 2025
+33
−93
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/usr/local/share/dotnet/dotnet run | ||
| #!/usr/bin/env dotnet run | ||
|
|
||
| // <ColorfulPackage> | ||
| #:package [email protected] | ||
|
|
@@ -71,7 +71,8 @@ async Task<AsciiMessageOptions> ProcessParseResults(ParseResult result) | |
| } | ||
| // </ProcessParsedArgs> | ||
|
|
||
| // <WriteAscii> | ||
|
|
||
| // <WriteAsciiArt> | ||
| async Task WriteAsciiArt(AsciiMessageOptions options) | ||
| { | ||
| foreach (string message in options.Messages) | ||
|
|
@@ -80,7 +81,7 @@ async Task WriteAsciiArt(AsciiMessageOptions options) | |
| await Task.Delay(options.Delay); | ||
| } | ||
| } | ||
| // </WriteAscii> | ||
| // </WriteAsciiArt> | ||
|
|
||
| // <Record> | ||
| public record AsciiMessageOptions(string[] Messages, int Delay); | ||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,7 @@ f1_keywords: | |
| - "#pragma checksum" | ||
| - "defaultline_CSharpKeyword" | ||
| - "#!" | ||
| - "#:sdk" | ||
| - "#:property" | ||
| - "#:package" | ||
| - "#:" | ||
| helpviewer_keywords: | ||
| - "preprocessor directives [C#]" | ||
| - "keywords [C#], preprocessor directives" | ||
|
|
@@ -62,69 +60,9 @@ Console.WriteLine("Hello"); | |
|
|
||
| The preceding code snippet informs a Unix shell to execute the file using `dotnet run`. The `/usr/bin/env` command locates the `dotnet` executable in your PATH, making this approach portable across different Unix and macOS distributions. The `#!` line must be the first line in the file, and the following tokens are the program to run. You need to enable the *execute* (`x`) permission on the C# file for that feature. | ||
|
|
||
| The `#:` directives that are used in file-based apps include: | ||
|
|
||
| - `#:sdk`: | ||
|
|
||
| The first instance specifies the value for the `<Project Sdk="value" />` node. Subsequent instances specify the `<Sdk Name="value" Version="version" />` node. The version can be omitted (i.e. if specified in global.json or included in .NET SDK). For example: | ||
|
|
||
| ```csharp | ||
| #:sdk Microsoft.NET.Sdk.Web | ||
| #:sdk [email protected] | ||
| ``` | ||
|
|
||
| The two preceding preprocessors is translated into: | ||
|
|
||
| ```xml | ||
| <Project Sdk="Microsoft.NET.Sdk.Web" /> | ||
| <Sdk Name="Aspire.AppHost.Sdk" Version="9.4.1" /> | ||
| ``` | ||
|
|
||
| - `#:property`: | ||
|
|
||
| Instances of `#:property` are translated into property elements in a `<PropertyGroup>`. A token of the form `Name=value` must follow the `property` token. The following example directives are valid `property` tokens: | ||
|
|
||
| ```csharp | ||
| #:property TargetFramework=net11.0 | ||
| #:property LangVersion=preview | ||
| ``` | ||
|
|
||
| The preceding two properties are translated into: | ||
|
|
||
| ```xml | ||
| <TargetFramework>net11.0</TargetFramework> | ||
| <LangVersion>preview</LangVersion> | ||
| ``` | ||
|
|
||
| - `#:package`: | ||
|
|
||
| Instances of `#:package` are translated into `PackageReference` elements to include NuGet packages with the specified version to your file. For example: | ||
|
|
||
| ```csharp | ||
| #:package [email protected]* | ||
| ``` | ||
|
|
||
| The preceding preprocessor token is translated into: | ||
|
|
||
| ```xml | ||
| <PackageReference Include="System.CommandLine" Version="2.0.0-*"> | ||
| ``` | ||
|
|
||
| - `#:project`: | ||
|
|
||
| Instances of `#:project` are translated into `ProjectReference` elements to include the project with the specified path to the project. For example: | ||
|
|
||
| ```csharp | ||
| #:project ../Path/To.Example | ||
| ``` | ||
|
|
||
| The preceding preprocessor token is translated into: | ||
|
|
||
| ```xml | ||
| <ProjectReference Include="../Path/To.Example/To.Example.csproj" /> | ||
| ``` | ||
| The `#:` directives that are used in file-based apps are described in the [file based apps reference](../../core/sdk/file-based-apps.md). | ||
|
|
||
| Tools can add new tokens following the `#:` convention. | ||
| Other tools can add new tokens following the `#:` convention. | ||
|
|
||
| ## Nullable context | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.