I would like to measure programmatically the solution load time in Visual Studio. I'm not sure whether is possible or not but I have the following code to try to achieve it:
// See https://aka.ms/new-console-template for more information
using System.Diagnostics;
var stopwatch = new Stopwatch();
stopwatch.Start();
var devEnvPath = @"C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe";
var solutionPath = @"C:\git\my-project\my-project.sln";
var command = $"\"{solutionPath}\"";
var cmdsi = new ProcessStartInfo
{
WindowStyle = ProcessWindowStyle.Normal,
FileName = devEnvPath,
RedirectStandardInput = true,
UseShellExecute = false,
Arguments = command
};
var cmd = Process.Start(cmdsi);
cmd.WaitForExit();
Console.WriteLine($"Took={stopwatch.ElapsedMilliseconds}ms");
The problem I have is that I previously tested fine with the /build
flag and worked fine so I can measure the compile time but if I just want to measure the load time I'm not able to do it unless I manually close the Visual Studio instance that appears when the console app is running. Is there any switch or some handle I can use to try to hook into it and measure?