Esempio n. 1
0
        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 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);
        }