| name | dotnet-dev |
| description | Expert guidance for .NET development in this repository. Use this skill for building, testing, debugging, and understanding project structure, coding conventions, dependency injection patterns, and testing practices. |
.NET Development Skills
Expert guidance for .NET development in this repository.
Build & Test Commands
dotnet build ./src/GitVersion.slnx
dotnet build --project ./src/GitVersion.Core/GitVersion.Core.csproj
dotnet test --solution ./src/GitVersion.slnx
dotnet test --project ./src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj
dotnet test --project ./src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj --framework net10.0
dotnet test --project ./src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj --filter "FullyQualifiedName~TestClassName"
dotnet format ./src/GitVersion.slnx
dotnet format --verify-no-changes ./src/GitVersion.slnx
Package Management
This repository uses Central Package Management via Directory.Packages.props.
Adding/Updating Packages
dotnet add ./src/ProjectName/ProjectName.csproj package PackageName
Important: Always update versions in src/Directory.Packages.props, not in individual .csproj files.
Directory.Packages.props Structure
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="PackageName" Version="1.0.0" />
</ItemGroup>
</Project>
Project Structure
src/ - Main solution with production code and tests
new-cli/ - New CLI implementation (separate solution)
build/ - Build automation (Cake-based)
docs/ - Documentation
Key Projects
| Project | Purpose |
|---|
GitVersion.Core | Core version calculation logic |
GitVersion.App | CLI application |
GitVersion.Configuration | Configuration file handling |
GitVersion.Output | Output formatters (JSON, BuildServer) |
GitVersion.BuildAgents | CI/CD platform integrations |
GitVersion.MsBuild | MSBuild task integration |
GitVersion.LibGit2Sharp | Git repository abstraction |
Coding Conventions
Primary Constructors
Prefer primary constructors with readonly field assignments:
internal class BuildAgentResolver(IEnumerable<IBuildAgent> buildAgents, ILogger<BuildAgentResolver> logger) : IBuildAgentResolver
{
private readonly IEnumerable<IBuildAgent> buildAgents = buildAgents.NotNull();
private readonly ILogger<BuildAgentResolver> logger = logger.NotNull();
public IBuildAgent? Resolve()
{
}
}
Dependency Injection
Use constructor injection with ILogger<T> for logging:
public class MyService
{
private readonly ILogger<MyService> logger;
public MyService(ILogger<MyService> logger)
{
this.logger = logger;
}
}
Logging
Use Microsoft.Extensions.Logging with Serilog:
this.logger.LogInformation("Processing {BranchName}", branch.Name);
this.logger.LogWarning("Configuration not found, using defaults");
this.logger.LogError(ex, "Failed to calculate version");
this.logger.LogDebug("Cache hit for {CacheKey}", key);
Nullable Reference Types
All projects use nullable reference types. Handle nullability explicitly:
public string? OptionalProperty { get; set; }
public string RequiredProperty { get; set; } = string.Empty;
File-Scoped Namespaces
Use file-scoped namespaces:
namespace GitVersion;
public class MyClass
{
}
Testing
Test Project Naming
- Test projects mirror source projects:
GitVersion.Core → GitVersion.Core.Tests
Test Frameworks
- NUnit - Primary test framework
- NSubstitute - Mocking framework
- Shouldly - Assertion library
Test Patterns
[TestFixture]
public class MyServiceTests
{
[Test]
public void MethodName_Scenario_ExpectedResult()
{
var service = new MyService();
var result = service.DoSomething();
result.ShouldBe(expected);
}
[TestCase("input1", "expected1")]
[TestCase("input2", "expected2")]
public void MethodName_WithParameters_ReturnsExpected(string input, string expected)
{
var result = service.Process(input);
result.ShouldBe(expected);
}
}
Configuration Files
Supported Names
GitVersion.yml
GitVersion.yaml
.GitVersion.yml
.GitVersion.yaml
Schema Location
JSON schemas are in schemas/ directory for validation.
Build Agents
Build agent integrations write environment variables with GitVersion_ prefix:
Environment.SetEnvironmentVariable($"GitVersion_{name}", value);
Common Tasks
Running the CLI Locally
dotnet run --project src/GitVersion.App
Debugging Tests
dotnet test --project ./src/GitVersion.Core.Tests/GitVersion.Core.Tests.csproj -v detailed
dotnet test --filter "FullyQualifiedName=GitVersion.Core.Tests.MyTest"
Checking for Errors
dotnet build ./src/GitVersion.slnx -warnaserror
Public API Management
This repository
uses Microsoft.CodeAnalysis.PublicApiAnalyzers
to track public API surface.
Rules
PublicAPI.Unshipped.txt: All new or modified public APIs go here
PublicAPI.Shipped.txt: Only deletions are allowed; never add or modify entries directly
Workflow
- When adding new public APIs, they automatically get flagged and should be added to
PublicAPI.Unshipped.txt
- When modifying existing APIs, move the old entry from
PublicAPI.Shipped.txt to PublicAPI.Unshipped.txt (marked as
removed) and add the new signature to PublicAPI.Unshipped.txt
- Only remove entries from
PublicAPI.Shipped.txt when an API is being deleted
- During release, unshipped APIs get moved to shipped via the
mark-shipped.ps1 script