main
cs 237 lines 9.66 KB
Raw
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 WixE2E
4 {
5 using System;
6 using System.IO;
7 using System.Linq;
8 using System.Security.Cryptography;
9 using System.Text;
10 using WixInternal.TestSupport;
11 using Xunit;
12
13 public class WixE2EFixture
14 {
15 [Fact]
16 public void CanBuildWixlibMultiFramework()
17 {
18 var projectPath = TestData.Get("TestData", "WixprojLibraryMultiFramework", "WixprojLibraryMultiFramework.wixproj");
19
20 CleanEverything();
21
22 var result = RestoreAndBuild(projectPath);
23 result.AssertSuccess();
24 }
25
26 [Fact]
27 public void CanBuildWixlibWithNativeDll()
28 {
29 var projectPath = TestData.Get("TestData", "WixprojLibraryVcxprojDll", "WixprojLibraryVcxprojDll.wixproj");
30
31 CleanEverything();
32
33 var result = RestoreAndBuild(projectPath);
34 result.AssertSuccess();
35 }
36
37 [Fact]
38 public void CanBuildModuleWithWinFormsApp()
39 {
40 var projectPath = TestData.Get("TestData", "WixprojModuleCsprojWinFormsNetFx", "WixprojModuleCsprojWinFormsNetFx.wixproj");
41
42 CleanEverything();
43
44 var result = RestoreAndBuild(projectPath);
45 result.AssertSuccess();
46 }
47
48 [Fact]
49 public void CanBuildPackageWithWebApp()
50 {
51 var projectPath = TestData.Get("TestData", "WixprojPackageCsprojWebApplicationNetCore", "WixprojPackageCsprojWebApplicationNetCore.wixproj");
52
53 CleanEverything();
54
55 var result = RestoreAndBuild(projectPath);
56 result.AssertSuccess();
57 }
58
59 [Fact]
60 public void CanBuildPackageWithNativeWindowsApp()
61 {
62 var projectPath = TestData.Get("TestData", "WixprojPackageVcxprojWindowsApp", "WixprojPackageVcxprojWindowsApp.wixproj");
63
64 CleanEverything();
65
66 var result = RestoreAndBuild(projectPath);
67 result.AssertSuccess();
68
69 var signingStatement = result.Output.Where(s => s.Contains("warning :"))
70 .Select(s => s.Replace(Path.GetDirectoryName(projectPath), "<projectFolder>").Replace(@"\Debug\", @"\<configuration>\").Replace(@"\Release\", @"\<configuration>\"))
71 .ToArray();
72 WixAssert.CompareLineByLine(new[]
73 {
74 @"<projectFolder>\WixprojPackageVcxprojWindowsApp.wixproj(18,5): warning : SignMsi = obj\<configuration>\en-US\WixprojPackageVcxprojWindowsApp.msi;obj\<configuration>\ja-JP\WixprojPackageVcxprojWindowsApp.msi"
75 }, signingStatement);
76 }
77
78 [Fact]
79 public void CanIncrementalBuildPackageWithNativeWindowsAppWithNoEdits()
80 {
81 var projectDirectory = TestData.Get("TestData", "WixprojPackageVcxprojWindowsApp");
82 var projectPath = Path.Combine(projectDirectory, "WixprojPackageVcxprojWindowsApp.wixproj");
83 var projectBinPath = Path.Combine(projectDirectory, "bin");
84
85 CleanEverything();
86
87 var result = RestoreAndBuild(projectPath);
88 result.AssertSuccess();
89
90 var firstBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
91 var firstHashes = firstBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
92
93 // This should be an incremental build and not do any work.
94 //
95 result = RestoreAndBuild(projectPath);
96 result.AssertSuccess();
97
98 var secondBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
99 var secondHashes = secondBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
100
101 WixAssert.CompareLineByLine(firstHashes, secondHashes);
102 }
103
104 [Fact]
105 public void CanIncrementalBuildPackageWithNativeWindowsAppWithEdits()
106 {
107 var projectDirectory = TestData.Get("TestData", "WixprojPackageVcxprojWindowsApp");
108 var projectPath = Path.Combine(projectDirectory, "WixprojPackageVcxprojWindowsApp.wixproj");
109 var projectBinPath = Path.Combine(projectDirectory, "bin");
110
111 CleanEverything();
112
113 var result = RestoreAndBuild(projectPath);
114 result.AssertSuccess();
115
116 var firstBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
117 var firstRelativePaths = firstBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')}").ToArray();
118 var firstHashes = firstBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
119
120 var packageWxsPath = Path.Combine(projectDirectory, "Package.wxs");
121 File.SetLastWriteTime(packageWxsPath, DateTime.Now);
122
123 // This should be an incremental build that does work because a file was updated.
124 //
125 result = RestoreAndBuild(projectPath);
126 result.AssertSuccess();
127
128 var secondBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
129 var secondRelativePaths = secondBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')}").ToArray();
130 var secondHashes = secondBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
131
132 WixAssert.CompareLineByLine(firstRelativePaths, secondRelativePaths);
133 Assert.NotEqual(firstHashes, secondHashes);
134 }
135
136 [Theory]
137 [InlineData(false)]
138 [InlineData(true)]
139 public void CanBuildPackageWithHarvesting(bool x64)
140 {
141 var projectPath = TestData.Get("TestData", "WixprojPackageHarvesting", "WixprojPackageHarvesting.wixproj");
142
143 CleanEverything();
144
145 var result = RestoreAndBuild(projectPath, x64);
146 result.AssertSuccess();
147 }
148
149 [Theory]
150 [InlineData(false)]
151 [InlineData(true)]
152 public void CanBuildPackageWithHeatDir(bool x64)
153 {
154 var projectPath = TestData.Get("TestData", "WixprojPackageHeatDir", "WixprojPackageHeatDir.wixproj");
155
156 CleanEverything();
157
158 var result = RestoreAndBuild(projectPath, x64);
159 result.AssertSuccess();
160 }
161
162 [Fact(Skip = "Investigate if .NET Core WebApplications can be incrementally built")]
163 public void CanIncrementalBuildPackageWithNetCoreWebAppWithoutEdits()
164 {
165 var projectDirectory = TestData.Get("TestData", "WixprojPackageCsprojWebApplicationNetCore");
166 var projectPath = Path.Combine(projectDirectory, "WixprojPackageCsprojWebApplicationNetCore.wixproj");
167 var projectBinPath = Path.Combine(projectDirectory, "bin");
168
169 CleanEverything();
170
171 var result = RestoreAndBuild(projectPath);
172 result.AssertSuccess();
173
174 var firstBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
175 var firstHashes = firstBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
176
177 //var packageWxsPath = Path.Combine(projectDirectory, "Package.wxs");
178 //File.SetLastWriteTime(packageWxsPath, DateTime.Now);
179
180 // This should be an incremental build that does work because a file was updated.
181 //
182 result = RestoreAndBuild(projectPath);
183 result.AssertSuccess();
184
185 var secondBuiltFiles = Directory.GetFiles(projectBinPath, "*.*", SearchOption.AllDirectories).ToArray();
186 var secondHashes = secondBuiltFiles.Select(s => $"{s.Substring(projectBinPath.Length).TrimStart('\\')} with hash: {GetFileHash(s)}").ToArray();
187
188 WixAssert.CompareLineByLine(firstHashes, secondHashes);
189 }
190
191 private static void CleanEverything()
192 {
193 var rootFolder = TestData.Get("TestData");
194 var deleteFolders = new[] { "Debug", "bin", "obj" };
195
196 foreach (var projectFolder in Directory.GetDirectories(rootFolder))
197 {
198 foreach (var deleteFolder in deleteFolders)
199 {
200 var folder = Path.Combine(projectFolder, deleteFolder);
201
202 if (Directory.Exists(folder))
203 {
204 Directory.Delete(folder, true);
205 }
206 }
207 }
208
209 foreach (var logFile in Directory.GetFiles(rootFolder, "*.binlog", SearchOption.AllDirectories))
210 {
211 File.Delete(logFile);
212 }
213 }
214
215 private static string GetFileHash(string path)
216 {
217 using (var sha2 = SHA256.Create())
218 {
219 var bytes = File.ReadAllBytes(path);
220 var hashBytes = sha2.ComputeHash(bytes);
221
222 var sb = new StringBuilder();
223 foreach (var hash in hashBytes)
224 {
225 sb.AppendFormat("{0:X}", hash);
226 }
227
228 return sb.ToString();
229 }
230 }
231
232 private static MsbuildRunnerResult RestoreAndBuild(string projectPath, bool x64 = true, bool suppressValidation = true)
233 {
234 return MsbuildRunner.Execute(projectPath, new[] { "-Restore", "-v:m", "-bl", $"-p:SuppressValidation={suppressValidation}" }, x64);
235 }
236 }
237 }