DotNetProjectManager class is the central component of DotNET Build Buddy, responsible for generating and updating .NET project files and solution files.
Class Overview
Location:/workspace/source/src/dotnetProjectManager.ts:42
Constructor
new DotNetProjectManager()
Creates a new instance of the project manager.- Sets
workspaceRootfrom the first workspace folder - Initializes XML parser for reading project files
- Initializes XML builder for writing project files
- Creates a
NuGetCompatibilityCheckerinstance - Creates a
NuGetDiagnosticProviderinstance
Public Methods
generateSolutionFile
Generates a Visual Studio solution file that includes all .NET project files in the workspace.Promise that resolves when the solution file is generated
- Finds all project files using
findProjectFiles() - Generates solution content with proper formatting
- Writes
Solution.slnto the workspace root - Shows success/error notification
- Returns early if no workspace folder is found
- Shows informational message if no project files exist
- Displays error message on failure
updateAllProjectFiles
Updates or creates project files based on source files in the workspace and performs NuGet compatibility checks.Promise that resolves when all project files are updated
- Finds all source files (
.cs,.fs,.vb) - Groups files by directory and project type
- Checks existing projects for compatibility issues
- Updates or creates project files for each group
- Preserves existing settings (target framework, packages, etc.)
- Reports compatibility issues and suggests fixes
- Target framework (
TargetFrameworkorTargetFrameworks) - Nullable reference types setting
- Root namespace
- SDK attribute
- Package references
- Custom properties
refreshAllFiles
Performs a complete refresh of both project files and the solution file.Promise that resolves when all files are refreshed
Private Methods
findProjectFiles
Searches for all .NET project files in the workspace.Array of absolute file paths to project files
**/*.csproj(C# projects)**/*.fsproj(F# projects)**/*.vbproj(VB.NET projects)
**/bin/****/obj/****/node_modules/**
findSourceFiles
Searches for all .NET source files in the workspace.Array of absolute file paths to source files
**/*.cs(C# source files)**/*.fs(F# source files)**/*.vb(VB.NET source files)
**/bin/****/obj/****/node_modules/**
groupSourceFilesByDirectory
Groups source files by directory and project type for organization.Array of source file paths
Object mapping group keys (format:
projectType|directory) to file arraysreadProjectFile
Reads and parses an existing project file to extract configuration.Absolute path to the project file
checkAllProjectCompatibility
Checks NuGet package compatibility for all projects in the workspace.- Package reference compatibility checking
- Framework upgrade suggestions
- Inline diagnostic updates
- Compatibility issue reporting
- Uses
NuGetCompatibilityCheckerfor analysis - Uses
NuGetDiagnosticProviderfor inline warnings/errors - Respects configuration settings for caching and API usage
detectTargetFramework
Detects the target framework from existing projects or returns a default.Target framework string (e.g.,
"net8.0", "netcoreapp3.1"), or null if none found"net8.0"
generateProjectContent
Generates the XML content for a project file.Project type:
"csharp", "fsharp", or "vbnet"Array of source file paths relative to the project directory
Directory where the project file will be created
Existing project information to preserve, or null for new projects
Target framework (e.g.,
"net8.0")XML content for the project file
generateSolutionContent
Generates the content for a Visual Studio solution file.Array of project file paths
Solution file content in Visual Studio format
- Solution format version 12.00 (Visual Studio 2022)
- Debug and Release configurations
- Project type GUIDs for C#, F#, and VB.NET
- Unique GUIDs for solution and each project
Type Definitions
ProjectInfo
DotNetVersionInfo
Usage Example
The
DotNetProjectManager automatically handles NuGet compatibility checking if enabled in settings. See NuGetCompatibilityChecker for details.