| 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.BuildTasks |
| 4 | { |
| 5 | using System; |
| 6 | using System.IO; |
| 7 | using System.Linq; |
| 8 | using System.Runtime.InteropServices; |
| 9 | using Microsoft.Build.Utilities; |
| 10 | using WixInternal.TestSupport; |
| 11 | using WixToolset.BuildTasks; |
| 12 | using WixToolset.Data; |
| 13 | using WixToolset.Data.Symbols; |
| 14 | using Xunit; |
| 15 | |
| 16 | public class WixBuildTaskFixture |
| 17 | { |
| 18 | public static readonly string PublishedWixSdkToolsFolder = Path.Combine(Path.GetDirectoryName(new Uri(typeof(WixBuildTaskFixture).Assembly.CodeBase).LocalPath), "..", "..", "..", "publish", "WixToolset.Sdk", "tools"); |
| 19 | |
| 20 | // This line replicates what happens in WixBuild task when hosted in the PublishedWixSdkToolsFolder. However, WixBuild task is hosted inproc to this test assembly so the |
| 21 | // root folder is relative to the test assembly's folder which does not have wix.exe local. So, we have to find wix.exe relative to PublishedWixSdkToolsFolder. |
| 22 | public static readonly string PublishedWixExeFolder = Path.Combine(PublishedWixSdkToolsFolder, "net472", RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant()); |
| 23 | |
| 24 | [Fact] |
| 25 | public void CanBuildSimpleMsiPackage() |
| 26 | { |
| 27 | var folder = TestData.Get("TestData", "SimpleMsiPackage", "MsiPackage"); |
| 28 | |
| 29 | using (var fs = new DisposableFileSystem()) |
| 30 | { |
| 31 | var baseFolder = fs.GetFolder(); |
| 32 | var intermediateFolder = Path.Combine(baseFolder, "obj"); |
| 33 | var pdbPath = Path.Combine(baseFolder, "bin", "testpackage.wixpdb"); |
| 34 | var engine = new FakeBuildEngine(); |
| 35 | |
| 36 | var task = new WixBuild |
| 37 | { |
| 38 | BuildEngine = engine, |
| 39 | SourceFiles = new[] |
| 40 | { |
| 41 | new TaskItem(Path.Combine(folder, "Package.wxs")), |
| 42 | new TaskItem(Path.Combine(folder, "PackageComponents.wxs")), |
| 43 | }, |
| 44 | LocalizationFiles = new[] |
| 45 | { |
| 46 | new TaskItem(Path.Combine(folder, "Package.en-us.wxl")), |
| 47 | }, |
| 48 | BindPaths = new[] |
| 49 | { |
| 50 | new TaskItem(Path.Combine(folder, "data")), |
| 51 | }, |
| 52 | IntermediateDirectory = new TaskItem(intermediateFolder), |
| 53 | OutputFile = new TaskItem(Path.Combine(baseFolder, "bin", "test.msi")), |
| 54 | PdbType = "Full", |
| 55 | PdbFile = new TaskItem(pdbPath), |
| 56 | DefaultCompressionLevel = "nOnE", |
| 57 | ToolPath = PublishedWixExeFolder |
| 58 | }; |
| 59 | |
| 60 | var result = task.Execute(); |
| 61 | Assert.True(result, $"MSBuild task failed unexpectedly. Output:\r\n{engine.Output}"); |
| 62 | |
| 63 | Assert.True(File.Exists(Path.Combine(baseFolder, "bin", "test.msi"))); |
| 64 | Assert.True(File.Exists(pdbPath)); |
| 65 | Assert.True(File.Exists(Path.Combine(baseFolder, "bin", "cab1.cab"))); |
| 66 | |
| 67 | var intermediate = Intermediate.Load(pdbPath); |
| 68 | var section = intermediate.Sections.Single(); |
| 69 | |
| 70 | var fileSymbol = section.Symbols.OfType<FileSymbol>().Single(); |
| 71 | WixAssert.StringEqual(Path.Combine(folder, "data", "test.txt"), fileSymbol[FileSymbolFields.Source].AsPath().Path); |
| 72 | WixAssert.StringEqual(@"test.txt", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath().Path); |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |