Improve where file-level directives are added#50956
Merged
jjonescz merged 2 commits intodotnet:release/10.0.1xxfrom Sep 26, 2025
Merged
Improve where file-level directives are added#50956jjonescz merged 2 commits intodotnet:release/10.0.1xxfrom
jjonescz merged 2 commits intodotnet:release/10.0.1xxfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the placement and ordering of file-level directives in C# script files by handling shebang directives and implementing sorted insertion of named directives.
- Directives are now placed after shebang (
#!) directives to respect script file structure - Named directives (like packages) are inserted in alphabetical order for better organization
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Run/FileBasedAppSourceEditor.cs | Implements sorting logic for named directives and shebang handling in directive placement |
| test/dotnet.Tests/CommandTests/Run/FileBasedAppSourceEditorTests.cs | Adds test cases for sorted directive insertion and shebang directive handling |
333fred
approved these changes
Sep 22, 2025
MiYanni
approved these changes
Sep 25, 2025
Member
Author
|
@RikkiGibson for a review, thanks |
RikkiGibson
approved these changes
Sep 26, 2025
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.
Description
dotnet add app.cs packagewill now insert#:packagedirectives:#!directives (first commit) because#!needs to always be first in the file.dotnet add project.csproj package.Customer impact
This was discovered by me while dogfooding the feature.
Regression
No.
Risk
Low. This is just a tooling update, scoped to the new feature (file-based apps). Unit tests verify the behavior.