Beispiel #1
0
 public PluginTargetResult(
     string targetName,
     IReadOnlyCollection <ITaskItem2> taskItems,
     BuildResultCode resultCode)
 {
     TargetName = targetName;
     TaskItems  = taskItems;
     ResultCode = resultCode;
 }
Beispiel #2
0
        public void CacheAndUndeclaredReferenceEnforcementShouldAcceptSelfReferences(BuildResultCode expectedBuildResult, string[] targets)
        {
            AssertBuild(targets,
                        (result, logger) =>
            {
                result.OverallResult.ShouldBe(expectedBuildResult);

                logger.Errors.ShouldBeEmpty();
            });
        }
        /// <summary>
        /// Checks that building the specified target produced the expected result.
        /// </summary>
        public static void AssertExpectedTargetOutput(BuildResult result, string target, BuildResultCode resultCode)
        {
            DumpTargetResult(result, target);

            TargetResult targetResult;
            if (!result.ResultsByTarget.TryGetValue(target, out targetResult))
            {
                Assert.Inconclusive(@"Could not find result for target ""{0}""", target);
            }
            Assert.AreEqual<BuildResultCode>(resultCode, result.OverallResult, "Unexpected build result");
        }
Beispiel #4
0
 private ResultCode Convert(BuildResultCode buildResultCode)
 {
     switch (buildResultCode)
     {
         case BuildResultCode.Success:
             return ResultCode.Success;
         case BuildResultCode.Failure:
             return ResultCode.Failure;
         default:
             throw new ArgumentOutOfRangeException("buildResultCode");
     }
 }
Beispiel #5
0
        /// <summary>
        /// Checks that building the specified target produced the expected result.
        /// </summary>
        public static void AssertExpectedTargetOutput(BuildResult result, string target, BuildResultCode resultCode)
        {
            DumpTargetResult(result, target);

            TargetResult targetResult;

            if (!result.ResultsByTarget.TryGetValue(target, out targetResult))
            {
                Assert.Inconclusive(@"Could not find result for target ""{0}""", target);
            }
            Assert.AreEqual <BuildResultCode>(resultCode, result.OverallResult, "Unexpected build result");
        }
Beispiel #6
0
        public void Verify_build_results(string projOrSlnFullPath
                                         , IDictionary <string, string> globalProperties, IEnumerable <string> buildTargets
                                         , BuildResultCode expectedResultCode, Func <Exception, bool> evaluateException
                                         , Action <IEnumerable <string>, IEnumerable <string> > verifyVersions, IEnumerable <IFilterSource> filterSources)
        {
            OutputHelper.WriteLine($"Attempting to build: '{projOrSlnFullPath}'");

            void OnToolsetRequired(object sender, ToolsetRequiredEventArgs e)
            {
                // TODO: TBD: could probably update to toolset 16.0 (VS2019)...
                const string expectedToolsVersion = "15.0";

                e.Predicate = ts => ts.ToolsVersion == expectedToolsVersion;
                e.GetInstallDirectoryName = ts => new FileInfo(ts.ToolsPath).Directory?.Parent?.Parent?.FullName;
            }

            void OnConfigureEnvironmentVariables(object sender, ConfigureEnvironmentVariablesEventArgs e)
            {
                /* These do not seem to impact one way or another, but probably should be done just
                 * for sake of consistency regardless of the MSBuild version we're running against. */
                SetEnvironmentVariable("VSINSTALLDIR", e.InstallDirectoryName);
                SetEnvironmentVariable("MSBUILD_EXE_PATH", e.Toolset.ToolsPath);
                SetEnvironmentVariable("VisualStudioVersion", e.Toolset.ToolsVersion);
                // TODO: TBD: may possible have to set environment variable: MSBuildSDKsPath:
                // https://stackoverflow.com/questions/46257393/msbuild-throws-error-the-sdk-microsoft-net-sdk-specified-could-not-be-found
                // {"The SDK 'Microsoft.NET.Sdk' specified could not be found. L:\\Source\\Ellumination Technologies\\BumpAssemblyVersions\\master\\usage\\direct\\NetStd.ProjXml.AllowWildcard.FileInfoVersions\\NetStd.ProjXml.AllowWildcard.FileInfoVersions.csproj"}
            }

            void OnConfigureBuild(object sender, ConfigureBuildEventArgs e)
            {
                e.GlobalProperties          = globalProperties;
                e.ProjectOrSolutionFullPath = projOrSlnFullPath;
                // ReSharper disable once PossibleMultipleEnumeration
                e.TargetsToBuild = buildTargets.ToArray();
            }

            void OnAfterBuild(object sender, BuildResultEventArgs e)
            {
                Assert.NotNull(e.Result);
                Assert.Null(e.Exception);
                Assert.Equal(expectedResultCode, e.Result.OverallResult);
            }

            void OnBuildExceptionOccurred(object sender, BuildResultEventArgs e)
            {
                Assert.Null(e.Result);
                Assert.NotNull(e.Exception);
                Assert.True(evaluateException(e.Exception));
            }

            void ReportVersions(string message, params string[] versions)
            {
                if (!versions.Any())
                {
                    OutputHelper.WriteLine("There are no versions reported.");
                    return;
                }

                OutputHelper.WriteLine($"{message}: {Join(", ", versions.Select(v => $"'{v}'"))}");
            }

            var bis = BuildInvocationService;
            var nis = NuGetInvocationService;

            try
            {
                bis.ToolsetRequired += OnToolsetRequired;
                bis.ConfigureEnvironmentVariables += OnConfigureEnvironmentVariables;
                bis.ConfigureBuild         += OnConfigureBuild;
                bis.AfterBuild             += OnAfterBuild;
                bis.BuildExceptionOccurred += OnBuildExceptionOccurred;

                // ReSharper disable once PossibleMultipleEnumeration
                var versionsBefore = filterSources.SelectMany(source => source.Versions).ToArray();

                ReportVersions("In no particular order, the version(s) of interest before are", versionsBefore);

                nis.Restore(projOrSlnFullPath);

                bis.Run();

                // ReSharper disable once PossibleMultipleEnumeration
                var versionsAfter = filterSources.SelectMany(source => source.Versions).ToArray();

                ReportVersions("In no particular order, the version(s) of interest after are", versionsAfter);

                verifyVersions?.Invoke(versionsBefore, versionsAfter);
            }
            finally
            {
                bis.ToolsetRequired -= OnToolsetRequired;
                bis.ConfigureEnvironmentVariables -= OnConfigureEnvironmentVariables;
                bis.ConfigureBuild         -= OnConfigureBuild;
                bis.AfterBuild             -= OnAfterBuild;
                bis.BuildExceptionOccurred -= OnBuildExceptionOccurred;
            }
        }
Beispiel #7
0
 private static WorkUnitResult CreateWorkUnitResult(BuildResultCode resultCode)
 {
     return(resultCode == BuildResultCode.Success
         ? new WorkUnitResult(WorkUnitResultCode.Success, WorkUnitActionCode.Continue, null)
         : new WorkUnitResult(WorkUnitResultCode.Failed, WorkUnitActionCode.Stop, null));
 }
Beispiel #8
0
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="code">Result code of the operation</param>
 /// <param name="fileName">Full file path of the produced output assembly</param>
 /// <param name="compileException">Exception generated in the operation.</param>
 public CompileResult(BuildResultCode code, string fileName, Exception compileException)
 {
     BuildResultCode = code;
     FileName = fileName;
     Exception = compileException;
 }
Beispiel #9
0
 public ABBuildResult(AssetBundleManifest manifest, BuildResultCode code, string message)
 {
     Manifest = manifest;
     Message  = message;
     Result   = code;
 }