Project and Solution Management

This section outlines how the switchvsversion tool interacts with projects and solutions.

Project File Management

The switchvsversion tool modifies project files to support framework and version switching. It does this by parsing project files and making changes to the appropriate settings.

Example:

// File: switchvsversion/src/SwitchVSVersion/ProjectFileModifier.cs
          
              private void SetFrameworkVersion(string projectFilePath, string frameworkName, string frameworkVersion)
              {
                  // ...
                  
                  // Get the project file information
                  var projectFile = this.ParseProjectFile(projectFilePath);
                  // ...
          
                  // Set the framework version
                  projectFile.SetFrameworkVersion(frameworkName, frameworkVersion);
          
                  // ...
          
                  // Write the project file changes
                  this.WriteProjectFile(projectFile, projectFilePath);
              }
          

Source: src/SwitchVSVersion/ProjectFileModifier.cs

Solution File Management

The switchvsversion tool can also manage solution files. This includes updating references and project dependencies to support the new framework or version.

Example:

// File: switchvsversion/src/SwitchVSVersion/SolutionFileModifier.cs
          
              public void UpdateSolutionFile(string solutionFilePath, List<string> projectFiles, string frameworkName, string frameworkVersion)
              {
                  // ...
          
                  // Get the solution file information
                  var solutionFile = this.ParseSolutionFile(solutionFilePath);
                  // ...
          
                  // Update the project references
                  solutionFile.UpdateProjectReferences(projectFiles, frameworkName, frameworkVersion);
          
                  // ...
          
                  // Write the solution file changes
                  this.WriteSolutionFile(solutionFile, solutionFilePath);
              }
          

Source: src/SwitchVSVersion/SolutionFileModifier.cs

Framework and Version Options

The switchvsversion tool supports a variety of framework and version options. The specific options available depend on the framework and version being targeted. The supported options can be viewed by running the command switchvsversion --help.

Example:

switchvsversion --help
          
          Usage: switchvsversion [options]
          
          Options:
            -f, --framework <framework>   The framework to switch to (e.g., .NET Framework, .NET Core, .NET 5)
            -v, --version <version>     The version of the framework to switch to (e.g., 4.8, 3.1, 6.0)
            -p, --project <project>     The path to the project file to switch
            -s, --solution <solution>   The path to the solution file to switch
            -h, --help                   Display this help screen.
          

Source: src/SwitchVSVersion/Program.cs