| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolsetTest.Sdk |
| 4 | { |
| 5 | using System; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using WixInternal.TestSupport; |
| 9 | using Xunit; |
| 10 | |
| 11 | // When these tests are run repeatedly, they will expose an issue |
| 12 | // in the Windows Installer where ICE validations will occasionally |
| 13 | // fail to send all error/warning messages. The inconsistency |
| 14 | // obviously wreaks havoc on the tests. |
| 15 | // |
| 16 | // These tests are still interesting (and complex) enough to keep |
| 17 | // around for manual testing. Uncomment or define the following |
| 18 | // line to do so. |
| 19 | #if DISABLE_VALIDATION_TESTS_DUE_TO_WINDOWS_INSTALLER_INCONSISTENCIES |
| 20 | public class MsbuildValidationFixture |
| 21 | { |
| 22 | [Theory] |
| 23 | [InlineData(BuildSystem.DotNetCoreSdk)] |
| 24 | [InlineData(BuildSystem.MSBuild)] |
| 25 | [InlineData(BuildSystem.MSBuild64)] |
| 26 | public void CannotBuildMsiPackageWithIceIssues(BuildSystem buildSystem) |
| 27 | { |
| 28 | var sourceFolder = TestData.Get(@"TestData\MsiPackageWithIceError\MsiPackage"); |
| 29 | |
| 30 | var testLogsFolder = TestData.GetUnitTestLogsFolder(); |
| 31 | File.Delete(Path.Combine(testLogsFolder, buildSystem + ".binlog")); |
| 32 | File.Delete(Path.Combine(testLogsFolder, buildSystem + ".msi")); |
| 33 | |
| 34 | using (var fs = new TestDataFolderFileSystem()) |
| 35 | { |
| 36 | fs.Initialize(sourceFolder); |
| 37 | var baseFolder = fs.BaseFolder; |
| 38 | var projectPath = Path.Combine(baseFolder, "MsiPackage.wixproj"); |
| 39 | |
| 40 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, suppressValidation: false); |
| 41 | |
| 42 | File.Copy(Path.ChangeExtension(projectPath, ".binlog"), Path.Combine(testLogsFolder, buildSystem + ".binlog")); |
| 43 | File.Copy(Path.Combine(baseFolder, "obj", "x86", "Release", "en-US", "MsiPackage.msi"), Path.Combine(testLogsFolder, buildSystem + ".msi")); |
| 44 | |
| 45 | var iceIssues = result.Output.Where(line => line.Contains(": error") || line.Contains(": warning")) |
| 46 | .Select(line => line.Replace(baseFolder, "<baseFolder>") |
| 47 | .Replace("1>", String.Empty) // remove any multi-proc markers |
| 48 | .Replace("WIX204", "WIX0204") // normalize error number reporting because MSBuild is not consistent on zero padding |
| 49 | .Trim()) |
| 50 | .OrderBy(s => s, StringComparer.OrdinalIgnoreCase) |
| 51 | .ToArray(); |
| 52 | WixAssert.CompareLineByLine(new[] |
| 53 | { |
| 54 | @"<baseFolder>\Package.wxs(17): error WIX0204: ICE12: CustomAction: CausesICE12Error is of type: 35. Therefore it must come after CostFinalize @ 1000 in Seq Table: InstallExecuteSequence. CA Seq#: 49 [<baseFolder>\MsiPackage.wixproj]", |
| 55 | @"<baseFolder>\Package.wxs(17): error WIX0204: ICE12: CustomAction: CausesICE12Error is of type: 35. Therefore it must come after CostFinalize @ 1000 in Seq Table: InstallExecuteSequence. CA Seq#: 49 [<baseFolder>\MsiPackage.wixproj]", |
| 56 | @"<baseFolder>\Package.wxs(8): warning WIX1076: ICE46: Property 'Myproperty' referenced in column 'LaunchCondition'.'Condition' of row 'Myproperty' differs from a defined property by case only. [<baseFolder>\MsiPackage.wixproj]", |
| 57 | @"<baseFolder>\Package.wxs(8): warning WIX1076: ICE46: Property 'Myproperty' referenced in column 'LaunchCondition'.'Condition' of row 'Myproperty' differs from a defined property by case only. [<baseFolder>\MsiPackage.wixproj]", |
| 58 | }, iceIssues); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | [Theory] |
| 63 | [InlineData(BuildSystem.DotNetCoreSdk)] |
| 64 | [InlineData(BuildSystem.MSBuild)] |
| 65 | [InlineData(BuildSystem.MSBuild64)] |
| 66 | public void CannotBuildMsiPackageWithIceWarningsAsErrors(BuildSystem buildSystem) |
| 67 | { |
| 68 | var sourceFolder = TestData.Get(@"TestData\MsiPackageWithIceError\MsiPackage"); |
| 69 | |
| 70 | using (var fs = new TestDataFolderFileSystem()) |
| 71 | { |
| 72 | fs.Initialize(sourceFolder); |
| 73 | var baseFolder = fs.BaseFolder; |
| 74 | var projectPath = Path.Combine(baseFolder, "MsiPackage.wixproj"); |
| 75 | |
| 76 | var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] |
| 77 | { |
| 78 | $"-p:TreatWarningsAsErrors=true", |
| 79 | MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "SuppressIces", "ICE12"), |
| 80 | }, suppressValidation: false); |
| 81 | Assert.Equal(1, result.ExitCode); |
| 82 | |
| 83 | var iceIssues = result.Output.Where(line => (line.Contains(": error") || line.Contains(": warning"))) |
| 84 | .Select(line => line.Replace(baseFolder, "<baseFolder>") |
| 85 | .Replace("1>", String.Empty) // remove any multi-proc markers |
| 86 | .Replace("WIX204", "WIX0204") // normalize error number reporting because MSBuild is not consistent on zero padding |
| 87 | .Trim()) |
| 88 | .OrderBy(s => s, StringComparer.OrdinalIgnoreCase) |
| 89 | .ToArray(); |
| 90 | WixAssert.CompareLineByLine(new[] |
| 91 | { |
| 92 | @"<baseFolder>\Package.wxs(8): error WIX1076: ICE46: Property 'Myproperty' referenced in column 'LaunchCondition'.'Condition' of row 'Myproperty' differs from a defined property by case only. [<baseFolder>\MsiPackage.wixproj]", |
| 93 | @"<baseFolder>\Package.wxs(8): error WIX1076: ICE46: Property 'Myproperty' referenced in column 'LaunchCondition'.'Condition' of row 'Myproperty' differs from a defined property by case only. [<baseFolder>\MsiPackage.wixproj]", |
| 94 | }, iceIssues); |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | #endif |
| 99 | } |