Working with solutions in Visual Studio extensions
Applies to:
Visual Studio
Visual Studio for Mac
Note
This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here
Here's a collection of small code samples on different ways to work with solutions.
Solution events
Listen to any solution event.
VS.Events.SolutionEvents.OnAfterOpenProject += OnAfterOpenProject;
...
private void OnAfterOpenProject(Project obj)
{
// Handle the event
}
Is a solution open?
Check if a solution is currently open or opening.
bool isOpen = await VS.Solutions.IsOpenAsync();
bool isOpening = await VS.Solutions.IsOpeningAsync();
Get all projects in solution
Get a list of all projects in the solution.
var projects = await VS.Solutions.GetAllProjectsAsync();