public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            lock (buildLock)
            {
                var projectFileName = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".csproj");
                var exeFilePath = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".exe");
                var consoleLogger = new MsBuildConsoleLogger(logger);
                var globalProperties = new Dictionary<string, string>();
                var buildRequest = new BuildRequestData(projectFileName, globalProperties, null, new[] { "Build" }, null);
                var buildParameters = new BuildParameters(new ProjectCollection()) { DetailedSummary = false, Loggers = new Microsoft.Build.Framework.ILogger[] { consoleLogger } };
                var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(exeFilePath))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");
                    logger.WriteLineInfo("Let's try to build it via BuildBenchmark.bat!");
                    var buildProcess = new Process
                    {
                        StartInfo =
                        {
                            FileName = Path.Combine(generateResult.DirectoryPath, "BuildBenchmark.bat"),
                            WorkingDirectory = generateResult.DirectoryPath,
                            UseShellExecute = false,
                            RedirectStandardOutput = false,
                        }
                    };
                    buildProcess.Start();
                    buildProcess.WaitForExit();
                    if (File.Exists(exeFilePath))
                        return new BuildResult(generateResult, true, null, exeFilePath);
                }

                return new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success, buildResult.Exception, exeFilePath);
            }
        }
Example #2
0
        private Microsoft.Build.Execution.BuildResult BuildWithManagedApi(ILogger logger, string projectFilePath)
        {
            var consoleLogger    = new MsBuildConsoleLogger(logger);
            var globalProperties = new Dictionary <string, string>();
            var buildRequest     = new BuildRequestData(projectFilePath, globalProperties, null, new[] { "Build" }, null);
            var buildParameters  = new BuildParameters(new ProjectCollection())
            {
                DetailedSummary = false,
                Loggers         = new Microsoft.Build.Framework.ILogger[] { consoleLogger }
            };

            return(BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest));
        }
        private Microsoft.Build.Execution.BuildResult BuildWithManagedApi(ILogger logger, string projectFilePath)
        {
            var consoleLogger = new MsBuildConsoleLogger(logger);
            var globalProperties = new Dictionary<string, string>();
            var buildRequest = new BuildRequestData(projectFilePath, globalProperties, null, new[] { "Build" }, null);
            var buildParameters = new BuildParameters(new ProjectCollection())
            {
                DetailedSummary = false,
                Loggers = new Microsoft.Build.Framework.ILogger[] { consoleLogger }
            };

            return BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);
        }
        private BuildResult BuildWithBat(GenerateResult generateResult, ILogger logger, string exeFilePath)
        {
            logger.WriteLineInfo($"Let's try to build it via {GeneratorBase.BuildBenchmarkScriptFileName}!");

            var buildProcess = new Process
            {
                StartInfo =
                {
                    FileName = Path.Combine(generateResult.DirectoryPath, GeneratorBase.BuildBenchmarkScriptFileName),
                    WorkingDirectory = generateResult.DirectoryPath,
                    UseShellExecute = false,
                    RedirectStandardOutput = false,
                }
            };
            buildProcess.Start();
            buildProcess.WaitForExit();

            return new BuildResult(generateResult, File.Exists(exeFilePath), null, exeFilePath);
        }
Example #5
0
        private BuildResult BuildWithBat(GenerateResult generateResult, ILogger logger, string exeFilePath)
        {
            logger.WriteLineInfo($"Let's try to build it via {GeneratorBase.BuildBenchmarkScriptFileName}!");

            var buildProcess = new Process
            {
                StartInfo =
                {
                    FileName               = Path.Combine(generateResult.DirectoryPath, GeneratorBase.BuildBenchmarkScriptFileName),
                    WorkingDirectory       = generateResult.DirectoryPath,
                    UseShellExecute        = false,
                    RedirectStandardOutput = false,
                }
            };

            buildProcess.Start();
            buildProcess.WaitForExit();

            return(new BuildResult(generateResult, File.Exists(exeFilePath), null, exeFilePath));
        }
Example #6
0
        public BuildResult Build(GenerateResult generateResult, ILogger logger)
        {
            lock (buildLock)
            {
                var projectFileName  = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".csproj");
                var exeFileName      = Path.Combine(generateResult.DirectoryPath, ClassicGenerator.MainClassName + ".exe");
                var consoleLogger    = new MsBuildConsoleLogger(logger);
                var globalProperties = new Dictionary <string, string>();
                var buildRequest     = new BuildRequestData(projectFileName, globalProperties, null, new[] { "Build" }, null);
                var buildParameters  = new BuildParameters(new ProjectCollection())
                {
                    DetailedSummary = false, Loggers = new Microsoft.Build.Framework.ILogger[] { consoleLogger }
                };
                var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequest);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(exeFileName))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");
                    logger.WriteLineInfo("Let's try to build it via BuildBenchmark.bat!");
                    var buildProcess = new Process
                    {
                        StartInfo =
                        {
                            FileName               = Path.Combine(generateResult.DirectoryPath, "BuildBenchmark.bat"),
                            WorkingDirectory       = generateResult.DirectoryPath,
                            UseShellExecute        = false,
                            RedirectStandardOutput = false,
                        }
                    };
                    buildProcess.Start();
                    buildProcess.WaitForExit();
                    if (File.Exists(exeFileName))
                    {
                        return(new BuildResult(generateResult, true, null));
                    }
                }

                return(new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success, buildResult.Exception));
            }
        }
Example #7
0
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            var projectFilePath = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".csproj");
            var executablePath  = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".exe");

            try
            {
                var buildResult = BuildWithManagedApi(logger, projectFilePath);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(executablePath))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");

                    return(BuildWithBat(generateResult, logger, executablePath));
                }

                return(new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success,
                                       buildResult.Exception, executablePath));
            }
            catch (FileLoadException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to load {msBuildDllNotFound.FileName}");

                return(BuildWithBat(generateResult, logger, executablePath));
            }
            catch (FileNotFoundException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to find {msBuildDllNotFound.FileName}");

                return(BuildWithBat(generateResult, logger, executablePath));
            }
            catch (InvalidOperationException exception)
            {
                logger.WriteLine($"Unable to build (InvalidOperationException). More information: {exception.Message}");

                return(BuildWithBat(generateResult, logger, executablePath));
            }
        }
        public BuildResult Build(GenerateResult generateResult, ILogger logger, Benchmark benchmark)
        {
            var projectFilePath = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".csproj");
            var executablePath = Path.Combine(generateResult.DirectoryPath, GeneratorBase.MainClassName + ".exe");

            try
            {
                var buildResult = BuildWithManagedApi(logger, projectFilePath);

                if (buildResult.OverallResult != BuildResultCode.Success && !File.Exists(executablePath))
                {
                    logger.WriteLineInfo("BuildManager.DefaultBuildManager can't build this project. =(");

                    return BuildWithBat(generateResult, logger, executablePath);
                }

                return new BuildResult(generateResult, buildResult.OverallResult == BuildResultCode.Success,
                    buildResult.Exception, executablePath);
            }
            catch (FileLoadException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to load {msBuildDllNotFound.FileName}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
            catch (FileNotFoundException msBuildDllNotFound)
            {
                logger.WriteLineInfo($"Unable to find {msBuildDllNotFound.FileName}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
            catch (InvalidOperationException exception)
            {
                logger.WriteLine($"Unable to build (InvalidOperationException). More information: {exception.Message}");

                return BuildWithBat(generateResult, logger, executablePath);
            }
        }
 public void ExportToLog(Summary summary, BenchmarkDotNet.Loggers.ILogger logger) => ExportCalled = true;