Beispiel #1
0
        private void Restore(IDictionary <string, string>?globalProperties, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult> targetOutputs)
        {
            Save();

            // IMPORTANT: Make a copy of the global properties here so as not to modify the ones passed in
            Dictionary <string, string> restoreGlobalProperties = new Dictionary <string, string>(globalProperties ?? ProjectCollection.GlobalProperties);

            restoreGlobalProperties["ExcludeRestorePackageImports"] = "true";
            restoreGlobalProperties["MSBuildRestoreSessionId"]      = Guid.NewGuid().ToString("D");

            BuildResult buildResult = BuildManagerHost.Build(
                FullPath,
                new[] { "Restore" },
                restoreGlobalProperties,
                new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())),
                BuildRequestDataFlags.ClearCachesAfterBuild | BuildRequestDataFlags.SkipNonexistentTargets | BuildRequestDataFlags.IgnoreMissingEmptyAndInvalidImports);

            targetOutputs = buildResult.ResultsByTarget;

            if (buildResult.Exception != null)
            {
                throw buildResult.Exception;
            }

            result = buildResult.OverallResult == BuildResultCode.Success;
        }
Beispiel #2
0
        private void Build(bool restore, string[]?targets, IDictionary <string, string>?globalProperties, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult>?targetOutputs)
        {
            targetOutputs = null;

            if (restore)
            {
                Restore(globalProperties, buildOutput, out result, out targetOutputs);

                if (!result)
                {
                    return;
                }
            }

            ProjectInstance projectInstance;

            if (globalProperties != null)
            {
                TryGetProject(out Project project, globalProperties);

                projectInstance = project.CreateProjectInstance();
            }
            else
            {
                projectInstance = ProjectInstance;
            }

            BuildResult buildResult = BuildManagerHost.Build(
                projectInstance,
                targets !,
                globalProperties !,
                new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())),
                BuildRequestDataFlags.None);

            result = buildResult.OverallResult == BuildResultCode.Success;

            if (targetOutputs != null)
            {
                foreach (KeyValuePair <string, TargetResult> targetResult in buildResult.ResultsByTarget)
                {
                    targetOutputs[targetResult.Key] = targetResult.Value;
                }
            }
            else
            {
                targetOutputs = buildResult.ResultsByTarget;
            }
        }
        private void Build(string[] targets, BuildOutput buildOutput, out bool result, out IDictionary <string, TargetResult> targetOutputs)
        {
            lock (BuildManager.DefaultBuildManager)
            {
                BuildRequestData restoreRequest = new BuildRequestData(
                    ProjectInstance,
                    targetsToBuild: targets ?? ProjectInstance.DefaultTargets.ToArray(),
                    hostServices: null,
                    flags: BuildRequestDataFlags.ReplaceExistingProjectInstance);

                BuildParameters buildParameters = new BuildParameters
                {
                    Loggers = new List <Framework.ILogger>(ProjectCollection.Loggers.Concat(buildOutput.AsEnumerable())),
                };

                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();
                }
            }
        }