public static VisualStudioInstance?GetMsBuildInstance(ProgressReporter progressReporter) { var instances = MSBuildLocator.QueryVisualStudioInstances(new VisualStudioInstanceQueryOptions() { DiscoveryTypes = DiscoveryType.DotNetSdk | DiscoveryType.DeveloperConsole | DiscoveryType.VisualStudioSetup }).ToList(); progressReporter.ReportInfo("Available msbuild instances"); foreach (var visualStudioInstance in instances) { progressReporter.ReportInfo($"Selected msbuild {visualStudioInstance.Name} {visualStudioInstance.Version}"); } var selectedMsBuildInstance = instances.FirstOrDefault(); if (selectedMsBuildInstance == null) { progressReporter.ReportInfo("Cannot find VisualStudio instance"); } else { progressReporter.ReportInfo($"Selected msbuild {selectedMsBuildInstance.Name} {selectedMsBuildInstance.Version}"); } return(selectedMsBuildInstance); }
public static MSBuildWorkspace CreateMsBuildWorkspace(ProgressReporter progressReporter) { var properties = new Dictionary <string, string>() { ["SmartGeneratorProcessing"] = "true" }; var msBuildWorkspace = MSBuildWorkspace.Create(properties); msBuildWorkspace.WorkspaceFailed += (o, e) => progressReporter.ReportInfo(e.Diagnostic.Message); return(msBuildWorkspace); }
public static IReadOnlyList <string> GetGeneratorPluginsSearchPaths(this ToolOptions options, ProgressReporter progressReporter) { return(options.GeneratorPaths.Split(";").Where(s => { if (File.Exists(s)) { return true; } progressReporter.ReportInfo($"Cannot find generator plugin file: {s}"); return false; }).Select(Path.GetFullPath).ToList()); }
public static ToolOptions?LoadOptions(string[] args, ProgressReporter progressReporter) { var options = OptionsHelper.ReadOptions(args); if (options == null) { return(null); } OptionsHelper.PrintInfoAboutParameters(options); if (string.IsNullOrWhiteSpace(options.GeneratorPaths)) { progressReporter.ReportInfo("No plugins provided. Generation skipped"); return(null); } return(options); }