public override void Run(string target)
        {
            if (String.IsNullOrWhiteSpace(target))
            {
                target = "Build";
            }

            string projectFile = this.ProjectFile;

            if (String.IsNullOrEmpty(projectFile))
            {
                throw new InvalidOperationException(
                          "The project file is not specified.");
            }
            if (!File.Exists(projectFile))
            {
                throw new IOException(
                          "The project file does not exists.");
            }

            ProjectCollection projectCollection = new ProjectCollection();

            projectCollection.DefaultToolsVersion = "4.0";

            ProjectTaskLogger buildLogger = new ProjectTaskLogger();

            buildLogger.Verbosity = this.Verbosity;

            if (this.MessageRaised != null)
            {
                buildLogger.MessageRaised +=
                    new BuildMessageEventHandler(this.MessageRaised.Invoke);
            }
            if (this.TargetStarted != null)
            {
                buildLogger.TargetStarted += new TargetStartedEventHandler(
                    this.TargetStarted.Invoke);
            }
            if (this.ProjectFinished != null)
            {
                buildLogger.ProjectFinished +=
                    new ProjectFinishedEventHandler(this.ProjectFinished.Invoke);
            }

            projectCollection.RegisterLogger(buildLogger);

            Project project = projectCollection.LoadProject(projectFile);

            try
            {
                project.Build(target);
            }
            finally
            {
                projectCollection.UnregisterAllLoggers();
            }
        }
예제 #2
0
        public override void Run(string target)
        {
            if (String.IsNullOrWhiteSpace(target))
            {
                target = "Build";
            }

            string projectFile = this.ProjectFile;

            if (String.IsNullOrEmpty(projectFile))
            {
                throw new InvalidOperationException(
                          "The project file is not specified.");
            }
            if (!File.Exists(projectFile))
            {
                throw new IOException(
                          "The project file does not exists.");
            }

            ProjectCollection projectCollection = new ProjectCollection();

            projectCollection.DefaultToolsVersion = "4.0";

            ProjectTaskLogger logger = new ProjectTaskLogger();

            logger.Verbosity = this.Verbosity;

            // We will only listen for the events that are subscribed...
            if (this.ErrorRaised != null)
            {
                logger.ErrorRaised +=
                    new BuildErrorEventHandler(this.ErrorRaised);
            }
            if (this.MessageRaised != null)
            {
                logger.MessageRaised +=
                    new BuildMessageEventHandler(this.MessageRaised);
            }
            if (this.WarningRaised != null)
            {
                logger.WarningRaised +=
                    new BuildWarningEventHandler(this.WarningRaised);
            }

            if (this.TaskStarted != null)
            {
                logger.TaskStarted +=
                    new TaskStartedEventHandler(this.TaskStarted);
            }
            if (this.TaskFinished != null)
            {
                logger.TaskFinished +=
                    new TaskFinishedEventHandler(this.TaskFinished);
            }

            if (this.TargetStarted != null)
            {
                logger.TargetStarted +=
                    new TargetStartedEventHandler(this.TargetStarted);
            }
            if (this.TargetFinished != null)
            {
                logger.TargetFinished +=
                    new TargetFinishedEventHandler(this.TargetFinished);
            }

            if (this.ProjectStarted != null)
            {
                logger.ProjectStarted +=
                    new ProjectStartedEventHandler(this.ProjectStarted);
            }
            if (this.ProjectFinished != null)
            {
                logger.ProjectFinished +=
                    new ProjectFinishedEventHandler(this.ProjectFinished);
            }

            projectCollection.RegisterLogger(logger);

            Project project = projectCollection.LoadProject(projectFile);

            try
            {
                project.Build(target);
            }
            finally
            {
                projectCollection.UnregisterAllLoggers();
            }
        }