Esempio n. 1
0
        /// <summary>
        /// Attempts to run the Restore target for the current project with a unique evaluation context.
        /// </summary>
        /// <param name="globalProperties">Global properties to use when running the Restore the target.</param>
        /// <param name="result">A value indicating the result of the restore.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the restore.</param>
        /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
        /// <returns>The current <see cref="ProjectCreator" />.</returns>
        public ProjectCreator TryRestore(IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs)
        {
            buildOutput = BuildOutput.Create();

            Restore(globalProperties, buildOutput, out result, out targetOutputs);

            return(this);
        }
Esempio n. 2
0
        /// <summary>
        /// Attempts to build the current project.
        /// </summary>
        /// <param name="restore">A value indicating whether or not the project should be restored before building.</param>
        /// <param name="globalProperties">Global properties to use when building the target.</param>
        /// <param name="result">A value indicating the result of the build.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param>
        /// <returns>The current <see cref="ProjectCreator" />.</returns>
        public ProjectCreator TryBuild(bool restore, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput)
        {
            buildOutput = BuildOutput.Create();

            Build(restore, null, globalProperties, buildOutput, out result, out _);

            return(this);
        }
Esempio n. 3
0
        /// <summary>
        /// Attempts to build the current project.
        /// </summary>
        /// <param name="restore">A value indicating whether or not the project should be restored before building.</param>
        /// <param name="target">The name of the target to build.</param>
        /// <param name="globalProperties">Global properties to use when building the target.</param>
        /// <param name="result">A value indicating the result of the build.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput" /> object that captured the logging from the build.</param>
        /// <returns>The current <see cref="ProjectCreator" />.</returns>
        public ProjectCreator TryBuild(bool restore, string target, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput)
        {
            buildOutput = BuildOutput.Create();

            Build(restore, target.ToArrayWithSingleElement(), globalProperties, buildOutput, out result, out _);

            return(this);
        }
        /// <summary>
        /// Attempts to run the Restore target for the current project with a unique evaluation context.
        /// </summary>
        /// <param name="result">A value indicating the result of the restore.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the restore.</param>
        /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryRestore(out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs)
        {
            Save();

            buildOutput = BuildOutput.Create();

            lock (BuildManager.DefaultBuildManager)
            {
                BuildRequestData restoreRequest = new BuildRequestData(
                    FullPath,
                    new Dictionary <string, string>
                {
                    ["ExcludeRestorePackageImports"] = "true",
                    ["MSBuildRestoreSessionId"]      = Guid.NewGuid().ToString("D"),
                },
                    ProjectCollection.DefaultToolsVersion,
                    targetsToBuild: new[] { "Restore" },
                    hostServices: null,
                    flags: BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports);

                BuildParameters buildParameters = new BuildParameters
                {
                    Loggers = new List <Framework.ILogger>
                    {
                        buildOutput,
                    },
                };

                BuildManager.DefaultBuildManager.BeginBuild(buildParameters);
                try
                {
                    BuildSubmission buildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(restoreRequest);

                    BuildResult buildResult = buildSubmission.Execute();

                    result = buildResult.OverallResult == BuildResultCode.Success;

                    targetOutputs = buildResult.ResultsByTarget;
                }
                finally
                {
                    BuildManager.DefaultBuildManager.EndBuild();
                }
            }

            Project.MarkDirty();

            Project.ReevaluateIfNecessary();

            return(this);
        }
        /// <summary>
        /// Attempts to build the current project.
        /// </summary>
        /// <param name="restore">A value indicating whether or not the project should be restored before building.</param>
        /// <param name="target">The name of the target to build.</param>
        /// <param name="result">A value indicating the result of the build.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryBuild(bool restore, string target, out bool result, out BuildOutput buildOutput)
        {
            if (restore)
            {
                TryRestore(out result, out buildOutput);

                if (!result)
                {
                    return(this);
                }
            }
            else
            {
                buildOutput = BuildOutput.Create();
            }

            Build(target.ToArrayWithSingleElement(), buildOutput, out result, out _);

            return(this);
        }
        /// <summary>
        /// Attempts to build the current project.
        /// </summary>
        /// <param name="restore">A value indicating whether or not the project should be restored before building.</param>
        /// <param name="targets">The names of the targets to build.</param>
        /// <param name="result">A value indicating the result of the build.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
        /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryBuild(bool restore, string[] targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs)
        {
            if (restore)
            {
                TryRestore(out result, out buildOutput, out targetOutputs);

                if (!result)
                {
                    return(this);
                }
            }
            else
            {
                buildOutput = BuildOutput.Create();
            }

            Build(targets, buildOutput, out result, out targetOutputs);

            return(this);
        }
        /// <summary>
        /// Attempts to build the current project.
        /// </summary>
        /// <param name="restore">A value indicating whether or not the project should be restored before building.</param>
        /// <param name="result">A value indicating the result of the build.</param>
        /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryBuild(bool restore, out bool result, out BuildOutput buildOutput)
        {
            if (restore)
            {
                TryRestore(out result, out buildOutput);

                if (!result)
                {
                    return(this);
                }
            }
            else
            {
                buildOutput = BuildOutput.Create();
            }

            Build(null, buildOutput, out result, out _);

            return(this);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets a <see cref="Project"/> instance from the current project.
        /// </summary>
        /// <param name="project">Receives the <see cref="Project"/> instance.</param>
        /// <param name="buildOutput">Receives <see cref="BuildOutput"/> instance.</param>
        /// <param name="globalProperties">Optional <see cref="IDictionary{String, String}"/> containing global properties.</param>
        /// <param name="toolsVersion">Optional tools version.</param>
        /// <param name="projectCollection">Optional <see cref="ProjectCollection"/> to use.  Defaults to <code>ProjectCollection.GlobalProjectCollection</code>.</param>
        /// <param name="projectLoadSettings">Optional <see cref="ProjectLoadSettings"/> to use.  Defaults to <see cref="ProjectLoadSettings.Default"/>.</param>
        /// <returns>The current <see cref="ProjectCreator"/>.</returns>
        public ProjectCreator TryGetProject(
            out Project project,
            out BuildOutput buildOutput,
            IDictionary <string, string> globalProperties = null,
            string toolsVersion = null,
            ProjectCollection projectCollection     = null,
            ProjectLoadSettings projectLoadSettings = ProjectLoadSettings.Default)
        {
            buildOutput = BuildOutput.Create();

            projectCollection = projectCollection ?? new ProjectCollection();

            projectCollection.RegisterLogger(buildOutput);

            project = new Project(
                RootElement,
                globalProperties,
                toolsVersion,
                projectCollection,
                projectLoadSettings);

            return(this);
        }
        private void Build(string[] targets, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult> targetOutputs)
        {
            buildOutput = BuildOutput.Create();

            Build(targets, buildOutput, out result, out targetOutputs);
        }
Esempio n. 10
0
        private void Build(string[]?targets, IDictionary <string, string>?globalProperties, out bool result, out BuildOutput buildOutput, out IDictionary <string, TargetResult>?targetOutputs)
        {
            buildOutput = BuildOutput.Create();

            Build(restore: false, targets, globalProperties, buildOutput, out result, out targetOutputs);
        }