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); }
static async Task <int> Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Console.WriteLine(((Exception)eventArgs.ExceptionObject).ToString()); }; var progressReporter = new ProgressReporter(); var options = OptionsHelper.LoadOptions(args, progressReporter); if (options == null) { return(-1); } var selectedMsBuildInstance = MsBuildHelper.GetMsBuildInstance(progressReporter); if (selectedMsBuildInstance == null) { return(-1); } MSBuildLocator.RegisterInstance(selectedMsBuildInstance); using (var workspace = MsBuildHelper.CreateMsBuildWorkspace(progressReporter)) { var project = await workspace.OpenProjectAsync(options.ProjectPath, progressReporter); var generatorAssemblySearchPaths = options.GetGeneratorPluginsSearchPaths(progressReporter); var generator = new CompilationGenerator(generatorAssemblySearchPaths, options.OutputPath, progressReporter); await generator.Process(project); } return(0); }
public CompilationGenerator(IReadOnlyList <string> generatorAssemblySearchPaths, string intermediateOutputDirectory, ProgressReporter progressReporter) { var generatorPluginProvider = new GeneratorPluginProvider(generatorAssemblySearchPaths); _intermediateOutputDirectory = intermediateOutputDirectory; _progressReporter = progressReporter; _documentTransformer = new DocumentTransformer(generatorPluginProvider, progressReporter); }
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 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); }
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 DocumentTransformer(GeneratorPluginProvider generatorPluginProvider, ProgressReporter errorReporter) { _generatorPluginProvider = generatorPluginProvider; _errorReporter = errorReporter; }