Target Framework: net9.0, net10.0
Programmatic interface to dotnet.exe and utilities for parsing .NET project files. Provides helpers for executing dotnet commands, analyzing project structure, and extracting metadata from solution and project files.
Automating .NET build processes and analyzing project files requires executing dotnet.exe and parsing project XML. Atc.DotNet simplifies this by providing:
- DotnetHelper: Locate and execute dotnet.exe programmatically
- DotnetBuildHelper: Build projects and collect compilation errors
- DotnetCsProjFileHelper: Parse and analyze .csproj files
- DotnetNugetHelper: Extract NuGet package references
- VisualStudioSolutionFileHelper: Parse .sln files and extract metadata
- Project Type Detection: Identify console apps, libraries, test projects, etc.
Perfect for:
- Build automation tools
- Code generators analyzing project structure
- CI/CD pipeline utilities
- DevOps tooling for .NET projects
- Project scaffolding and templates
- Dependency analysis tools
dotnet add package Atc.DotNet- .NET 9.0
- Locate dotnet.exe installation directory and executable
- Execute dotnet build with error collection
- Parse .csproj files and extract project type
- Extract NuGet package references from projects
- Parse Visual Studio solution files
- Detect project types (Console, Library, Web, Test, etc.)
- Analyze project dependencies
- Support for both file-based and content-based parsing
- Atc (foundation library)
Utilities for locating and working with dotnet.exe:
GetDotnetDirectory(): Finds the dotnet installation directoryGetDotnetExecutable(): Gets the full path to dotnet.exe
Build automation and error collection:
BuildAndCollectErrors(): Builds project and returns compilation errors
Project file analysis:
PredictProjectType(): Determines project type with file analyticsGetProjectType(): Determines project type from .csproj content
NuGet package analysis:
GetAllPackageReferences(): Extracts all package references from project
Solution file parsing:
GetSolutionFileMetadata(): Extracts metadata from .sln files
Using GetDotnetDirectory() to find the directory path of dotnet.exe / dotnet - depends on the operating system
DirectoryInfo dotnetDirectory = DotnetHelper.GetDotnetDirectory();Using GetDotnetExecutable() to find the file path of dotnet.exe / dotnet - depends on the operating system
FileInfo dotnetFile = DotnetHelper.GetDotnetExecutable();This method build and collect errors if any - 0 errors is the same as a successful build.
Dictionary<string, int> buildErrors = await DotnetBuildHelper.BuildAndCollectErrors(workingDirectory);var workingDirectory = new DirectoryInfo(@"c:\code\myproject");
var runNumber = 5;
var buildFile = new FileInfo(@"c:\code\myproject\mylib.csproj"),
var useNugetRestore = true,
var useConfigurationReleaseMode = true,
var timeoutInSec = 20,
var logPrefix = "BUILD-PREFIX";
var cancellationToken = CancellationToken.None;
Dictionary<string, int> buildErrors = await DotnetBuildHelper.BuildAndCollectErrors(
workingDirectory,
runNumber,
buildFile,
useNugetRestore,
useConfigurationReleaseMode,
timeoutInSec,
logPrefix,
cancellationToken);var file = new FileInfo(@"c:\code\myproject\mylib.csproj"),
DotnetProjectType projectType = DotnetCsProjFileHelper.PredictProjectType(file);Note: PredictProjectType use GetProjectType but extend the determinations with surrounded files analytics as looking into the Program.cs.
var file = new FileInfo(@"c:\code\myproject\mylib.csproj"),
DotnetProjectType projectType = DotnetCsProjFileHelper.GetProjectType(file);var file = new FileInfo(@"c:\code\myproject\mylib.csproj"),
List<DotnetNugetPackageMetadataBase> packages = DotnetNugetHelper.GetAllPackageReferences(file);var file = new FileInfo(@"c:\code\myproject\mylib.csproj"),
var fileContent = File.ReadAllText(file.FullName);
List<DotnetNugetPackageMetadataBase> packages = DotnetNugetHelper.GetAllPackageReferences(fileContent);var file = new FileInfo(@"c:\code\myproject\mylib.sln"),
VisualStudioSolutionFileMetadata metadata = VisualStudioSolutionFileHelper.GetSolutionFileMetadata(file);var file = new FileInfo(@"c:\code\myproject\mylib.sln"),
var fileContent = File.ReadAllText(file.FullName);
VisualStudioSolutionFileMetadata metadata = VisualStudioSolutionFileHelper.GetSolutionFileMetadata(file);Contributions are welcome! Please see the main repository README for contribution guidelines.