This library contains extensions to wrap the usage of dotnet.exe
from .NET code, extract metadata from .sln
and .csproj
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);