Skip to main content

Definition

Assembly: CloudNimble.EasyAF.MSBuild.dll Namespace: CloudNimble.EasyAF.MSBuild Inheritance: System.Object

Syntax

Summary

Manages MSBuild project files (.csproj, Directory.Build.props, etc.) with formatting preservation capabilities.

Remarks

This class provides comprehensive support for loading, validating, and modifying MSBuild project files while preserving the original formatting (indentation, line breaks). It follows the same pattern as DocsJsonManager for consistency.

Constructors

.ctor

Initializes a new instance of the MSBuildProjectManager class.

Syntax

.ctor

Initializes a new instance of the MSBuildProjectManager class with the specified file path.

Syntax

Parameters

Exceptions

.ctor Inherited

Inherited from object

Syntax

Properties

FilePath

Gets the file path of the loaded project.

Syntax

Property Value

Type: string The absolute path to the project file that was loaded or will be saved to. Returns null if no file path has been specified.

IsLoaded

Gets a value indicating whether a project is successfully loaded.

Syntax

Property Value

Type: bool True if a project is loaded and there are no errors; otherwise, false.

PreserveFormatting

Gets a value indicating whether formatting preservation is enabled.

Syntax

Property Value

Type: bool True if the project was loaded with formatting preservation; otherwise, false.

Project

Gets the loaded MSBuild project root element.

Syntax

Property Value

Type: Microsoft.Build.Construction.ProjectRootElement The ProjectRootElement instance loaded from the file system. Returns null if no project has been loaded or if loading failed.

ProjectErrors

Gets the collection of project loading and processing errors.

Syntax

Property Value

Type: System.Collections.Generic.List<System.CodeDom.Compiler.CompilerError> A list of CompilerError instances representing any errors encountered during project loading, validation, or processing operations.

Methods

AddItemGroup

Adds an ItemGroup with the specified condition and configures it using the provided action.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

AddPackageReference

Adds a PackageReference to the project.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

CreateNew

Creates a new MSBuild project file with default structure.

Syntax

Parameters

Exceptions

EnsureMSBuildRegistered

Ensures MSBuild is registered with the latest available version.

Syntax

Remarks

This method should be called before any MSBuild operations to ensure the correct version of MSBuild is loaded. On .NET Core, QueryVisualStudioInstances() returns SDK instances (versions like 8.0.x, 9.0.x, 10.0.x), not Visual Studio instances. We explicitly select and register the latest available instance.

Equals Inherited Virtual

Inherited from object

Syntax

Parameters

Returns

Type: bool

Equals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

GetHashCode Inherited Virtual

Inherited from object

Syntax

Returns

Type: int

GetPropertyValue

Gets the value of a property from the project.

Syntax

Parameters

Returns

Type: string The property value, or null if the property does not exist.

Exceptions

GetType Inherited

Inherited from object

Syntax

Returns

Type: System.Type

Load

Loads an existing MSBuild project file from the file path specified in the constructor.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

Load

Loads an existing MSBuild project file from the specified file path.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

MemberwiseClone Inherited

Inherited from object

Syntax

Returns

Type: object

ReferenceEquals Inherited

Inherited from object

Syntax

Parameters

Returns

Type: bool

RemoveProperty

Removes a property from the project.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

Save

Saves the current project to the file system using the original file path.

Syntax

Exceptions

Save

Saves the current project to the specified file path.

Syntax

Parameters

Exceptions

SetProperty

Sets a property value in the project.

Syntax

Parameters

Returns

Type: CloudNimble.EasyAF.MSBuild.MSBuildProjectManager The current instance for method chaining.

Exceptions

ToString Inherited Virtual

Inherited from object

Syntax

Returns

Type: string?