Ejemplo n.º 1
0
        public bool BuildTargetGaugeProject()
        {
            var projectFullPath = GetProjectFullPath();
            var gaugeBinDir     = Utils.GetGaugeBinDir();

            if (IsRunningOnMono() ||
                !string.IsNullOrEmpty(Utils.TryReadEnvValue("GAUGE_CSHARP_BUILD_FAKE")))
            {
                try {
                    Gauge.FSharpHelper.Builder.buildProject(projectFullPath, gaugeBinDir);
                } catch (Exception ex) {
                    Logger.Error(ex, "C# Project build failed {0}", ex.Message);
                    return(false);
                }
                return(true);
            }
            else
            {
                var consoleLogger = new ConsoleLogger(LoggerVerbosity.Quiet);
                try
                {
                    Logger.Debug("Create Gauge Bin Directory: {0}", gaugeBinDir);
                    Directory.CreateDirectory(gaugeBinDir);
                }
                catch (IOException ex)
                {
                    Logger.Fatal(ex, "Unable to create Gauge Bin Directory in {0}", gaugeBinDir);
                    throw;
                }

                Logger.Info("Building Project: {0}", projectFullPath);
                var pc             = new ProjectCollection();
                var globalProperty = new Dictionary <string, string>
                {
                    { "Configuration", "Release" },
                    { "Platform", "Any CPU" },
                    { "OutputPath", gaugeBinDir }
                };

                var buildRequestData = new BuildRequestData(projectFullPath, globalProperty, null, new[] { "Build" }, null);

                var errorCodeAggregator = new ErrorCodeAggregator();
                var buildParameters     = new BuildParameters(pc)
                {
                    Loggers = new ILogger[] { consoleLogger, errorCodeAggregator }
                };

                var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData);

                if (errorCodeAggregator.ErrorCodes.Contains("CS1001"))
                {
                    Logger.Error("You have chosen an invalid folder name to initialize a Gauge project.");
                    Logger.Error("Please choose a project name that complies with C# Project naming conventions.");
                }

                Logger.Info(buildResult.OverallResult);
                return(buildResult.OverallResult == BuildResultCode.Success);
            }
        }
        public bool BuildTargetGaugeProject()
        {
            var consoleLogger    = new ConsoleLogger(LoggerVerbosity.Quiet);
            var solutionFileList = Directory.GetFiles(Utils.GaugeProjectRoot, "*.sln");

            if (!solutionFileList.Any())
            {
                throw new NotAValidGaugeProjectException();
            }
            var solutionFullPath = solutionFileList.First();
            var gaugeBinDir      = Utils.GetGaugeBinDir();

            try
            {
                Logger.Debug("Create Gauge Bin Directory: {0}", gaugeBinDir);
                Directory.CreateDirectory(gaugeBinDir);
            }
            catch (IOException ex)
            {
                Logger.Fatal(ex, "Unable to create Gauge Bin Directory in {0}", gaugeBinDir);
                throw;
            }
            Logger.Info("Building Project: {0}", solutionFullPath);
            var pc             = new ProjectCollection();
            var globalProperty = new Dictionary <string, string>
            {
                { "Configuration", "Release" },
                { "Platform", "Any CPU" },
                { "OutputPath", gaugeBinDir }
            };

            var buildRequestData = new BuildRequestData(solutionFullPath, globalProperty, null, new[] { "Build" }, null);

            var errorCodeAggregator = new ErrorCodeAggregator();
            var buildParameters     = new BuildParameters(pc)
            {
                Loggers = new ILogger[] { consoleLogger, errorCodeAggregator }
            };

            var buildResult = BuildManager.DefaultBuildManager.Build(buildParameters, buildRequestData);

            if (errorCodeAggregator.ErrorCodes.Contains("CS1001"))
            {
                Logger.Error("You have chosen an invalid folder name to initialize a Gauge project.");
                Logger.Error("Please choose a project name that complies with C# Project naming conventions.");
            }

            Logger.Info(buildResult.OverallResult);
            return(buildResult.OverallResult == BuildResultCode.Success);
        }