Skip to content

Commit 840ecd9

Browse files
Copilotstephentoub
andauthored
Restructure copilot-instructions.md to emphasize mandatory baseline build (#123067)
# Description The coding agent was skipping baseline setup steps before building/running tests, causing "missing testhost" and "shared framework" errors. Restructured instructions to make baseline build impossible to miss. **Key changes:** - Moved baseline build to **first section** after title with ⚠️ MANDATORY heading - Added explicit cause-effect: skipping causes testhost/shared framework errors - Replaced verbose bullet lists with **quick-scan tables** for component ID and build commands - Added gate condition: "Only proceed after baseline build succeeds" - Reduced document from ~325 to ~185 lines (~43% reduction) - Removed table of contents and verbose iterative strategy section (standard behavior, not actionable) - Consolidated troubleshooting and references into compact table format **Restored guidance per feedback:** - WASM/WASI library detection logic (condensed) - "Checkout main branch" instruction before baseline build - Instruction to switch back to working branch after baseline build - Success criteria (exit code 0, zero test failures) - Library test project structure guidance with discovery command - "Target does not exist" troubleshooting entry - Log collection guidance for failure reporting **Added new components per feedback:** - Added entries for `src/tools`, `src/native/managed`, `src/tasks`, `src/tests` to component identification table - Added baseline build commands for Tools, Build Tasks, and Runtime Tests - Added workflow sections for Tools, Build Tasks, and Runtime Tests with build/test commands # Customer Impact N/A - Internal tooling instructions only. # Regression No. # Testing Documentation-only change. Verified no trailing whitespace per markdown guidelines. # Risk Low. No code changes. Core guidance retained; only organization and emphasis changed. # Package authoring no longer needed in .NET 9 IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version. Keep in mind that we still need package authoring in .NET 8 and older versions. <!-- START COPILOT CODING AGENT SUFFIX --> <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > Our instructions aren't working as well as we'd like. In particular, the coding agent isn't doing the baseline setup steps before it tries building/running tests. Please make whatever changes are needed to make these instructions more effectove. That could include anything from minor tweaks to an overhaul. Please retain the core instructions and guidance; focus on organization, brevity, relevance to copilot, etc </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent d3f4519 commit 840ecd9

File tree

1 file changed

+97
-237
lines changed

1 file changed

+97
-237
lines changed

.github/copilot-instructions.md

Lines changed: 97 additions & 237 deletions
Original file line numberDiff line numberDiff line change
@@ -33,293 +33,153 @@ In addition to the rules enforced by `.editorconfig`, you SHOULD:
3333

3434
# Building & Testing in dotnet/runtime
3535

36-
- [1. Prerequisites](#1-prerequisites)
37-
- [1.1. Determine Affected Components](#11-determine-affected-components)
38-
- [1.2. Baseline Setup](#12-baseline-setup)
39-
- [2. Iterative Build and Test Strategy](#2-iterative-build-and-test-strategy)
40-
- [2.1. Success Criteria](#21-success-criteria)
41-
- [3. CoreCLR (CLR) Workflow](#3-coreclr-clr-workflow)
42-
- [4. Mono Runtime Workflow](#4-mono-runtime-workflow)
43-
- [5. Libraries Workflow](#5-libraries-workflow)
44-
- [5.1. How To: Identify Affected Libraries](#51-how-to-identify-affected-libraries)
45-
- [5.2. How To: Build and Test Specific Library](#52-how-to-build-and-test-specific-library)
46-
- [6. WebAssembly (WASM) Libraries Workflow](#6-webassembly-wasm-libraries-workflow)
47-
- [7. Host Workflow](#7-host-workflow)
48-
- [8. Additional Notes](#8-additional-notes)
49-
- [8.1. Troubleshooting](#81-troubleshooting)
50-
- [8.2. Windows Command Equivalents](#82-windows-command-equivalents)
51-
- [8.3. References](#83-references)
36+
## ⚠️ MANDATORY: Run Baseline Build First
5237

53-
## 1. Prerequisites
38+
**You MUST complete these steps BEFORE making any code changes.** Skipping this causes "missing testhost" and "shared framework" errors that waste time.
5439

55-
These steps need to be done **before** applying any code changes.
40+
### Step 1: Identify Your Component
5641

57-
### 1.1. Determine Affected Components
42+
Based on file paths you will modify:
5843

59-
Identify which components will be impacted by the changes. If in doubt, analyze the paths of the files to be updated:
44+
| Files Changed | Component |
45+
|---------------|-----------|
46+
| `src/coreclr/` | CoreCLR |
47+
| `src/mono/` | Mono |
48+
| `src/libraries/` (no Browser/WASM or WASI targets) | Libraries |
49+
| `src/libraries/` with Browser/WASM or WASI targets in the affected `.csproj` | WASM/WASI Libraries |
50+
| `src/native/corehost/`, `src/installer/` | Host |
51+
| `src/tools` | Tools |
52+
| `src/native/managed` | Tools |
53+
| `src/tasks` | Build Tasks |
54+
| `src/tests` | Runtime Tests |
55+
| None of the above | Docs/infra only — skip build steps |
6056

61-
- **CoreCLR (CLR):** Changes in `src/coreclr/` or `src/tests/`
62-
- **Mono Runtime:** Changes in `src/mono/`
63-
- **Libraries:** Changes in `src/libraries/`
64-
- **WASM/WASI Libraries:** Changes in `src/libraries/` *and* the affected library targets WASM or WASI *and* the changes are included for the target (see below for details).
65-
- **Host:** Changes in `src/native/corehost/`, `src/installer/managed/`, or `src/installer/tests/`
66-
- If none above apply, it is most possibly an infra-only or a docs-only change. Skip build and test steps.
57+
**WASM/WASI Library Detection:** A change under `src/libraries/` is WASM/WASI-relevant if the library's `.csproj` has explicit Browser/WASM or WASI targets (`TargetFrameworks`, `TARGET_BROWSER`, `TARGET_WASI` constants, or `Condition` attributes referencing `browser`/`wasi`), **and** the changed file is not excluded from those targets via `Condition` on `<ItemGroup>` or `<Compile>`.
6758

68-
**WASM/WASI Library Change Detection**
59+
### Step 2: Run the Baseline Build (from repo root)
6960

70-
A change is considered WASM/WASI-relevant if:
61+
**First, checkout the `main` branch** to establish a known-good baseline, then run the appropriate build command:
7162

72-
- The relevant `.csproj` contains explicit Browser/WASM or WASI targets (look for `<TargetFrameworks>`, `$(TargetPlatformIdentifier)`, or `Condition` attributes referencing `browser` or `wasi`, as well as `TARGET_BROWSER` or `TARGET_WASI` constants), **and**
73-
- The changed file is not excluded from the build for that platform in any way with a `Condition` attribute on `<ItemGroup>` or `<Compile>`.
63+
| Component | Command |
64+
|-----------|---------|
65+
| **CoreCLR** | `./build.sh clr+libs+host` |
66+
| **Mono** | `./build.sh mono+libs` |
67+
| **Libraries** | `./build.sh clr+libs -rc release` |
68+
| **WASM Libraries** | `./build.sh mono+libs -os browser` |
69+
| **Host** | `./build.sh clr+libs+host -rc release -lc release` |
70+
| **Tools** | `./build.sh clr+libs -rc release` |
71+
| **Build Tasks** | `./build.sh clr+libs -rc release` |
72+
| **Runtime Tests** | `./build.sh clr+libs -lc release -rc checked` |
7473

75-
---
76-
77-
### 1.2. Baseline Setup
78-
79-
Before applying any changes, ensure you have a full successful build of the needed runtime+libraries as a baseline.
80-
81-
1. Checkout `main` branch
74+
For System.Private.CoreLib changes, use `-rc checked` instead of `-rc release` for asserts.
8275

83-
2. From the repository root, run the build depending on the affected component. If multiple components are affected, subsequently run and verify the builds for all of them.
84-
- **CoreCLR (CLR):** `./build.sh clr+libs+host`
85-
- **Mono Runtime:** `./build.sh mono+libs`
86-
- **Libraries:** `./build.sh clr+libs -rc release`
87-
- **WASM/WASI Libraries:** `./build.sh mono+libs -os browser`
88-
- **Host:** `./build.sh clr+libs+host -rc release -lc release`
89-
If changes are being made in the System.Private.CoreLib library, you can follow the Libraries steps, but you may want to use "-rc checked" instead of "-rc release"; that will result in asserts being included in the build rather than excluded.
76+
⏱️ **This build can take up to 40 minutes.** Do not cancel unless no output for 5+ minutes.
9077

91-
3. Verify the build completed without error.
92-
- _If the baseline build failed, report the failure and don't proceed with the changes._
78+
### Step 3: Configure Environment
9379

94-
4. From the repository root:
95-
- Configure PATH: `export PATH="$(pwd)/.dotnet:$PATH"`
96-
- Verify SDK Version: `dotnet --version` should match `sdk.version` in `global.json`.
80+
```bash
81+
export PATH="$(pwd)/.dotnet:$PATH"
82+
dotnet --version # Should match sdk.version in global.json
83+
```
9784

98-
5. Switch back to the working branch.
85+
**Only proceed with changes after the baseline build succeeds.** If it fails, report the failure and stop. After the baseline build, switch back to your working branch before making changes.
9986

10087
---
10188

102-
## 2. Iterative Build and Test Strategy
103-
104-
1. Apply the intended changes
105-
106-
2. **Attempt Build.** If the build fails, attempt to fix and retry the step (up to 5 attempts).
107-
108-
3. **Attempt Test.**
109-
- If a test _build_ fails, attempt to fix and retry the step (up to 5 attempts).
110-
- If a test _run_ fails,
111-
- Determine if the problem is in the test or in the source
112-
- If the problem is in the test, attempt to fix and retry the step (up to 5 attempts).
113-
- If the problem is in the source, reconsider the full changeset, attempt to fix and repeat the workflow.
114-
115-
4. **Workflow Iteration:**
116-
- Repeat build and test up to 5 cycles.
117-
- If issues persist after 5 workflow cycles, report failure.
118-
- If the same error persists after each fix attempt, do not repeat the same fix. Instead, escalate or report with full logs.
119-
120-
When retrying, attempt different fixes and adjust based on the build/test results.
121-
122-
### 2.1. Success Criteria
123-
124-
- **Build:**
125-
- Completes without errors.
126-
- Any non-zero exit code from build commands is considered a failure.
127-
128-
- **Tests:**
129-
- All tests must pass (zero failures).
130-
- Any non-zero exit code from test commands is considered a failure.
131-
132-
- **Workflow:**
133-
- On success: Report completion
134-
- Otherwise: Report error(s) with logs for diagnostics.
135-
- Collect logs from `artifacts/log/` and the console output for both build and test steps.
136-
- Attach relevant log files or error snippets when reporting failures.
89+
## Component-Specific Workflows
13790

138-
---
91+
After completing the baseline build above, use the appropriate workflow for your changes.
92+
All commands must complete with exit code 0, and all tests must pass with zero failures.
13993

140-
## 3. CoreCLR (CLR) Workflow
94+
### Libraries (Most Common)
14195

142-
From the repository root:
96+
**Build:** `./build.sh libs -rc release` (from repo root)
14397

144-
- Build:
145-
`./build.sh clr`
98+
**Test a specific library:**
99+
```bash
100+
cd src/libraries/<LibraryName>
101+
dotnet build
102+
dotnet build /t:test ./tests/<TestProject>.csproj
103+
```
146104

147-
- Run tests:
148-
`cd src/tests && ./build.sh && ./run.sh`
105+
Test projects are typically at: `tests/<LibraryName>.Tests.csproj` or `tests/<LibraryName>.Tests/<LibraryName>.Tests.csproj`, or under `tests/FunctionalTests/`, `tests/UnitTests/`, etc. Use `find tests -name '*.Tests.csproj'` to discover them.
149106

150-
- More info can be found in the dedicated workflow docs:
151-
- [Building CoreCLR Guide](/docs/workflow/building/coreclr/README.md)
152-
- [Building and Running CoreCLR Tests](/docs/workflow/testing/coreclr/testing.md)
107+
**Test all libraries:** `./build.sh libs.tests -test -rc release`
153108

154-
---
109+
**System.Private.CoreLib:** Rebuild with `./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc release`
155110

156-
## 4. Mono Runtime Workflow
111+
Before completing, ensure ALL tests for affected libraries pass.
157112

158-
From the repository root:
113+
### CoreCLR
159114

160-
- Build:
161-
`./build.sh mono+libs`
115+
**Build:** `./build.sh clr`
162116

163-
- Run tests:
117+
**Test:** `cd src/tests && ./build.sh && ./run.sh`
164118

165-
```bash
166-
./build.sh clr.host
167-
cd src/tests
168-
./build.sh mono debug /p:LibrariesConfiguration=debug
169-
./run.sh
170-
```
119+
### Mono
171120

172-
- More info can be found in the dedicated workflow docs:
173-
- [Building Mono](/docs/workflow/building/mono/README.md)
174-
- [Running test suites using Mono](/docs/workflow/testing/mono/testing.md)
121+
**Build:** `./build.sh mono+libs`
175122

176-
---
123+
**Test:**
124+
```bash
125+
./build.sh clr.host
126+
cd src/tests
127+
./build.sh mono debug /p:LibrariesConfiguration=debug
128+
./run.sh
129+
```
177130

178-
## 5. Libraries Workflow
131+
### WASM Libraries
179132

180-
From the repository root:
133+
**Build:** `./build.sh libs -os browser`
181134

182-
- Build all libraries:
183-
`./build.sh libs -rc release`
135+
**Test:** `./build.sh libs.tests -test -os browser`
184136

185-
- Run all tests for libraries:
186-
`./build.sh libs.tests -test -rc release`
137+
### Host
187138

188-
- Build a specific library:
189-
- Refer to the section [5.2. How To: Build and Test Specific Library](#52-how-to-build-and-test-specific-library) below.
139+
**Build:** `./build.sh host -rc release -lc release`
190140

191-
- Test a specific library:
192-
- Refer to the sections [5.1. How To: Identify Affected Libraries](#51-how-to-identify-affected-libraries) and [5.2. How To: Build and Test Specific Library](#52-how-to-build-and-test-specific-library) below.
141+
**Test:** `./build.sh host.tests -rc release -lc release -test`
193142

194-
- More info can be found in the dedicated workflow docs:
195-
- [Build Libraries](/docs/workflow/building/libraries/README.md)
196-
- [Testing Libraries](/docs/workflow/testing/libraries/testing.md)
143+
### Tools
197144

198-
When working on changes limited to a specific library, do not complete without at least running all tests for that library and confirming they pass. For example if you are working within "System.Text.RegularExpressions" then make sure after your last edits that all the test libraries under `src\libraries\System.Text.RegularExpressions\tests` pass. It is OK to filter to relevant specific tests during your work, but before returning, ensure that, at least, ALL tests for the library do pass.
145+
**Build:** `./build.sh tools+tools.ilasm`
199146

200-
### 5.1. How To: Identify Affected Libraries
147+
**Test:** `./build.sh tools+tools.ilasm+tools.illinktests+tools.cdactests -test`
201148

202-
For each changed file under `src/libraries/`, find the matching library and its test project(s).
203-
Most libraries use:
149+
### Build Tasks
204150

205-
- Source: `src/libraries/<LibraryName>/src/<LibraryName>.csproj`
151+
**Build:** `./build.sh tasks`
206152

207-
- Tests (single):
208-
- `src/libraries/<LibraryName>/tests/<LibraryName>.Tests.csproj`
209-
- OR `src/libraries/<LibraryName>/tests/<LibraryName>.Tests/<LibraryName>.Tests.csproj`
153+
### Runtime Tests
210154

211-
- Tests (multiple types):
212-
- `src/libraries/<LibraryName>/tests/FunctionalTests/<LibraryName>.Functional.Tests.csproj`
213-
- `src/libraries/<LibraryName>/tests/UnitTests/<LibraryName>.Unit.Tests.csproj`
214-
- Or similar.
155+
**Build:**
156+
```bash
157+
./build.sh clr+libs -lc release -rc checked
158+
./src/tests/build.sh checked
159+
./src/tests/run.sh checked
160+
```
215161

216162
---
217163

218-
### 5.2. How To: Build and Test Specific Library
219-
220-
If only one library is affected:
221-
222-
1. **Navigate to the library directory:**
223-
`cd src/libraries/<LibraryName>`
224-
225-
2. **Build the library:**
226-
`dotnet build`
227-
228-
3. **Build and run all test projects:**
164+
## Troubleshooting
229165

230-
- For each discovered `*.Tests.csproj` in the `tests` subdirectory:
231-
`dotnet build /t:test ./tests/<TestProject>.csproj`
166+
| Error | Solution |
167+
|-------|----------|
168+
| "shared framework must be built" | Run baseline build: `./build.sh clr+libs -rc release` |
169+
| "testhost" missing / FileNotFoundException | Run baseline build first (Step 2 above) |
170+
| Build timeout | Wait up to 40 min; only fail if no output for 5 min |
171+
| "Target does not exist" | Avoid specifying a target framework; the build will auto-select `$(NetCoreAppCurrent)` |
232172

233-
- *Adjust path as needed. If in doubt, search with `find tests -name '*.csproj'`.*
173+
**When reporting failures:** Include logs from `artifacts/log/` and console output for diagnostics.
234174

235-
- `dotnet build /t:test` is generally preferred over `dotnet test`
175+
**Windows:** Use `build.cmd` instead of `build.sh`. Set PATH: `set PATH=%CD%\.dotnet;%PATH%`
236176

237-
System.Private.CoreLib is special. To rebuild CoreLib and prepare to run tests with the changes, `cd` into the root of the repo and run:
238-
`./build.sh clr.corelib+clr.nativecorelib+libs.pretest -rc release`
239177
---
240178

241-
## 6. WebAssembly (WASM) Libraries Workflow
242-
243-
From the repository root:
244-
245-
- Build:
246-
`./build.sh libs -os browser`
247-
248-
- Run tests:
249-
`./build.sh libs.tests -test -os browser`
250-
251-
- More info can be found in the dedicated workflow docs:
252-
- [Build libraries for WebAssembly](/docs/workflow/building/libraries/webassembly-instructions.md)
253-
- [Testing Libraries on WebAssembly](/docs/workflow/testing/libraries/testing-wasm.md)
254-
255-
---
256-
257-
## 7. Host Workflow
258-
259-
From the repository root:
260-
261-
- Build:
262-
`./build.sh host -rc release -lc release`
263-
264-
- Run all tests:
265-
`./build.sh host.tests -rc release -lc release -test`
266-
267-
- More info can be found in the dedicated workflow docs:
268-
- [Building and running host tests](/docs/workflow/testing/host/testing.md)
269-
270-
---
271-
272-
## 8. Additional Notes
273-
274-
### 8.1. Troubleshooting
275-
276-
- **Shared Framework Missing**
277-
278-
- If the build fails with an error "The shared framework must be built before the local targeting pack can be consumed.", build both the runtime (clr or mono) and the libs.
279-
E.g., from the repo root, run `./build.sh clr+libs -rc release` if working on Libraries on CoreCLR. To find the applicable command, refer to the section [1.2. Baseline Setup](#12-baseline-setup).
280-
281-
- **Testhost Is Missing**
282-
283-
- If a test run fails with errors indicating a missing testhost, such as:
284-
- "Failed to launch testhost with error: System.IO.FileNotFoundException", or
285-
- "artifacts/bin/testhost/... No such file or directory",
286-
that means some of the prerequisites were not built.
287-
288-
- To resolve, build both the appropriate runtime (clr or mono) and the libs as a single command before running tests.
289-
E.g., from the repo root, run `./build.sh clr+libs -rc release` before testing Libraries on CoreCLR. To find the applicable command, refer to the section [1.2. Baseline Setup](#12-baseline-setup).
290-
291-
- **Build Timeout**
292-
293-
- Do not fail or cancel initial `./build.sh` builds due to timeout unless at least 40 minutes have elapsed.
294-
A full `clr+libs` build from scratch can take up to 32 minutes or more on some systems.
295-
296-
- Only wait for long-running `./build.sh` commands if they continue to produce output.
297-
If there is no output for 5 minutes, assume the build is stuck and fail early.
298-
299-
- **Target Does Not Exist**
300-
301-
- Avoid specifying a target framework when building unless explicitly asked.
302-
Build should identify and select the appropriate `$(NetCoreAppCurrent)` automatically.
303-
304-
---
305-
306-
### 8.2. Windows Command Equivalents
307-
308-
- Use `build.cmd` instead of `build.sh` on Windows.
309-
- Set PATH: `set PATH=%CD%\.dotnet;%PATH%`
310-
- All other commands are similar unless otherwise noted.
311-
312-
---
179+
## Reference
313180

314-
### 8.3. References
315-
316-
- [`.editorconfig`](/.editorconfig)
317-
- [Building CoreCLR Guide](/docs/workflow/building/coreclr/README.md)
318-
- [Building and Running CoreCLR Tests](/docs/workflow/testing/coreclr/testing.md)
319-
- [Building Mono](/docs/workflow/building/mono/README.md)
320-
- [Running test suites using Mono](/docs/workflow/testing/mono/testing.md)
321-
- [Build Libraries](/docs/workflow/building/libraries/README.md)
322-
- [Testing Libraries](/docs/workflow/testing/libraries/testing.md)
323-
- [Build libraries for WebAssembly](/docs/workflow/building/libraries/webassembly-instructions.md)
324-
- [Testing Libraries on WebAssembly](/docs/workflow/testing/libraries/testing-wasm.md)
325-
- [Building and running host tests](/docs/workflow/testing/host/testing.md)
181+
- [Build Libraries](/docs/workflow/building/libraries/README.md) · [Test Libraries](/docs/workflow/testing/libraries/testing.md)
182+
- [Build CoreCLR](/docs/workflow/building/coreclr/README.md) · [Test CoreCLR](/docs/workflow/testing/coreclr/testing.md)
183+
- [Build Mono](/docs/workflow/building/mono/README.md) · [Test Mono](/docs/workflow/testing/mono/testing.md)
184+
- [WASM Build](/docs/workflow/building/libraries/webassembly-instructions.md) · [WASM Test](/docs/workflow/testing/libraries/testing-wasm.md)
185+
- [Host Tests](/docs/workflow/testing/host/testing.md)

0 commit comments

Comments
 (0)