Esempio n. 1
0
        public async Task BuildSolution(string target)
        {
            State = AppState.Building;
            BuildStarted?.Invoke(this, EventArgs.Empty);

            var results = new List <Microsoft.Build.Execution.BuildResult>();

            await Task.Factory.StartNew(() =>
            {
                ClearOutput();

                var msbuild = Microsoft.Build.Execution.BuildManager.DefaultBuildManager;
                var projs   = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection;

                projs.AddToolset(new Microsoft.Build.Evaluation.Toolset("Current", Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion), projs, Path.Combine(DotNetInfo.SdkPath, DotNetInfo.SdkVersion)));

                var globalProperties = new Dictionary <string, string>()
                {
                    { "Configuration", SelectedConfiguration },
                    { "PlatformTarget", SelectedPlatform }
                };

                foreach (var proj in this.Workspace.CurrentSolution.Projects)
                {
                    projs.LoadProject(proj.FilePath);
                }

                var parameters = new Microsoft.Build.Execution.BuildParameters(projs);

                var loggers = new List <Microsoft.Build.Framework.ILogger>();
                var cl      = new Microsoft.Build.Logging.ConsoleLogger(Microsoft.Build.Framework.LoggerVerbosity.Normal, new Microsoft.Build.Logging.WriteHandler((s) => MSBuildLog(s)), new Microsoft.Build.Logging.ColorSetter((c) => MSBuildLogSetColor(c)), new Microsoft.Build.Logging.ColorResetter(() => MSBuildLogResetColor()));

                loggers.Add(cl);

                parameters.Loggers = loggers;

                msbuild.BeginBuild(parameters);

                var targets = new[] { target };

                if (!target.Equals("restore", StringComparison.OrdinalIgnoreCase) && !target.Equals("clean", StringComparison.OrdinalIgnoreCase))
                {
                    targets = new[] { "restore", target };
                }

                foreach (var p in Workspace.ProjectInstances)
                {
                    var pinstance   = new Microsoft.Build.Execution.ProjectInstance(p.FullPath, globalProperties, projs.DefaultToolsVersion, projs);
                    var requestData = new Microsoft.Build.Execution.BuildRequestData(pinstance, targets);

                    results.Add(msbuild.BuildRequest(requestData));
                }

                msbuild.EndBuild();
            });

            State = AppState.SolutionReady;
            BuildFinished?.Invoke(this, EventArgs.Empty);
            OnBuildFinished(results);
        }
Esempio n. 2
0
        protected override bool CompileSingle(AbstractBaseGenerator gen, Dictionary<string, string> buildProps, string workingPath, string target)
        {
            try
            {
                using (log4net.NDC.Push("Compiling " + gen.Description))
                {
                    Log.DebugFormat("Loading MsBuild Project");
                    var projectFile = Helper.PathCombine(workingPath, gen.TargetNameSpace, gen.ProjectFileName);
                    var req = new BuildRequestData(
                        projectFile,
                        buildProps,
                        null,
                        new[] { target },
                        null);

                    var logger = new Microsoft.Build.Logging.ConsoleLogger(LoggerVerbosity.Minimal);
                    var buildParameter = new BuildParameters();
                    buildParameter.Loggers = new List<ILogger>() { logger };

                    Log.DebugFormat("Compiling");
                    var result = BuildManager.DefaultBuildManager.Build(buildParameter, req);

                    if (result.OverallResult == BuildResultCode.Success)
                    {
                        return true;
                    }
                    else
                    {
                        Log.ErrorFormat("Failed to compile {0}", gen.Description);
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed compiling " + gen.Description, ex);
                return false;
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Process the noconsole switch and attach or not attach the correct console loggers
        /// </summary>
        internal static void ProcessConsoleLoggerSwitch
        (
            bool noConsoleLogger,
            string[] consoleLoggerParameters,
            List<DistributedLoggerRecord> distributedLoggerRecords,
            LoggerVerbosity verbosity,
            int cpuCount,
            ArrayList loggers
        )
        {
            // the console logger is always active, unless specifically disabled
            if (!noConsoleLogger)
            {
                // A central logger will be created for single proc and multiproc 
                ConsoleLogger logger = new ConsoleLogger(verbosity);
                string consoleParameters = "SHOWPROJECTFILE=TRUE;";

                if ((consoleLoggerParameters != null) && (consoleLoggerParameters.Length > 0))
                {
                    consoleParameters = AggregateParameters(consoleParameters, consoleLoggerParameters);
                }

                if (cpuCount == 1)
                {
                    // We've decided to use the MP logger even in single proc mode.
                    // Switch it on here, rather than in the logger, so that other hosts that use
                    // the existing ConsoleLogger don't see the behavior change in single proc.
                    logger.Parameters = "ENABLEMPLOGGING;" + consoleParameters;
                    loggers.Add(logger);
                }
                else
                {
                    logger.Parameters = consoleParameters;

                    // For performance, register this logger using the forwarding logger mechanism, rather than as an old-style
                    // central logger.
                    DistributedLoggerRecord forwardingLoggerRecord = CreateForwardingLoggerRecord(logger, consoleParameters, verbosity);
                    distributedLoggerRecords.Add(forwardingLoggerRecord);
                }
            }
        }