Development Guide¶
Complete guide to developing libraries created with the ConnectSoft Library Template.
Local Development Setup¶
Prerequisites¶
Required:
- .NET SDK 8.0 or later
- .NET SDK 9.0 (for multi-targeting)
- Git
- Code editor (Visual Studio 2022, VS Code, JetBrains Rider)
Optional:
- Python 3.x with pip (for MkDocs documentation)
- SQL LocalDB (for integration tests)
Initial Setup¶
-
Generate Library:
-
Navigate to Directory:
-
Restore Packages:
-
Verify Setup:
IDE Setup¶
Visual Studio 2022¶
-
Open Solution:
- Open
YourLibraryName.slnx(preferred) orYourLibraryName.sln - Visual Studio 2022 v17.14+ required for .slnx support
- Open
-
Configure:
- Ensure .NET 8 and .NET 9 SDKs are installed
- Verify NuGet package sources are configured
-
Build:
- Press
Ctrl+Shift+Bor use Build menu - Solution builds for both
net8.0andnet9.0
- Press
Visual Studio Code¶
- Install Extensions:
- C# Dev Kit (or C# extension)
-
.NET Extension Pack
-
Open Folder:
- File → Open Folder → Select library directory
-
Build:
- Press
Ctrl+Shift+Bor use Terminal:dotnet build
- Press
JetBrains Rider¶
-
Open Solution:
- File → Open → Select
YourLibraryName.slnxor.sln
- File → Open → Select
-
Configure:
- Ensure .NET SDKs are detected
- Configure NuGet feeds if needed
-
Build:
- Press
Ctrl+F9or use Build menu
- Press
Building and Testing¶
Building¶
Build All Projects¶
# Using .slnx (faster)
dotnet build YourLibraryName.slnx
# Using .sln (fallback)
dotnet build YourLibraryName.sln
# Specific configuration
dotnet build -c Release
dotnet build -c Debug
Build Specific Project¶
# Build library project
dotnet build src/YourLibraryName/YourLibraryName.csproj
# Build test project
dotnet build tests/YourLibraryName.UnitTests/YourLibraryName.UnitTests.csproj
Build Specific Framework¶
Testing¶
Run All Tests¶
# Run all tests
dotnet test
# With code coverage
dotnet test --collect:"XPlat Code Coverage"
# Verbose output
dotnet test --verbosity normal
Run Specific Tests¶
# Run tests in specific project
dotnet test tests/YourLibraryName.UnitTests/
# Run specific test class
dotnet test --filter "FullyQualifiedName~MyTestClass"
# Run specific test method
dotnet test --filter "FullyQualifiedName~MyTestClass.MyTestMethod"
Test Filtering¶
# Run tests by category
dotnet test --filter "Category=Integration"
# Run tests by name pattern
dotnet test --filter "Name~Process"
# Exclude tests
dotnet test --filter "FullyQualifiedName!~Integration"
Code Coverage¶
Collect Coverage¶
# Collect coverage
dotnet test --collect:"XPlat Code Coverage"
# Coverage output location
# $(TestResults)/{guid}/coverage.cobertura.xml
View Coverage Report¶
Option 1: ReportGenerator Tool
-
Install tool:
-
Generate report:
-
Open
coverage/index.htmlin browser
Option 2: Visual Studio
- Run tests with coverage
- View Test Explorer → Code Coverage Results
Option 3: JetBrains Rider
- Run tests with coverage
- View Coverage tool window
Code Organization¶
Project Structure¶
Follow the template's feature-based organization:
src/YourLibraryName/
├── YourLibraryName.csproj
├── Options/ # Configuration (if UseOptions=true)
├── Metrics/ # Metrics (if UseMetrics=true)
├── Diagnostics/ # Tracing (if UseActivitySource=true)
└── YourFeature/ # Your custom features
Adding New Features¶
Create Feature Folder¶
- Create folder:
src/YourLibraryName/YourFeature/ - Add classes in namespace:
YourLibraryName.YourFeature - Follow existing patterns
Example: Adding a Cache Feature¶
// src/YourLibraryName/Cache/CacheService.cs
namespace YourLibraryName.Cache
{
public interface ICacheService
{
T? Get<T>(string key);
void Set<T>(string key, T value, TimeSpan expiration);
}
public class CacheService : ICacheService
{
// Implementation
}
}
Namespace Conventions¶
Main Namespace: Matches library name
Feature Namespaces: Feature folders map to namespaces
namespace YourLibraryName.Cache
{
// Cache feature
}
namespace YourLibraryName.Validation
{
// Validation feature
}
Test Namespaces: Mirror source with .UnitTests suffix
Code Style¶
Follow Analyzer Rules¶
The template includes static code analyzers:
- StyleCop.Analyzers
- SonarAnalyzer.CSharp
- Meziantou.Analyzer
Fix Analyzer Issues:
XML Documentation¶
Document all public APIs:
/// <summary>
/// Provides caching functionality for the library.
/// </summary>
/// <remarks>
/// This service implements an in-memory cache with configurable expiration.
/// </remarks>
public class CacheService : ICacheService
{
/// <summary>
/// Gets a value from the cache.
/// </summary>
/// <typeparam name="T">The type of the cached value.</typeparam>
/// <param name="key">The cache key.</param>
/// <returns>The cached value, or <c>null</c> if not found.</returns>
public T? Get<T>(string key)
{
// Implementation
}
}
Debugging¶
Visual Studio Debugging¶
-
Set Breakpoints:
- Click in left margin or press
F9 - Red dot indicates breakpoint
- Click in left margin or press
-
Start Debugging:
- Press
F5or Debug → Start Debugging - Select test project or library project
- Press
-
Debug Tests:
- Right-click test method → Debug Test
- Or use Test Explorer → Debug
-
Debug Options:
- Step Over:
F10 - Step Into:
F11 - Step Out:
Shift+F11 - Continue:
F5
- Step Over:
VS Code Debugging¶
-
Create launch.json:
{ "version": "0.2.0", "configurations": [ { "name": ".NET Core Launch", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "program": "${workspaceFolder}/src/YourLibraryName/bin/Debug/net8.0/YourLibraryName.dll", "args": [], "cwd": "${workspaceFolder}", "stopAtEntry": false }, { "name": ".NET Core Attach", "type": "coreclr", "request": "attach" } ] } -
Debug:
- Press
F5or use Run and Debug view - Set breakpoints and debug
- Press
JetBrains Rider Debugging¶
-
Set Breakpoints:
- Click in left margin or press
Ctrl+F8
- Click in left margin or press
-
Start Debugging:
- Press
Shift+F9or use Run menu - Select configuration (test or application)
- Press
-
Debug Tests:
- Right-click test → Debug
- Or use Unit Test Sessions tool window
Common Debugging Scenarios¶
Debugging Tests¶
[TestMethod]
public void MyTest()
{
// Set breakpoint here
var service = new MyService();
var result = service.DoWork(); // Step into here
Assert.IsNotNull(result);
}
Debugging Library Code¶
- Create a test or console app that uses your library
- Set breakpoints in library code
- Debug the test/app
- Step into library methods
Debugging Configuration Issues¶
// Add logging to see configuration values
var options = serviceProvider.GetRequiredService<IOptions<MyOptions>>();
_logger.LogInformation("Options: {Options}", JsonSerializer.Serialize(options.Value));
Debugging Metrics¶
// Use TestMeterFactory to inspect metrics
var meterFactory = new TestMeterFactory();
var metrics = new MyMetrics(meterFactory);
// Use metrics and inspect TestMeterFactory
Performance Considerations¶
Build Performance¶
- Use .slnx Format: 48% faster than .sln
- Parallel Builds: Enable in IDE settings
- Incremental Builds: Only rebuild changed files
Test Performance¶
- Parallel Execution: Tests run in parallel by default
- Test Filtering: Run only relevant tests during development
- Skip Slow Tests: Use
[Ignore]attribute for slow integration tests
Runtime Performance¶
- Avoid Premature Optimization: Profile first
- Use Appropriate Data Structures: Choose right collection types
- Async/Await: Use for I/O operations
- Caching: Cache expensive computations
Best Practices¶
Code Quality¶
- Write Tests First: TDD approach helps design
- Keep Methods Small: Single responsibility
- Use Meaningful Names: Clear, descriptive names
- Document Public APIs: XML comments for all public members
Dependency Management¶
- Minimize Dependencies: Only include what's needed
- Keep Versions Updated: Regularly update packages
- Use CPM: Central Package Management for consistency
- Review Dependencies: Check for deprecated/vulnerable packages
Testing¶
- Test Coverage: Aim for 70%+ coverage
- Test Organization: Mirror source structure
- Test Naming: Descriptive test method names
- Test Isolation: Each test should be independent
Documentation¶
- Keep README Updated: Document usage and examples
- XML Comments: Document all public APIs
- Code Examples: Include usage examples
- Changelog: Document breaking changes
Troubleshooting¶
Build Errors¶
Error: NETSDK1045: The current .NET SDK does not support targeting .NET 9.0
Fix: Install .NET 9 SDK
Error: NU1101: Unable to find package
Fix:
- Check
nuget.configfor feed configuration - Restore packages:
dotnet restore
Test Errors¶
Error: Tests not found
Fix:
- Verify test project name contains "test"
- Check test project references library project
- Ensure
IsTestProject=truein .csproj
Error: Coverage not collected
Fix:
- Verify
coverlet.collectorpackage reference - Check test run settings file
IDE Issues¶
Issue: IntelliSense not working
Fix:
- Restore packages:
dotnet restore - Rebuild solution
- Restart IDE
Issue: Analyzers not running
Fix:
- Check
Directory.Packages.propsfor analyzer packages - Verify analyzers are not suppressed in
GlobalSuppressions.cs
Related Documentation¶
- Overview - Template overview
- Parameters - Template parameters
- Architecture - Design patterns
- Runbook - CI/CD operations
- Use Cases - Real-world examples