Created
April 29, 2020 20:35
-
-
Save jmarolf/97d0d388efbc0096ab268fedec2bb8f0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net472</TargetFramework> | |
<LangVersion>8.0</LangVersion> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Build.Locator" Version="1.2.6" /> | |
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.5.0" /> | |
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="3.5.0" /> | |
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="3.5.0" /> | |
</ItemGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Linq; | |
using System.Threading.Tasks; | |
using Microsoft.Build.Locator; | |
using Microsoft.CodeAnalysis.MSBuild; | |
namespace ConsoleApp { | |
class Program { | |
static async Task Main(string[] args) { | |
var visualStudioInstances = MSBuildLocator.QueryVisualStudioInstances().First(); | |
MSBuildLocator.RegisterInstance(visualStudioInstances); | |
using var workspace = MSBuildWorkspace.Create(); | |
workspace.WorkspaceFailed += (o, e) => Console.WriteLine(e.Diagnostic.Message); | |
var solutionPath = args[0]; | |
var solution = await workspace.OpenSolutionAsync(solutionPath, new ConsoleProgressReporter()); | |
} | |
private class ConsoleProgressReporter : IProgress<ProjectLoadProgress> { | |
public void Report(ProjectLoadProgress loadProgress) { | |
var projectDisplay = Path.GetFileName(loadProgress.FilePath); | |
if (loadProgress.TargetFramework != null) { | |
projectDisplay += $" ({loadProgress.TargetFramework})"; | |
} | |
Console.WriteLine($"{loadProgress.Operation,-15} {loadProgress.ElapsedTime,-15:m\\:ss\\.fffffff} {projectDisplay}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment