Visual Studio Project Parsing
The FindOrphanedItems.Core.Project
namespace is responsible for parsing Visual Studio project files (.vcproj, .csproj). This is crucial for identifying orphaned files, which are files that are included in the project but do not exist on disk.
Parsing Logic
The parsing logic is implemented in the Project
class.
- Project Types: The code supports parsing different project types, identified by the file extension.
- Version Handling: The code handles different versions of Visual Studio project files, primarily .vcproj and .csproj files. The project file format has evolved over time, so the parsing logic needs to adapt.
Key Functionality:
- Dependency Extraction: The code extracts project dependencies, including references to other projects.
- File References: The code extracts file references from the project files.
- Build Configuration Information: The code extracts build configuration information, such as platform and configuration settings.
Usage
The Project
class provides the following methods for interacting with project files:
LoadProjectFile(string projectFilePath)
: Loads a project file and parses its contents.GetDependencies()
: Returns a list of project dependencies.GetFileReferences()
: Returns a list of file references.GetConfiguration(string platform, string configuration)
: Returns build configuration information for a specific platform and configuration.
Example
using FindOrphanedItems.Core.Project;
// Load a Visual Studio project file
Project project = new Project();
project.LoadProjectFile("path/to/project.vcproj");
// Get project dependencies
List<string> dependencies = project.GetDependencies();
// Get file references
List<string> fileReferences = project.GetFileReferences();
// Get build configuration information
ProjectConfiguration configuration = project.GetConfiguration("Win32", "Release");
Project Structure
The FindOrphanedItems.Core.Project
namespace includes the following classes:
Project
: The main class responsible for parsing project files.ProjectDependency
: Represents a project dependency.ProjectFileReference
: Represents a file reference in a project file.ProjectConfiguration
: Represents build configuration information for a project.
Documentation Sources
- https://github.com/stevedunn/find-visual-studio-orphaned-items/
- https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-project-file-schema?view=vs-2022
- https://docs.microsoft.com/en-us/visualstudio/msbuild/understanding-msbuild-project-files?view=vs-2022
- FindOrphanedItems.Core/Project/Project.cs