fileBasedApps: unit tests, no-csproj cone detection, language-ID check#9472
Draft
Copilot wants to merge 2 commits into
Draft
fileBasedApps: unit tests, no-csproj cone detection, language-ID check#9472Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
Implements microsoft/vscode-dotnettools#2369. Adds a new `dotnet.convertToProject` command that lets users convert a file-based C# app to a project-based app by running `dotnet project convert <file>` in an integrated terminal. Two entry points are provided: - Right-click on a .cs file in the Explorer or editor → "Convert C# File-based App to Project" - Command palette → "Convert C# File-based App to Project" → quick pick of all discoverable file-based app entry points in the workspace (files starting with `#!` or containing `#:` directives) Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Copilot
AI
changed the title
Add "Convert C# File-based App to Project" command (fixes vscode-dotnettools#2369)
Add "Convert C# File-based App to Project" command
Jun 25, 2026
Copilot created this pull request from a session on behalf of
mwiemer-microsoft
June 25, 2026 18:55
View session
…ne, language-ID check
- Export `FileBasedAppKind` enum and `detectFileBasedAppKind` with injectable
reader so unit tests don't need fs mocks
- Export `isInProjectCone` helper (walk ancestor dirs to find .csproj)
- pickAndConvertToProject: include C# files outside any .csproj cone as FBA
entry points even when they lack explicit #! / #: markers
- pickAndConvertToProject: augment the findFiles result with any open text
documents that VS Code already treats as csharp language but lack .cs ext
- convertToProject (right-click path): check document.languageId === 'csharp'
via openTextDocument instead of filePath.endsWith('.cs')
- Add TODO noting that the .NET 10 SDK has no CLI command for FBA detection
(only dotnet project convert); flag the Roslyn LSP request as the future fix
- Add 20 unit tests covering shebang, directives, BOM, None edge cases, and
all isInProjectCone permutations
Co-authored-by: mwiemer-microsoft <80539004+mwiemer-microsoft@users.noreply.github.com>
Copilot
AI
changed the title
Add "Convert C# File-based App to Project" command
fileBasedApps: unit tests, no-csproj cone detection, language-ID check
Jun 26, 2026
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.
Improves the "Convert to Project" command's FBA entry-point discovery with three behavioural changes and adds unit test coverage for the previously untestable detection logic.
Changes
Testability refactor (
convertToProject.ts)const enum FileBasedAppKind→export enum;detectFileBasedAppKindnow exported with an injectablereadFileHeadparameter (defaults to the realfsimpl), eliminating the need to mockfsin tests.defaultReadFileHead.No-
.csproj-cone detection (item 2)isInProjectCone(filePath, csprojDirs)walks ancestor directories to check for a.csproj.pickAndConvertToProjectnow collects all.csprojlocations viafindFiles, then includes any.csfile not inside any project cone in the picker — even without#!/#:markers — since such files have no project to belong to.VS Code language ID instead of file extension (item 3)
document.languageId === 'csharp'instead offilePath.endsWith('.cs').findFiles('**/*.cs')with any already-opentextDocumentswhoselanguageIdiscsharpbut whose path wasn't caught by the glob.SDK detection investigation (item 4)
dotnet projectin .NET 10 only exposesconvert(no dry-run/detect), anddotnet run --fileactually runs the program. No viable CLI detection path exists today. A TODO inpickAndConvertToProjectrecords this and flagsworkspace/_ms_fileBasedProgramEntryPointsas the right long-term replacement once Roslyn exposes it.Unit tests (
test/lsptoolshost/unitTests/convertToProject.test.ts)20 new tests across
detectFileBasedAppKindandisInProjectCone:Covers: shebang,
#:directives, BOM handling, unreadable files, 5-line scan cutoff, and allisInProjectConeancestor/sibling permutations.