/// <summary>
        /// Builds the project - based on http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.engine.aspx.
        /// </summary>
        /// <param name="projectPath">The project (csproj) path</param>
        /// <returns>True if builds okay</returns>
        private static bool BuildProject(string projectPath)
        {
            var logPath = Path.Combine(Path.GetDirectoryName(projectPath), "build.log");

            //.Net 4 Microsoft.Build.Evaluation.Project and ProjectCollection
            var engine = new ProjectCollection();

            // Instantiate a new FileLogger to generate build log
            var logger = new Microsoft.Build.Logging.FileLogger();

            // Set the logfile parameter to indicate the log destination
            logger.Parameters = @"logfile=" + logPath;

            // Register the logger with the engine
            engine.RegisterLogger(logger);

            // Build a project file
            bool success = engine.LoadProject(projectPath).Build();
            //Unregister all loggers to close the log file
            engine.UnregisterAllLoggers();

            //if fails, put the log file into the assert statement
            string txt = "Should have built";
            if (!success && File.Exists(logPath))
                txt = File.ReadAllText(logPath);
            Console.WriteLine(txt);

            return success;
        }
Beispiel #2
0
        /// <summary>
        /// Builds the project - based on http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.engine.aspx.
        /// </summary>
        /// <param name="projectPath">The project (csproj) path</param>
        /// <returns>True if builds okay</returns>
        private static bool BuildProject(string projectPath)
        {
            var logPath = Path.Combine(Path.GetDirectoryName(projectPath), "build.log");

            //.Net 4 Microsoft.Build.Evaluation.Project and ProjectCollection
            var engine = new ProjectCollection();

            // Instantiate a new FileLogger to generate build log
            var logger = new Microsoft.Build.Logging.FileLogger();

            // Set the logfile parameter to indicate the log destination
            logger.Parameters = @"logfile=" + logPath;

            // Register the logger with the engine
            engine.RegisterLogger(logger);

            // Build a project file
            bool success = engine.LoadProject(projectPath).Build();

            //Unregister all loggers to close the log file
            engine.UnregisterAllLoggers();

            //if fails, put the log file into the assert statement
            string txt = "Built " + Path.GetFileName(projectPath);

            if (!success && File.Exists(logPath))
            {
                txt = File.ReadAllText(logPath);
            }
            Console.WriteLine(txt);

            return(success);
        }
Beispiel #3
0
        /// <summary>
        /// Add a file logger with the appropriate parameters to the loggers list for each
        /// non-empty set of file logger parameters provided.
        /// </summary>
        private static void ProcessFileLoggers(string[][] groupedFileLoggerParameters, List<DistributedLoggerRecord> distributedLoggerRecords, LoggerVerbosity verbosity, int cpuCount, ArrayList loggers)
        {
            for (int i = 0; i < groupedFileLoggerParameters.Length; i++)
            {
                // If we had no, say, "/fl5" then continue; we may have a "/fl6" and so on
                if (groupedFileLoggerParameters[i] == null) continue;

                string fileParameters = "SHOWPROJECTFILE=TRUE;";
                // Use a default log file name of "msbuild.log", "msbuild1.log", "msbuild2.log", etc; put this first on the parameter
                // list so that any supplied log file parameter will override it 
                if (i == 0)
                {
                    fileParameters += "logfile=msbuild.log;";
                }
                else
                {
                    fileParameters += "logfile=msbuild" + i + ".log;";
                }

                if (groupedFileLoggerParameters[i].Length > 0)
                {
                    // Join the file logger parameters into one string seperated by semicolons
                    fileParameters = AggregateParameters(fileParameters, groupedFileLoggerParameters[i]);
                }

                FileLogger fileLogger = new FileLogger();
                // Set to detailed by default, can be overidden by fileLoggerParameters
                LoggerVerbosity defaultFileLoggerVerbosity = LoggerVerbosity.Detailed;
                fileLogger.Verbosity = defaultFileLoggerVerbosity;

                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.
                    fileLogger.Parameters = "ENABLEMPLOGGING;" + fileParameters;
                    loggers.Add(fileLogger);
                }
                else
                {
                    fileLogger.Parameters = fileParameters;

                    // For performance, register this logger using the forwarding logger mechanism, rather than as an old-style
                    // central logger.
                    DistributedLoggerRecord forwardingLoggerRecord = CreateForwardingLoggerRecord(fileLogger, fileParameters, defaultFileLoggerVerbosity);
                    distributedLoggerRecords.Add(forwardingLoggerRecord);
                }
            }
        }
Beispiel #4
0
        private void windowsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ComponentTypeContainer.UnloadAppDomain();
                //string msBuildPath = @"C:\Windows\Microsoft.NET\Framework\v3.5\";

                // Instantiate a new FileLogger to generate build log
                Microsoft.Build.Logging.FileLogger logger = new Microsoft.Build.Logging.FileLogger();                

                // Set the logfile parameter to indicate the log destination
                logger.Parameters = @"logfile=C:\temp\build.log";

                // Register the logger with the engine
                //engine.RegisterLogger(logger);

                String projectPath = Path.Combine(_currentProject.Path, _currentProject.VisualStudioProjectPath);
                Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(projectPath);

                //BuildRequestData buildRequest = new BuildRequestData

                //bool success=p.Build("Rebuild");
                bool success = p.Build(logger); 
                if (!success)
                {
                    DialogResult _res = MessageBox.Show("There was an error during build, Would you like to see the log?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (_res == DialogResult.Yes)
                    {
                        if (File.Exists(@"c:\temp\build.log"))
                            Process.Start("notepad.exe", @"c:\temp\build.log");
                        else
                            MessageBox.Show("Log file not found");
                    }
                }
            }
            catch (Exception err)
            {
                MilkshakeForm.ShowErrorMessage(err);
            }
        }