Skip to main content
The 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
export class DotNetProjectManager {
    private workspaceRoot: string;
    private parser: xml2js.Parser;
    private builder: xml2js.Builder;
    private compatibilityChecker: NuGetCompatibilityChecker;
    private diagnosticProvider: NuGetDiagnosticProvider;

    constructor();
}

Constructor

new DotNetProjectManager()

Creates a new instance of the project manager.
constructor()
Initialization:
  • Sets workspaceRoot from the first workspace folder
  • Initializes XML parser for reading project files
  • Initializes XML builder for writing project files
  • Creates a NuGetCompatibilityChecker instance
  • Creates a NuGetDiagnosticProvider instance
Example:
import { DotNetProjectManager } from './dotnetProjectManager';

const projectManager = new DotNetProjectManager();

Public Methods

generateSolutionFile

Generates a Visual Studio solution file that includes all .NET project files in the workspace.
public async generateSolutionFile(): Promise<void>
Returns
Promise<void>
Promise that resolves when the solution file is generated
Implementation Details:
  1. Finds all project files using findProjectFiles()
  2. Generates solution content with proper formatting
  3. Writes Solution.sln to the workspace root
  4. Shows success/error notification
Example Usage:
const manager = new DotNetProjectManager();
await manager.generateSolutionFile();
Error Handling:
  • 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.
public async updateAllProjectFiles(): Promise<void>
Returns
Promise<void>
Promise that resolves when all project files are updated
Implementation Details:
  1. Finds all source files (.cs, .fs, .vb)
  2. Groups files by directory and project type
  3. Checks existing projects for compatibility issues
  4. Updates or creates project files for each group
  5. Preserves existing settings (target framework, packages, etc.)
  6. Reports compatibility issues and suggests fixes
Example Usage:
const manager = new DotNetProjectManager();
await manager.updateAllProjectFiles();
What Gets Preserved:
  • Target framework (TargetFramework or TargetFrameworks)
  • 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.
public async refreshAllFiles(): Promise<void>
Returns
Promise<void>
Promise that resolves when all files are refreshed
Implementation:
public async refreshAllFiles(): Promise<void> {
    await this.updateAllProjectFiles();
    await this.generateSolutionFile();
}
Example Usage:
const manager = new DotNetProjectManager();
await manager.refreshAllFiles();

Private Methods

findProjectFiles

Searches for all .NET project files in the workspace.
private async findProjectFiles(): Promise<string[]>
return
string[]
Array of absolute file paths to project files
Search Patterns:
  • **/*.csproj (C# projects)
  • **/*.fsproj (F# projects)
  • **/*.vbproj (VB.NET projects)
Excluded Patterns:
  • **/bin/**
  • **/obj/**
  • **/node_modules/**

findSourceFiles

Searches for all .NET source files in the workspace.
private async findSourceFiles(): Promise<string[]>
return
string[]
Array of absolute file paths to source files
Search Patterns:
  • **/*.cs (C# source files)
  • **/*.fs (F# source files)
  • **/*.vb (VB.NET source files)
Excluded Patterns:
  • **/bin/**
  • **/obj/**
  • **/node_modules/**

groupSourceFilesByDirectory

Groups source files by directory and project type for organization.
private groupSourceFilesByDirectory(sourceFiles: string[]): Record<string, string[]>
sourceFiles
string[]
required
Array of source file paths
return
Record<string, string[]>
Object mapping group keys (format: projectType|directory) to file arrays
Example:
{
  "csharp|/workspace/src/Api": ["/workspace/src/Api/Controller.cs"],
  "csharp|/workspace/src/Services": ["/workspace/src/Services/UserService.cs"],
  "fsharp|/workspace/src/Functions": ["/workspace/src/Functions/Handler.fs"]
}

readProjectFile

Reads and parses an existing project file to extract configuration.
private async readProjectFile(projectPath: string): Promise<ProjectInfo>
projectPath
string
required
Absolute path to the project file
return
ProjectInfo
interface ProjectInfo {
    targetFramework?: string;
    targetFrameworks?: string[];
    nullable?: string;
    rootNamespace?: string;
    sdk?: string;
    customProperties?: Record<string, string>;
    packageReferences?: Array<{ Include: string; Version?: string }>;
    customItemGroups?: string[];
}

checkAllProjectCompatibility

Checks NuGet package compatibility for all projects in the workspace.
private async checkAllProjectCompatibility(): Promise<void>
Performs:
  • Package reference compatibility checking
  • Framework upgrade suggestions
  • Inline diagnostic updates
  • Compatibility issue reporting
Integration:
  • Uses NuGetCompatibilityChecker for analysis
  • Uses NuGetDiagnosticProvider for inline warnings/errors
  • Respects configuration settings for caching and API usage

detectTargetFramework

Detects the target framework from existing projects or returns a default.
private async detectTargetFramework(): Promise<string | null>
return
string | null
Target framework string (e.g., "net8.0", "netcoreapp3.1"), or null if none found
Default: "net8.0"

generateProjectContent

Generates the XML content for a project file.
private generateProjectContent(
    projectType: string,
    sourceFiles: string[],
    projectDir: string,
    existingInfo: ProjectInfo | null,
    targetFramework: string
): string
projectType
string
required
Project type: "csharp", "fsharp", or "vbnet"
sourceFiles
string[]
required
Array of source file paths relative to the project directory
projectDir
string
required
Directory where the project file will be created
existingInfo
ProjectInfo | null
required
Existing project information to preserve, or null for new projects
targetFramework
string
required
Target framework (e.g., "net8.0")
return
string
XML content for the project file

generateSolutionContent

Generates the content for a Visual Studio solution file.
private generateSolutionContent(projectFiles: string[]): string
projectFiles
string[]
required
Array of project file paths
return
string
Solution file content in Visual Studio format
Generated Structure:
  • 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

interface ProjectInfo {
    targetFramework?: string;
    targetFrameworks?: string[];
    nullable?: string;
    rootNamespace?: string;
    sdk?: string;
    customProperties?: Record<string, string>;
    packageReferences?: Array<{ Include: string; Version?: string }>;
    customItemGroups?: string[];
}

DotNetVersionInfo

interface DotNetVersionInfo {
    type: 'net' | 'netcoreapp' | 'netframework' | 'netstandard';
    version?: string;
    fullTargetFramework: string;
}

Usage Example

import * as vscode from 'vscode';
import { DotNetProjectManager } from './dotnetProjectManager';

export function activate(context: vscode.ExtensionContext) {
    const projectManager = new DotNetProjectManager();

    // Register commands
    context.subscriptions.push(
        vscode.commands.registerCommand(
            'myextension.updateProjects',
            async () => {
                await projectManager.updateAllProjectFiles();
            }
        )
    );
}
The DotNetProjectManager automatically handles NuGet compatibility checking if enabled in settings. See NuGetCompatibilityChecker for details.

Build docs developers (and LLMs) love