Kysect.DotnetProjectSystem 1.0.0

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package Kysect.DotnetProjectSystem --version 1.0.0
NuGet\Install-Package Kysect.DotnetProjectSystem -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Kysect.DotnetProjectSystem" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Kysect.DotnetProjectSystem --version 1.0.0
#r "nuget: Kysect.DotnetProjectSystem, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Kysect.DotnetProjectSystem as a Cake Addin
#addin nuget:?package=Kysect.DotnetProjectSystem&version=1.0.0

// Install Kysect.DotnetProjectSystem as a Cake Tool
#tool nuget:?package=Kysect.DotnetProjectSystem&version=1.0.0

Kysect.DotnetProjectSystem

codecov Mutation testing badge

DotnetProjectSystem is a nuget package for working with .sln, .csproj and .props files.

Main features

  • Creating solution and project files structure from code, fluent API
  • Parsing solution and project files
  • Typed wrappers for reading and modifying solution and project files
  • API for modifying solution and project files. Implementation of strategy for migration solution to Central Package Management
  • Support of TestableIO.System.IO.Abstractions for testing

Creating solution and project files structure

  • Task: create solution file, project files and Directory.Build.props file.
  • Use case: need to create sample solution for test proposes (on real file system or MockFileSystem).

Code sample for creating solution and project files structure:

var factory = new SolutionFileStructureBuilderFactory(fileSystem, syntaxFormatter);

var project =
    new ProjectFileStructureBuilder("FirstProject")
        .SetContent("""
                    <Project>
                      <PropertyGroup>
                        <TargetFramework>net8.0</TargetFramework>
                      </PropertyGroup>
                    </Project>
                    """)
        .AddFile(["Models", "MyModel.cs"], "using System;");

var directoryBuildPropsFile = DirectoryBuildPropsFile.CreateEmpty();
directoryBuildPropsFile.File.Properties.SetProperty("Company", "Kysect");

factory.Create("NewSolution")
    .AddProject(project)
    .AddDirectoryBuildProps(directoryBuildPropsFile)
    .Save(@"D:\Repositories\NewSolution");

will create this file structure:

D:\Repositories\NewSolution\
|- FirstProject/
   |- FirstProject.csproj
   |- Models
      |- MyModel.cs
|- Directory.Build.props
|- NewSolution.sln

Parsing solution and project files

Nuget provide API for parsing .sln and .csproj files:

string solutionFilePath = ...;
var parser = new DotnetSolutionParser(_fileSystem, logger);
var result = parser.Parse(solutionFilePath);

Parse method return model DotnetSolutionDescriptor that contains information about projects. Project represented by DotnetProjectFile model that provide access to project properties and items.

Typed wrappers for reading and modifying solution and project files

Some samples for working with DotnetProjectFile:

DotnetProjectFile project = ...;
var packageReferences = project.PackageReferences.GetPackageReferences();
// packageReferences = { { "System.Text.Json", "8.0.0" }, { "Microsoft.Extensions.Logging", "8.0.0" } }

project.PackageReferences.SetPackageReference("System.Text.Json", "9.0.0");
// packageReferences = { { "System.Text.Json", "9.0.0" }, { "Microsoft.Extensions.Logging", "8.0.0" }

project.PackageReferences.AddPackageReference("Kysect.Editorconfig", "1.0.0");

var implicitUsings = project.Properties.GetProperty("ImplicitUsings");
// implicitUsings = true
project.Properties.SetProperty("ImplicitUsings", "false");
// implicitUsings = false

API for modifying solution and project files

Nuget provide API for modification of parsed solution. NuGet package shipped with implementation of strategy for migration solution to Central Package Management as sample.

string solutionFilePath = ...;
var factory = new DotnetSolutionModifierFactory(_fileSystem, _solutionFileContentParser, _formatter);
var solutionModifier = _solutionModifierFactory.Create(solutionFilePath);
var migrator = new CentralPackageManagementMigrator(logger);

migrator.Migrate(solutionModifier);

Support of TestableIO.System.IO.Abstractions

TestableIO.System.IO.Abstractions is NuGet that provide abstraction for file system. This abstraction can be used for testing. Nuget provide implementation of IFileSystem for TestableIO.System.IO.Abstractions. Kysect.DotnetProjectSystem fully support this abstraction.

Used by

Currently main use case for this library is https://github.com/kysect/Zeya - tool for managing .NET projects and modification them. You can check it for more examples of using this library.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 46 5/5/2024
0.1.16 127 3/28/2024
0.1.15 74 3/27/2024
0.1.14 121 3/17/2024
0.1.13 109 3/17/2024
0.1.12 88 3/8/2024
0.1.11 185 2/10/2024
0.1.10 114 1/28/2024
0.1.9 74 1/28/2024
0.1.8 80 1/28/2024
0.1.7 74 1/27/2024
0.1.6 69 1/27/2024
0.1.5 74 1/27/2024
0.1.4 69 1/27/2024
0.1.3 70 1/27/2024
0.1.2 71 1/27/2024
0.1.1 74 1/27/2024
0.1.0 75 1/23/2024