Skip to content

Commit 28576b2

Browse files
committed
Add some more copilot instructions to deal with nuget references
1 parent 929432b commit 28576b2

File tree

3 files changed

+177
-30
lines changed

3 files changed

+177
-30
lines changed

.github/workflows/copilot-setup-steps.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v5
1919

20+
# The NuGet MCP requires .NET 10 SDK to be available in PATH.
21+
- name: Setup local dotnet and add it to PATH PATH
22+
run:
23+
echo "$PWD/.dotnet/" >> $GITHUB_PATH
24+
2025
- name: Install Dependencies
2126
run: |
2227
sudo ./eng/common/native/install-dependencies.sh && \
@@ -26,11 +31,8 @@ jobs:
2631
- name: Restore solution
2732
run: ./build.sh -restore
2833

29-
- name: Put dotnet on the path
30-
run: echo "PATH=$PWD/.dotnet:$PATH" >> $GITHUB_ENV
31-
3234
- name: Run dotnet info
3335
run: dotnet --info
3436

35-
- name: Build clr+libs
37+
- name: Build repo
3638
run: ./build.sh

.vscode/mcp.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"servers": {
3+
"github-mcp": {
4+
"type": "http",
5+
"url": "https://api.githubcopilot.com/mcp"
6+
},
7+
"nuget": {
8+
"type": "stdio",
9+
"command": "dnx",
10+
"args": [
11+
"NuGet.Mcp.Server",
12+
"--prerelease",
13+
"--yes"
14+
]
15+
}
16+
},
17+
}

AGENTS.md

Lines changed: 154 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,50 @@ Build.cmd
3838
- `-configuration <Debug|Release>`: Build configuration (default: Debug)
3939
- `-architecture <x64|x86|arm|arm64>`: Target architecture
4040
- `-restore`: Restore dependencies before building
41-
- `-build`: Build the repository
42-
- `-rebuild`: Clean and rebuild
41+
- `-build`: Build the repository (incremental, only changed projects)
42+
- `-rebuild`: Clean and rebuild (required after changing .props/.targets files)
43+
- `-bl`: Requests a binlog.
4344
- `-test`: Run tests after building
4445

46+
### Build Output Locations
47+
48+
Understanding where build outputs are placed is essential for verification and debugging:
49+
50+
- **Managed Build outputs**: `artifacts/bin/<ProjectName>/<Configuration>/<TargetFramework>/`
51+
- **SOS Build outputs**: `artifacts/bin/<OS>.<Architecture>.<Configuration>`
52+
- **Test results when using global test script**: `artifacts/TestResults/`
53+
- **Build logs**: `artifacts/log/` (including `Build.binlog` for detailed analysis)
54+
- **NuGet packages**: `artifacts/packages/<Configuration>/`
55+
- **Temporary files**: `artifacts/tmp/`
56+
- **Intermediate files**: `artifacts/obj/` (such as obj files, generated files, etc.)
57+
58+
### Quick Build Commands
59+
60+
After a full build of the repo has been done, some commands can be used to iterate faster on changes:
61+
62+
### For changes under src/Tools:
63+
64+
```bash
65+
# Build the relevant tool
66+
dotnet build src/Tools/dotnet-dump/dotnet-dump.csproj
67+
68+
# Build without restoring (faster if dependencies haven't changed)
69+
dotnet build --no-restore
70+
```
71+
72+
### For changes under to native files:
73+
74+
```bash
75+
# Build the native components to verify compilation works
76+
./build.sh -skipmanaged
77+
78+
# Do a full test run:
79+
./build -test
80+
```
81+
4582
## Testing
4683

47-
### Running Tests
84+
### Running All Tests
4885

4986
**Linux/macOS:**
5087
```bash
@@ -56,12 +93,27 @@ Build.cmd
5693
Test.cmd
5794
```
5895

59-
The test script runs all tests in the repository. Test projects are located in the `src/tests` directory.
96+
The test script runs all tests in the repository. **Important**: `test.sh` calls `eng/build.sh -test -skipmanaged -skipnative`, which means it only runs tests without rebuilding. Always build first if you've made code changes.
6097

6198
### Test Organization
62-
- Unit tests are typically in `*.Tests` projects
63-
- Integration tests may be in separate test projects
64-
- Test helpers are in `Microsoft.Diagnostics.TestHelpers`
99+
100+
Test projects are usually located in `src/tests/` with the following structure:
101+
102+
- **Tool and libraries tests**: `*.UnitTests.csproj` or `*.Tests.csproj` under the appropriate tool's folder in `src/tests`.
103+
- Changes with native dependencies (SOS, DBGShim, dotnet-sos, dotnet-dump) are better tested with the global test script.
104+
105+
### Running Specific Tests
106+
107+
```bash
108+
# Run tests for a specific project
109+
dotnet test src/tests/Microsoft.Diagnostics.DebugServices.UnitTests/
110+
111+
# Run tests with detailed output
112+
dotnet test --logger "console;verbosity=detailed"
113+
114+
# Run a specific test by name
115+
dotnet test --filter "FullyQualifiedName~TestMethodName"
116+
```
65117

66118
## Project Structure
67119

@@ -91,17 +143,25 @@ The test script runs all tests in the repository. Test projects are located in t
91143
The repository follows standard .NET coding conventions defined in the `.editorconfig` file at the root. This is a **must** for C# code. Ensure your changes conform to these settings:
92144

93145
1. **Indentation**: 4 spaces (no tabs)
94-
2. **Line endings**: LF on Linux/macOS, CRLF on Windows
146+
2. **Line endings**: LF on Linux/macOS, CRLF on Windows (EditorConfig enforces this)
95147
3. **Braces**: Opening braces on new lines for types, methods, properties, control blocks
96-
4. **Naming**:
97-
- PascalCase for types, methods, properties, public fields
98-
- camelCase for local variables, parameters, private fields
99-
- `_camelCase` for private instance fields (with underscore prefix)
100-
5. **File organization**: One type per file, filename matches type name
101-
6. **Additional EditorConfig rules**:
148+
4. **Naming conventions** (strictly enforced):
149+
- PascalCase for types, methods, properties, public fields, constants
150+
- camelCase for local variables and parameters
151+
- `_camelCase` for private/internal instance fields (underscore prefix)
152+
- `s_camelCase` for static private/internal fields (s_ prefix)
153+
5. **File headers**: All C# files must include the MIT license header:
154+
```csharp
155+
// Licensed to the .NET Foundation under one or more agreements.
156+
// The .NET Foundation licenses this file to you under the MIT license.
157+
```
158+
6. **Using directives**: Must be placed **outside** the namespace declaration
159+
7. **Var keyword**: Avoid using `var` - use explicit types (configured as error when type is apparent)
160+
8. **File organization**: One type per file, filename matches type name
161+
9. **Additional rules**:
102162
- Trim trailing whitespace
103163
- Insert final newline
104-
- Follow C# new line and indentation preferences
164+
- Prefer braces even for single-line blocks
105165

106166
### Native Code (C/C++)
107167

@@ -111,6 +171,14 @@ Native code follows similar conventions:
111171
- Use clear, descriptive names
112172
- Follow existing patterns in the codebase
113173

174+
### Platform-Specific Line Endings
175+
176+
**Critical**: Line endings must match the platform to avoid breaking scripts:
177+
- Shell scripts (`.sh`): **LF only** (will break on Linux/macOS if CRLF)
178+
- Batch files (`.cmd`, `.bat`): **CRLF only**
179+
- C# files: LF on Linux/macOS, CRLF on Windows
180+
- The `.editorconfig` file enforces these rules automatically
181+
114182
## Making Changes
115183

116184
### General Guidelines
@@ -141,10 +209,33 @@ Native code follows similar conventions:
141209
### After Making Changes
142210

143211
1. **Build**: Ensure your changes compile without errors or new warnings
212+
```bash
213+
./build.sh # or Build.cmd on Windows
214+
```
144215
2. **Test**: Run relevant tests to verify functionality
216+
```bash
217+
./test.sh # or Test.cmd on Windows
218+
```
145219
3. **Code style**: Verify changes match the repository's coding standards
220+
- Check file headers (.NET Foundation header)
221+
- Verify naming conventions (especially field prefixes)
222+
- Ensure using directives are outside namespace
223+
- Confirm line endings are correct for file type
146224
4. **Documentation**: Update if your changes affect public APIs or behavior
147225

226+
### Investigating Build or Test Failures
227+
228+
When builds or tests fail, follow this diagnostic process:
229+
230+
1. **Check build logs**: Look at `artifacts/log/Build.binlog` using the Binary Log Viewer
231+
2. **Review terminal output**: MSBuild errors will show the failing project and error code
232+
3. **Check test results**: Detailed test logs are in `artifacts/TestResults/`
233+
4. **For native builds**: Review CMake output for missing dependencies or configuration issues
234+
5. **Clean and rebuild**: Sometimes required after changing build configuration files:
235+
```bash
236+
./build.sh -rebuild
237+
```
238+
148239
## Development Workflow
149240

150241
### Typical Workflow
@@ -178,16 +269,43 @@ Native code follows similar conventions:
178269

179270
### Solution Files
180271

181-
The main solution file is `build.sln` at the root. This file is generated from `build.proj` and can be regenerated using:
182-
```bash
183-
./eng/generate-sln.sh
184-
```
272+
The main solution file is `build.sln` at the root. **Important**: This file is auto-generated from `build.proj`.
273+
274+
- **Do NOT manually edit** `build.sln`
275+
- Regenerate after adding/removing projects:
276+
- Linux/macOS: `./eng/generate-sln.sh`
277+
- Windows: `.\eng\generate-sln.ps1`
278+
- The solution is regenerated automatically during builds when needed
185279

186280
### Dependency Management
187281

188-
- NuGet packages: `eng/Versions.props` defines package versions
189-
- Project references: Use relative paths in `.csproj` files
190-
- Native dependencies: Handled through CMake
282+
**NuGet Package Versions**:
283+
284+
The repository uses a centralized version management system:
285+
286+
- **`eng/Versions.props`**: Defines all NuGet package versions for the repo
287+
- **Always update this file** when changing package versions
288+
- Use the `nuget` MCP tool to query and resolve version conflicts
289+
- **`eng/Version.Details.props`**: Auto-generated by Arcade/Darc
290+
- **Never edit directly** - requires modifying Version.Details.xml.
291+
- **`eng/Version.Details.xml`**: Dependency tracking metadata
292+
- **Never edit directly** - requires metadata not available to agents.
293+
294+
**Package Source Configuration**:
295+
296+
- Never modify `NuGet.config` to add a source feed unless explicitly requested
297+
- **Never** add `nuget.org` as a source to `NuGet.config`
298+
- Use the `nuget` MCP tool for querying packages and resolving conflicts
299+
300+
**Project References**:
301+
302+
- Use relative paths in `.csproj` files when adding dependencies between projects
303+
Example: `<ProjectReference Include="..\Microsoft.Diagnostics.DebugServices\Microsoft.Diagnostics.DebugServices.csproj" />`
304+
305+
**Native Dependencies**:
306+
307+
- Handled through machine-wide installation or container installation
308+
- See `documentation/building/` for platform-specific prerequisites
191309

192310
### Platform-Specific Code
193311

@@ -212,15 +330,24 @@ start-vs.cmd
212330

213331
### Common Issues
214332

215-
1. **Build failures**: Ensure all prerequisites are installed (see documentation/building/)
216-
2. **Test failures**: Some tests may require specific runtime versions or configurations
217-
3. **Native component issues**: Check CMake output for missing dependencies
333+
1. **Build failures**:
334+
- Ensure all prerequisites are installed (see `documentation/building/`)
335+
- Check `artifacts/log/Build.binlog` for detailed error information
336+
2. **Test failures**:
337+
- Some tests require specific runtime versions or configurations
338+
- Check test output in `artifacts/TestResults/` if using global test script
339+
- Verify you built before testing (test scripts don't rebuild)
340+
3. **Native component issues**:
341+
- Check terminal output for cl/clang/cmake error output.
342+
4. **Line ending issues**:
343+
- Shell scripts fail on Linux/macOS: Check for CRLF line endings
344+
- Ensure `.editorconfig` settings are being respected by your editor
218345

219346
## Dependencies and Security
220347

221348
### Adding Dependencies
222349

223-
1. **NuGet packages**: Add to `eng/Versions.props` with appropriate version
350+
1. **NuGet packages**: Add to `eng/Versions.props` with appropriate version and never modify `NuGet.config` to add a source feed unless asked to do so specifically. Particularly, *never* add `nuget.org` as a source to `NuGet.config`. Use the `nuget` MCP as needed to query and solve for assembly version conflicts.
224351
2. **Security**: Be mindful of security implications when adding dependencies
225352
3. **Licensing**: Ensure new dependencies are compatible with MIT license
226353
4. **Minimize dependencies**: Only add when necessary
@@ -279,6 +406,7 @@ start-vs.cmd
279406
## Questions and Support
280407

281408
If you encounter issues or have questions:
409+
282410
1. Check existing documentation in `/documentation`
283411
2. Review closed issues and pull requests for similar problems
284412
3. Consult the [FAQ](documentation/FAQ.md)

0 commit comments

Comments
 (0)