Skip to content

fix(compiler): add bin/, obj/ to tsp init .gitignore for C# server emitter - #12617

Open
Samdanae Imran (samdanae) wants to merge 2 commits into
microsoft:mainfrom
samdanae:fix/7336-init-gitignore-patterns
Open

Samdanae Imran (samdanae) wants to merge 2 commits into
microsoft:mainfrom
samdanae:fix/7336-init-gitignore-patterns

Conversation

@samdanae

@samdanae Samdanae Imran (samdanae) commented Nov 19, 2026 •

Copy link
Copy Markdown

When you pick the C# server emitter in tsp init, the generated .gitignore now includes bin/ and obj/.

This doesn't matter if you scaffold into the default tsp-output folder, since that's already ignored. But if you scaffold somewhere else, for example {project-root}/server, git doesn't ignore the bin/ and obj/ folders from dotnet build, so they don't get ignored.

To avoid ignoring bin/ and obj/ in projects that don't use the C# server, I added an optional gitignorePatterns list to the emitters in the init template. tsp init adds the configured lines for each selected emitter.

The C# client emitter has the same issue. Happy to add bin/ and obj/ for it too (here or in a follow-up).

Fixes #7336

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@samdanae

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The tests do not verify that unselected emitters’ patterns are excluded, leaving a key regression gap, and the changelog omits the required configuration example.

2 open issues
What changed in this PR

Updates tsp init to ignore .NET build artifacts when the C# server emitter is selected, including when server output is outside tsp-output.

Changes:

  • Adds optional per-emitter gitignorePatterns metadata and appends selected emitters’ patterns without duplicates.
  • Configures the C# server emitter to ignore bin/ and obj/.
  • Adds scaffolding tests and a compiler changelog entry.
File Description
packages/​compiler/​test/​init/​init-template.test.ts Tests pattern inclusion and deduplication.
packages/​compiler/​templates/​scaffolding.json Includes C# server ignore patterns in generated templates.
packages/​compiler/​src/​init/​scaffold.ts Appends unique patterns from selected emitters.
packages/​compiler/​src/​init/​init-template.ts Defines and validates gitignorePatterns.
packages/​compiler/​.scripts/​build-init-templates.ts Configures C# server patterns in template source.
.chronus/​changes/​compiler-init-gitignore-patterns-2026-10-19-12-56-0.md Documents the initialization change and template capability.

Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings November 19, 2026 23:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The scaffold’s pattern deduplication retains first occurrences, changing order-sensitive Git ignore behavior; it should retain last occurrences and include a regression test with a negated pattern.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Preserve last-occurrence order for duplicate ignore patterns

packages/​compiler/​src/​init/​scaffold.ts:240

The Set keeps the first occurrence of each pattern, which changes the meaning of order-sensitive Git ignore rules. For example, an emitter supplying ["*.log", "!keep.log", "*.log"] should ignore keep.log, but the generated file leaves it unignored. Retain the last occurrence of each pattern instead, and add a regression test with a negated pattern.

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: @typespec/http-server-csharp - add bin and obj to .gitignore

3 participants