How it works...

In this recipe, we wrote a C# console application based on Roslyn Workspaces API to perform various operations on a projects in a solution: add, remove, edit, and display project properties. The rich Workspaces APIs provide you with a powerful object model for analyzing and editing projects and documents in a solution. Let's walk through the code and understand how we implemented these operations:

public static void Main(string[] args){ // Parse arguments to get solution. string slnPath = ParseArguments(args); if (slnPath == null) {  return; } // Create workspace. MSBuildWorkspace workspace = MSBuildWorkspace.Create(); // Open solution within the workspace. Console.WriteLine($"Loading solution '{slnPath}'..."); Solution solution ...

Get Roslyn Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.