|  | 
|  | 1 | +# .NET Extensions Repository | 
|  | 2 | + | 
|  | 3 | +**Always reference these instructions first and fallback to search or bash commands only when you encounter unexpected information that does not match the info here.** | 
|  | 4 | + | 
|  | 5 | +The .NET Extensions repository contains a suite of libraries providing facilities commonly needed when creating production-ready applications. Major areas include AI abstractions, compliance mechanisms, diagnostics, contextual options, resilience (Polly), telemetry, AspNetCore extensions, static analysis, and testing utilities. | 
|  | 6 | + | 
|  | 7 | +## Working Effectively | 
|  | 8 | + | 
|  | 9 | +### Prerequisites and Bootstrap | 
|  | 10 | +- **CRITICAL**: Ensure you have access to the appropriate Azure DevOps feeds. If build fails with "Name or service not known" for `pkgs.dev.azure.com`, this indicates network/authentication issues with required internal feeds. | 
|  | 11 | +- Install .NET SDK 9.0.109 (as specified in global.json) if you do not already have it: | 
|  | 12 | +  ```bash | 
|  | 13 | +  curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version 9.0.109 --install-dir ~/.dotnet | 
|  | 14 | +  export PATH="$HOME/.dotnet:$PATH" | 
|  | 15 | +  ``` | 
|  | 16 | +- Verify installation: `dotnet --version` should show `9.0.109` | 
|  | 17 | + | 
|  | 18 | +### Essential Build Commands | 
|  | 19 | +- **Restore dependencies**: `./restore.sh` (Linux/Mac) or `restore.cmd` (Windows) | 
|  | 20 | +  - **CRITICAL - NEVER CANCEL**: Takes 5-10 minutes on first run. Always set timeout to 30+ minutes. | 
|  | 21 | +  - Downloads .NET SDK, tools, and packages from Azure DevOps feeds | 
|  | 22 | +  - Equivalent to `./build.sh --restore` | 
|  | 23 | + | 
|  | 24 | +- **Build the entire solution**: `./build.sh` (Linux/Mac) or `build.cmd` (Windows)   | 
|  | 25 | +  - **CRITICAL - NEVER CANCEL**: Takes 45-60 minutes for full build. Always set timeout to 90+ minutes. | 
|  | 26 | +  - Repository has 124 total projects - build times are expected to be substantial | 
|  | 27 | +  - Without parameters: equivalent to `./build.sh --restore --build` | 
|  | 28 | +  - Individual actions: `--restore`, `--build`, `--test`, `--pack` | 
|  | 29 | + | 
|  | 30 | +- **Run tests**: `./build.sh --test` | 
|  | 31 | +  - **CRITICAL - NEVER CANCEL**: Takes 20-30 minutes. Always set timeout to 60+ minutes. | 
|  | 32 | +  - Runs all unit tests across the solution | 
|  | 33 | + | 
|  | 34 | +### Solution Generation (Key Workflow) | 
|  | 35 | +This repository does NOT contain a single solution file. Instead, use the slngen tool to generate filtered solutions: | 
|  | 36 | + | 
|  | 37 | +- **Generate filtered solution**: `./build.sh --vs <keywords>` | 
|  | 38 | +  - Examples:  | 
|  | 39 | +    - `./build.sh --vs Http,Fakes,AspNetCore` | 
|  | 40 | +    - `./build.sh --vs Polly` (for resilience libraries) | 
|  | 41 | +    - `./build.sh --vs AI` (for AI-related projects) | 
|  | 42 | +    - `./build.sh --vs '*'` (all projects - escape asterisk) | 
|  | 43 | +  - Creates `SDK.sln` in repository root | 
|  | 44 | +  - Also performs restore operation | 
|  | 45 | +  - **NEVER CANCEL**: Takes 5-15 minutes depending on filter scope. Set timeout to 30+ minutes. | 
|  | 46 | + | 
|  | 47 | +- **Open in Visual Studio Code**: `./start-code.sh` (Linux/Mac) or `start-code.cmd` (Windows) | 
|  | 48 | +  - Sets up environment variables for proper .NET SDK resolution | 
|  | 49 | +  - Opens repository in VS Code with correct configuration | 
|  | 50 | + | 
|  | 51 | +### Build Validation and CI Requirements | 
|  | 52 | +- **Always run before committing**: | 
|  | 53 | +  ```bash | 
|  | 54 | +  ./build.sh --restore --build --test | 
|  | 55 | +  ``` | 
|  | 56 | +- **Check for API changes**: If you modify public APIs, run `./scripts/MakeApiBaselines.ps1` to update API baseline manifest files | 
|  | 57 | +- **NEVER CANCEL** long-running builds or tests - this repository has hundreds of projects and build times are expected to be lengthy | 
|  | 58 | + | 
|  | 59 | +### Common Build Issues and Workarounds | 
|  | 60 | + | 
|  | 61 | +1. **"Workload manifest microsoft.net.sdk.aspire not installed"**: | 
|  | 62 | +   - Run `git clean -xdf` then restore again | 
|  | 63 | +   - Caused by multiple SDK installations | 
|  | 64 | + | 
|  | 65 | +2. **"Could not resolve SDK Microsoft.DotNet.Arcade.Sdk"** or feed access errors: | 
|  | 66 | +   - Indicates no access to internal Microsoft Azure DevOps feeds | 
|  | 67 | +   - **NOT A CODE ISSUE** - environment/network limitation | 
|  | 68 | +   - Document as "Build requires access to internal Microsoft feeds" | 
|  | 69 | + | 
|  | 70 | +3. **SSL connection errors during restore**: | 
|  | 71 | +   - Try disabling IPv6 on network adapter | 
|  | 72 | +   - May indicate network/firewall restrictions | 
|  | 73 | + | 
|  | 74 | +### Project Structure and Navigation | 
|  | 75 | + | 
|  | 76 | +#### Key Directories | 
|  | 77 | +- `src/` - Main source code: | 
|  | 78 | +  - `src/Analyzers/` - Code analyzers | 
|  | 79 | +  - `src/Generators/` - Source generators   | 
|  | 80 | +  - `src/Libraries/` - Core extension libraries | 
|  | 81 | +  - `src/Packages/` - NuGet package definitions | 
|  | 82 | +  - `src/ProjectTemplates/` - Project templates | 
|  | 83 | +- `test/` - Test projects (organized to match src/ structure) | 
|  | 84 | +- `docs/` - Documentation including `building.md` | 
|  | 85 | +- `scripts/` - PowerShell automation scripts | 
|  | 86 | +- `eng/` - Build engineering and configuration | 
|  | 87 | + | 
|  | 88 | +#### Build Outputs   | 
|  | 89 | +- `artifacts/bin/` - Compiled binaries | 
|  | 90 | +- `artifacts/log/` - Build logs (including `Build.binlog` for MSBuild Structured Log Viewer) | 
|  | 91 | +- `artifacts/packages/` - Generated NuGet packages | 
|  | 92 | + | 
|  | 93 | +#### Key Files | 
|  | 94 | +- `global.json` - Specifies required .NET SDK version (9.0.109) | 
|  | 95 | +- `Directory.Build.props` - MSBuild properties for entire repository | 
|  | 96 | +- `NuGet.config` - Package source configuration (internal Microsoft feeds) | 
|  | 97 | + | 
|  | 98 | +## Validation Scenarios | 
|  | 99 | + | 
|  | 100 | +**After making changes, always execute these validation steps**: | 
|  | 101 | +1. **Generate relevant filtered solution**: `./build.sh --vs <relevant-keywords>` | 
|  | 102 | +   - For AI libraries: `./build.sh --vs AI` | 
|  | 103 | +   - For AspNetCore: `./build.sh --vs AspNetCore` | 
|  | 104 | +   - For telemetry: `./build.sh --vs Telemetry,Logging,Metrics` | 
|  | 105 | +   - For resilience: `./build.sh --vs Polly,Resilience` | 
|  | 106 | +2. **Build and test**: `./build.sh --build --test` (remember: NEVER CANCEL, 60+ minute timeout) | 
|  | 107 | +3. **For public API changes**: Run `./scripts/MakeApiBaselines.ps1` to update API baseline manifest files | 
|  | 108 | +4. **Manual verification**:  | 
|  | 109 | +   - Check that your changes compile across target frameworks (net8.0, net9.0) | 
|  | 110 | +   - Review generated packages in `artifacts/packages/` if applicable | 
|  | 111 | +   - Verify no new build warnings in `artifacts/log/Build.binlog` | 
|  | 112 | + | 
|  | 113 | +**Cannot run applications interactively** - this is a library repository. Validation is primarily through unit tests and integration tests. | 
|  | 114 | + | 
|  | 115 | +**Common validation patterns by library type**: | 
|  | 116 | +- **Source generators** (Microsoft.Gen.*): Build consumer projects that use the generator | 
|  | 117 | +- **AspNetCore extensions**: Build test web applications that reference the extensions   | 
|  | 118 | +- **Testing utilities**: Use them in test projects to verify functionality | 
|  | 119 | +- **Analyzers**: Build projects that trigger the analyzer rules | 
|  | 120 | + | 
|  | 121 | +## Time Expectations and Timeouts | 
|  | 122 | + | 
|  | 123 | +**CRITICAL - NEVER CANCEL BUILD OR TEST COMMANDS**: | 
|  | 124 | +- **First-time setup**: 15-20 minutes (SDK download + initial restore) - timeout: 45+ minutes | 
|  | 125 | +- **Restore operation**: 5-10 minutes - **ALWAYS set timeout to 30+ minutes, NEVER CANCEL**   | 
|  | 126 | +- **Full build**: 45-60 minutes - **ALWAYS set timeout to 90+ minutes, NEVER CANCEL** | 
|  | 127 | +- **Test execution**: 20-30 minutes - **ALWAYS set timeout to 60+ minutes, NEVER CANCEL** | 
|  | 128 | +- **Filtered solution generation**: 5-15 minutes - **ALWAYS set timeout to 30+ minutes** | 
|  | 129 | + | 
|  | 130 | +**Repository has 124 total projects** - build times are substantial by design. If commands appear to hang, wait at least 60 minutes before considering alternatives. | 
|  | 131 | + | 
|  | 132 | +## Advanced Usage | 
|  | 133 | + | 
|  | 134 | +### Custom Solution Generation | 
|  | 135 | +```bash | 
|  | 136 | +# Using PowerShell script directly with options | 
|  | 137 | +./scripts/Slngen.ps1 -Keywords "Http","Fakes" -Folders -OutSln "MyCustom.sln" | 
|  | 138 | +``` | 
|  | 139 | + | 
|  | 140 | +### Build Configuration Options | 
|  | 141 | +- `--configuration Debug|Release` - Build configuration | 
|  | 142 | +- `--verbosity minimal|normal|detailed|diagnostic` - MSBuild verbosity | 
|  | 143 | +- `--onlyTfms "net8.0;net9.0"` - Build specific target frameworks only | 
|  | 144 | + | 
|  | 145 | +### Code Coverage | 
|  | 146 | +```bash | 
|  | 147 | +./build.sh --restore --build --configuration Release --testCoverage | 
|  | 148 | +``` | 
|  | 149 | +Results available at: `artifacts/TestResults/Release/CoverageResultsHtml/index.html` | 
|  | 150 | + | 
|  | 151 | +## Common Tasks Reference | 
|  | 152 | + | 
|  | 153 | +**Key library areas and their keywords for filtered solutions**: | 
|  | 154 | +- **AI libraries**: `./build.sh --vs AI` (Microsoft.Extensions.AI.*, embedding, chat completion) | 
|  | 155 | +- **Telemetry**: `./build.sh --vs Telemetry,Logging,Metrics` (logging, metrics, tracing) | 
|  | 156 | +- **AspNetCore**: `./build.sh --vs AspNetCore` (middleware, diagnostics, testing) | 
|  | 157 | +- **Resilience**: `./build.sh --vs Polly,Resilience` (Polly integration, resilience patterns) | 
|  | 158 | +- **Compliance**: `./build.sh --vs Compliance,Audit` (data classification, audit reports) | 
|  | 159 | +- **Hosting**: `./build.sh --vs Hosting,Options` (contextual options, ambient metadata) | 
|  | 160 | +- **Testing utilities**: `./build.sh --vs Testing,Fakes` (mocking, fake implementations) | 
|  | 161 | + | 
|  | 162 | +**Find projects by pattern**: | 
|  | 163 | +```bash | 
|  | 164 | +# AI-related projects | 
|  | 165 | +find src/Libraries -name "*AI*" -name "*.csproj" | 
|  | 166 | + | 
|  | 167 | +# All AspNetCore extensions   | 
|  | 168 | +find src/Libraries -name "*AspNetCore*" -name "*.csproj" | 
|  | 169 | + | 
|  | 170 | +# Source generators | 
|  | 171 | +find src/Generators -name "*.csproj" | 
|  | 172 | + | 
|  | 173 | +# Test projects for a specific library | 
|  | 174 | +find test/Libraries -name "*[LibraryName]*" -name "*.csproj" | 
|  | 175 | +``` | 
|  | 176 | + | 
|  | 177 | +**Working with specific libraries workflow**: | 
|  | 178 | +1. Identify library area: `ls src/Libraries/` or use find commands above | 
|  | 179 | +2. Generate focused solution: `./build.sh --vs <library-keywords>` | 
|  | 180 | +3. Navigate to library directory: `cd src/Libraries/Microsoft.Extensions.[Area]` | 
|  | 181 | +4. Check corresponding tests: `cd test/Libraries/Microsoft.Extensions.[Area].Tests` | 
|  | 182 | +5. Review library README: `cat src/Libraries/Microsoft.Extensions.[Area]/README.md` | 
|  | 183 | +6. Build and test: `./build.sh --build --test` (with appropriate timeouts) | 
0 commit comments