|
| 1 | +# .NET Technology Stack & Build System |
| 2 | + |
| 3 | +## .NET 8+ Development Environment |
| 4 | + |
| 5 | +### Build Tools & Dependencies |
| 6 | +- **Build System**: dotnet CLI |
| 7 | +- **Package Manager**: NuGet |
| 8 | +- **Testing Framework**: xUnit |
| 9 | +- **Code Formatting**: dotnet-format |
| 10 | +- **SDK Version**: AWS SDK for .NET v4 |
| 11 | +- **.NET Version**: .NET 8+ |
| 12 | + |
| 13 | +### Common Build Commands |
| 14 | + |
| 15 | +```bash |
| 16 | +# Build and Package |
| 17 | +dotnet build SOLUTION.sln # Build solution |
| 18 | +dotnet build PROJECT.csproj # Build specific project |
| 19 | +dotnet clean # Clean build artifacts |
| 20 | + |
| 21 | +# Testing |
| 22 | +dotnet test # Run all tests |
| 23 | +dotnet test --filter Category=Integration # Run integration tests |
| 24 | +dotnet test --logger trx # Run tests with detailed output |
| 25 | + |
| 26 | +# Execution |
| 27 | +dotnet run # Run project |
| 28 | +dotnet run --project PROJECT.csproj # Run specific project |
| 29 | + |
| 30 | +# Code Quality |
| 31 | +dotnet format # Format code |
| 32 | +``` |
| 33 | + |
| 34 | +### .NET-Specific Pattern Requirements |
| 35 | + |
| 36 | +#### File Naming Conventions |
| 37 | +- Use PascalCase for class names and file names |
| 38 | +- Service prefix pattern: `{Service}Actions.cs` (e.g., `S3Actions.cs`) |
| 39 | +- Hello scenarios: `Hello{Service}.cs` (e.g., `HelloS3.cs`) |
| 40 | +- Test files: `{Service}Tests.cs` |
| 41 | + |
| 42 | +#### Hello Scenario Structure |
| 43 | +- **Class naming**: `Hello{Service}.cs` class with main method |
| 44 | +- **Method structure**: Static Main method as entry point |
| 45 | +- **Documentation**: Include XML documentation explaining the hello example purpose |
| 46 | + |
| 47 | +#### Code Structure Standards |
| 48 | +- **Namespace naming**: Use reverse domain notation (e.g., `Amazon.DocSamples.S3`) |
| 49 | +- **Class structure**: One public class per file matching filename |
| 50 | +- **Method naming**: Use PascalCase for method names |
| 51 | +- **Properties**: Use PascalCase for property names |
| 52 | +- **Constants**: Use PascalCase for constants |
| 53 | +- **Async methods**: Suffix with `Async` (e.g., `ListBucketsAsync`) |
| 54 | + |
| 55 | +#### Dependency Injection Patterns |
| 56 | +```csharp |
| 57 | + /// <summary> |
| 58 | + /// Main entry point for the AWS Control Tower basics scenario. |
| 59 | + /// </summary> |
| 60 | + /// <param name="args">Command line arguments.</param> |
| 61 | + public static async Task Main(string[] args) |
| 62 | + { |
| 63 | + using var host = Host.CreateDefaultBuilder(args) |
| 64 | + .ConfigureServices((_, services) => |
| 65 | + services.AddAWSService<IAmazonControlTower>() |
| 66 | + .AddAWSService<IAmazonControlCatalog>() |
| 67 | + .AddAWSService<IAmazonOrganizations>() |
| 68 | + .AddAWSService<IAmazonSecurityTokenService>() |
| 69 | + .AddTransient<ControlTowerWrapper>() |
| 70 | + ) |
| 71 | + .Build(); |
| 72 | + |
| 73 | + logger = LoggerFactory.Create(builder => { builder.AddConsole(); }) |
| 74 | + .CreateLogger<ControlTowerBasics>(); |
| 75 | + |
| 76 | + wrapper = host.Services.GetRequiredService<ControlTowerWrapper>(); |
| 77 | + orgClient = host.Services.GetRequiredService<IAmazonOrganizations>(); |
| 78 | + stsClient = host.Services.GetRequiredService<IAmazonSecurityTokenService>(); |
| 79 | + |
| 80 | + await RunScenario(); |
| 81 | + } |
| 82 | +``` |
| 83 | + |
| 84 | +#### Error Handling Patterns |
| 85 | +```csharp |
| 86 | +using Amazon.S3; |
| 87 | +using Amazon.S3.Model; |
| 88 | +using System; |
| 89 | +using System.Threading.Tasks; |
| 90 | + |
| 91 | +public class ExampleClass |
| 92 | +{ |
| 93 | + public async Task ExampleMethodAsync() |
| 94 | + { |
| 95 | + var s3Client = new AmazonS3Client(); |
| 96 | + |
| 97 | + try |
| 98 | + { |
| 99 | + var response = await s3Client.ListBucketsAsync(); |
| 100 | + // Process response |
| 101 | + Console.WriteLine($"Found {response.Buckets.Count} buckets"); |
| 102 | + } |
| 103 | + catch (AmazonS3Exception e) |
| 104 | + { |
| 105 | + // Handle S3-specific exceptions |
| 106 | + Console.WriteLine($"S3 Error: {e.Message}"); |
| 107 | + Console.WriteLine($"Error Code: {e.ErrorCode}"); |
| 108 | + throw; |
| 109 | + } |
| 110 | + catch (Exception e) |
| 111 | + { |
| 112 | + // Handle general exceptions |
| 113 | + Console.WriteLine($"Error: {e.Message}"); |
| 114 | + throw; |
| 115 | + } |
| 116 | + finally |
| 117 | + { |
| 118 | + s3Client?.Dispose(); |
| 119 | + } |
| 120 | + } |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +#### Testing Standards |
| 125 | +- **Test framework**: Use xUnit attributes (`[Fact]`, `[Theory]`) |
| 126 | +- **Integration tests**: Mark with `[Trait("Category", "Integration")]` |
| 127 | +- **Async testing**: Use `async Task` for async test methods |
| 128 | +- **Resource management**: Use `using` statements for AWS clients |
| 129 | +- **Test naming**: Use descriptive method names explaining test purpose |
| 130 | + |
| 131 | +#### Project Structure |
| 132 | +``` |
| 133 | +src/ |
| 134 | +├── {Service}Examples/ |
| 135 | +│ ├── Hello{Service}.cs |
| 136 | +│ ├── {Service}Actions.cs |
| 137 | +│ ├── {Service}Scenarios.cs |
| 138 | +│ └── {Service}Examples.csproj |
| 139 | +└── {Service}Examples.Tests/ |
| 140 | + ├── {Service}Tests.cs |
| 141 | + └── {Service}Examples.Tests.csproj |
| 142 | +``` |
| 143 | + |
| 144 | +#### Documentation Requirements |
| 145 | +- **XML documentation**: Use `///` for class and method documentation |
| 146 | +- **Parameter documentation**: Document all parameters with `<param>` |
| 147 | +- **Return documentation**: Document return values with `<returns>` |
| 148 | +- **Exception documentation**: Document exceptions with `<exception>` |
| 149 | +- **README sections**: Include dotnet setup and execution instructions |
| 150 | + |
| 151 | +### AWS Credentials Handling |
| 152 | + |
| 153 | +#### Critical Credential Testing Protocol |
| 154 | +- **CRITICAL**: Before assuming AWS credential issues, always test credentials first with `aws sts get-caller-identity` |
| 155 | +- **NEVER** assume credentials are incorrect without verification |
| 156 | +- If credentials test passes but .NET SDK fails, investigate SDK-specific credential chain issues |
| 157 | +- Common .NET SDK credential issues: EC2 instance metadata service conflicts, credential provider chain order |
| 158 | + |
| 159 | +### Build Troubleshooting |
| 160 | + |
| 161 | +#### DotNetV4 Build Troubleshooting |
| 162 | +- **CRITICAL**: When you get a response that the project file does not exist, use `listDirectory` to find the correct project/solution file path before trying to build again |
| 163 | +- **NEVER** repeatedly attempt the same build command without first locating the actual file structure |
| 164 | +- Always verify file existence with directory listing before executing build commands |
| 165 | + |
| 166 | +### Language-Specific Pattern Errors to Avoid |
| 167 | +- ❌ **NEVER create examples for dotnetv3 UNLESS explicitly instructed to by the user** |
| 168 | +- ❌ **NEVER use camelCase for .NET class or method names** |
| 169 | +- ❌ **NEVER forget to dispose AWS clients (use using statements)** |
| 170 | +- ❌ **NEVER ignore proper exception handling for AWS operations** |
| 171 | +- ❌ **NEVER skip NuGet package management** |
| 172 | +- ❌ **NEVER assume credentials without testing first** |
| 173 | +- ❌ **NEVER use other language folders for patterns** |
| 174 | + |
| 175 | +### Best Practices |
| 176 | +- ✅ **ALWAYS create examples in the dotnetv4 directory unless instructed otherwise** |
| 177 | +- ✅ **ALWAYS follow the established .NET project structure** |
| 178 | +- ✅ **ALWAYS use PascalCase for .NET identifiers** |
| 179 | +- ✅ **ALWAYS use using statements for AWS client management** |
| 180 | +- ✅ **ALWAYS include proper exception handling for AWS service calls** |
| 181 | +- ✅ **ALWAYS test AWS credentials before assuming credential issues** |
| 182 | +- ✅ **ALWAYS include comprehensive XML documentation** |
| 183 | +- ✅ **ALWAYS use async/await patterns for AWS operations** |
| 184 | +- ✅ **ALWAYS use dependency injection for AWS services** |
| 185 | +- ✅ **ALWAYS create a separate class in the Actions project for the Hello example** |
| 186 | +- ✅ **ALWAYS add project files to the main solution file DotNetV4Examples.sln** |
| 187 | +- ✅ **ALWAYS put print statements in the action methods if possible** |
| 188 | + |
| 189 | +### Project Configuration Requirements |
| 190 | +- **Target Framework**: Specify appropriate .NET version in .csproj |
| 191 | +- **AWS SDK packages**: Include specific AWS service NuGet packages |
| 192 | +- **Test packages**: Include xUnit and test runner packages |
| 193 | +- **Configuration**: Support for appsettings.json and environment variables |
| 194 | + |
| 195 | +### Integration with Knowledge Base |
| 196 | +Before creating .NET code examples: |
| 197 | +1. Query `coding-standards-KB` for "DotNet-code-example-standards" |
| 198 | +2. Query `DotNet-premium-KB` for "DotNet implementation patterns" |
| 199 | +3. Follow KB-documented patterns for project structure and class organization |
| 200 | +4. Validate against existing .NET examples only after KB consultation |
0 commit comments