Skip to content

Library written in C# for reading Visual Studio files.

Notifications You must be signed in to change notification settings

bbadjari/vsfile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

94 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VS File

Overview

VS File is a software library written in C# for reading various files used by the Visual Studio integrated development environment (IDE). Certain Visual Studio files, such as solution files, reference other files that may themselves reference other files, forming hierarchical relationships between them. Resolving these references may be necessary for .NET applications that operate on these files outside of the Visual Studio IDE. With minimal programming effort, the VS File library facilitates this need.

Features

  • Read Visual Basic project files (*.vbproj) referenced in Visual Studio solution files (*.sln).
  • Read Visual Basic source files (*.vb) referenced in Visual Basic project files.
  • Read Visual C# project files (*.csproj) referenced in Visual Studio solution files.
  • Read Visual C# source files (*.cs) referenced in Visual C# project files.
  • Read Visual F# project files (*.fsproj) referenced in Visual Studio solution files.
  • Read Visual F# source files (*.fs) referenced in Visual F# project files.
  • Read Visual Basic/C# source files contained in ASP.NET web site directories.
  • Search for supported Visual Studio files using wildcard characters and recursive search.

Requirements

VS File requires that the .NET Framework 4.5 is installed.

Usage

VS File is a library designed to be used in .NET applications as a referenced .NET assembly.

Classes

The following is a description of all of the classes one needs to be familiar with in order to use this library:

VisualStudioFile

  • Represents a Visual Studio file located at a specific file path with a known file extension.
  • Serves as the base class for all supported Visual Studio files.

SolutionFile

  • Represents a Visual Studio solution file.
  • Subclasses the VisualStudioFile class.
  • File extension for this file is ".sln".
  • Used to resolve references to all supported Visual Studio project files.
  • Used to resolve references to ASP.NET web site directories.

ProjectFile

  • Represents a Visual Studio project file.
  • Subclasses the VisualStudioFile class.
  • Serves as the base class for all supported Visual Studio project files.
  • Generic class that specifies the type of Visual Studio source file that is referenced in the specific Visual Studio project file being represented.
  • Used to read Visual Studio project files and resolve references to Visual Studio source files.
  • Skips any auto-generated Visual Studio source files that may be referenced.

SourceFile

  • Represents a Visual Studio source file.
  • Subclasses the VisualStudioFile class.
  • Serves as the base class for all supported Visual Studio source files.

BasicProjectFile

  • Represents a project file for the Visual Basic .NET programming language.
  • Subclasses the ProjectFile class.
  • File extension for this project file is ".vbproj".
  • References Visual Basic source files.

BasicSourceFile

  • Represents a source file written in the Visual Basic .NET programming language.
  • Subclasses the SourceFile class.
  • File extension for this source file is ".vb".

CSharpProjectFile

  • Represents a project file for the Visual C# .NET programming language.
  • Subclasses the ProjectFile class.
  • File extension for this project file is ".csproj".
  • References Visual C# source files.

CSharpSourceFile

  • Represents a source file written in the Visual C# .NET programming language.
  • Subclasses the SourceFile class.
  • File extension for this source file is ".cs".

FSharpProjectFile

  • Represents a project file for the Visual F# .NET programming language.
  • Subclasses the ProjectFile class.
  • File extension for this project file is ".fsproj".
  • References Visual F# source files.

FSharpSourceFile

  • Represents a source file written in the Visual F# .NET programming language.
  • Subclasses the SourceFile class.
  • File extension for this source file is ".fs".

VisualStudioFiles

  • Manages multiple Visual Studio files of varying type.
  • Used to initialize multiple Visual Studio files located in multiple file paths.
  • Supports file paths having wildcard characters (* or ?) in place of file names.
  • Supports searching recursively through file path subdirectories.
  • Supported Visual Studio files are not loaded when initialized.

WebSiteDirectory

  • Represents an ASP.NET web site directory containing files.
  • Used to locate all Visual Basic/C# source files contained in directory path and subdirectories.

Example

The following is a simple example of using some of the above-mentioned classes:

static void PrintSolutionFiles(string filePath)
{
    // Initialize and load Visual Studio solution file at given file path.

    SolutionFile solutionFile = new SolutionFile(filePath);

    solutionFile.Load();

    // Print names of Visual Basic project files referenced in Visual Studio solution file.
    foreach (BasicProjectFile projectFile in solutionFile.BasicProjectFiles)
    {
        Console.WriteLine(projectFile.FileName);

        // Load project file.
        projectFile.Load();

        // Print names of Visual Basic source files referenced in Visual Basic project file.
        foreach (BasicSourceFile sourceFile in projectFile.SourceFiles)
            Console.WriteLine("- " + sourceFile.FileName);
    }

    // Print names of Visual C# project files referenced in Visual Studio solution file.
    foreach (CSharpProjectFile projectFile in solutionFile.CSharpProjectFiles)
    {
        Console.WriteLine(projectFile.FileName);

        // Load project file.
        projectFile.Load();

        // Print names of Visual C# source files referenced in Visual C# project file.
        foreach (CSharpSourceFile sourceFile in projectFile.SourceFiles)
            Console.WriteLine("- " + sourceFile.FileName);
    }
}

A more practical example of using the VS File library can be obtained from: https://github.com/bbadjari/stylecopcli

Releases

The latest release of this software can be obtained from: https://github.com/bbadjari/vsfile

1.3 (1.3.0.0) - February 12, 2022

  • Added format version of Visual Studio solution files in SolutionFile class.
  • ASP.NET web site relative paths referenced in Visual Studio solution files with format version 12.00 or higher now correctly resolved.
  • Added dotnet.yml file containing GitHub Action to build and test solution.
  • Added NUnit unit and integration tests (over 150).
  • Added NuGet package support for managing required external libraries.
  • Upgraded solution and projects to use Visual Studio 2013 and .NET Framework 4.5.
  • Corrections in VisualStudioFile class to ensure platform-specific directory separator character used in file path and current directory used if no directory information in given file path.

1.2.1 (1.2.1.0) - February 5, 2012

  • Web site files in all subdirectories are now loaded in WebSiteDirectory class.

1.2 (1.2.0.0) - December 21, 2011

  • Included generated XML documentation file.
  • Marked assembly to indicate Common Language Specification (CLS) compliance.
  • Added support for ASP.NET web site directories that contain source files.
  • Referenced files are now cleared whenever project files or solution file loaded (i.e. read).
  • Added support for Visual F# project files and source files.

1.1.2 (1.1.2.0) - December 12, 2011

  • Current directory now used when initializing files in VisualStudioFiles class if no directory information in given file path.

1.1.1 (1.1.1.0) - December 5, 2011

  • Full file path is now used when creating source files in ProjectFile class.
  • Added NAnt build file.

1.1 (1.1.0.0) - December 4, 2011

  • Added Project and Source namespaces that contain Visual Studio project files and source files respectively.
  • Added ProjectFile class to serve as base class for Visual Studio project files.
  • Added SourceFile class to serve as base class for Visual Studio source files.
  • Added support for Visual Basic project files and source files.
  • Project files no longer include auto-generated source files.
  • Added VisualStudioFiles class for managing multiple Visual Studio files of varying type. Useful for initializing Visual Studio files located in multiple provided file paths, including file paths containing wildcard characters.

1.0.1 (1.0.1.0) - October 31, 2011

  • Non-Visual C# project files are now skipped when reading solution files in SolutionFile class.

1.0 (1.0.0.0) - August 11, 2011

  • Initial release.

Copyright & License

Copyright (c) 2011-2022 Bernard Badjari

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Library written in C# for reading Visual Studio files.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages