summaryrefslogtreecommitdiff
path: root/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs')
-rw-r--r--src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs410
1 files changed, 410 insertions, 0 deletions
diff --git a/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs b/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs
new file mode 100644
index 00000000..d54da457
--- /dev/null
+++ b/src/tools/test/WixToolsetTest.HeatTasks/MsbuildHeatFixture.cs
@@ -0,0 +1,410 @@
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
3namespace WixToolsetTest.Sdk
4{
5 using System;
6 using System.IO;
7 using System.Linq;
8 using WixBuildTools.TestSupport;
9 using WixToolset.Core.TestPackage;
10 using WixToolset.Data;
11 using WixToolset.Data.Symbols;
12 using Xunit;
13
14 public class MsbuildHeatFixture
15 {
16 public static readonly string HeatTargetsPath = Path.Combine(Path.GetDirectoryName(new Uri(typeof(MsbuildHeatFixture).Assembly.CodeBase).AbsolutePath), "..", "..", "..", "publish", "WixToolset.Heat", "build", "WixToolset.Heat.targets");
17
18 public MsbuildHeatFixture()
19 {
20 EnsureWixSdkCached();
21 }
22
23 [Theory]
24 [InlineData(BuildSystem.DotNetCoreSdk)]
25 [InlineData(BuildSystem.MSBuild)]
26 [InlineData(BuildSystem.MSBuild64)]
27 public void CanBuildHeatFilePackage(BuildSystem buildSystem)
28 {
29 var sourceFolder = TestData.Get("TestData", "HeatFilePackage");
30
31 using (var fs = new DisposableFileSystem())
32 {
33 var baseFolder = fs.GetFolder();
34 var binFolder = Path.Combine(baseFolder, @"bin");
35 var intermediateFolder = Path.Combine(baseFolder, @"obj\");
36 var projectPath = Path.Combine(sourceFolder, "HeatFilePackage.wixproj");
37
38 var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] {
39 "-Restore",
40 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "HeatTargetsPath", MsbuildHeatFixture.HeatTargetsPath),
41 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "BaseIntermediateOutputPath", intermediateFolder),
42 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "OutputPath", binFolder),
43 });
44 result.AssertSuccess();
45
46 var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem, true);
47 Assert.Single(heatCommandLines);
48
49 var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
50 WixAssert.StringCollectionEmpty(warnings);
51
52 var generatedFilePath = Path.Combine(intermediateFolder, "Release", "_ProductComponents_INSTALLFOLDER_HeatFilePackage.wixproj_file.wxs");
53 var generatedContents = File.ReadAllText(generatedFilePath);
54 var testXml = generatedContents.GetTestXml();
55 WixAssert.StringEqual(@"<Wix>" +
56 "<Fragment>" +
57 "<DirectoryRef Id='INSTALLFOLDER'>" +
58 "<Component Id='HeatFilePackage.wixproj' Guid='*'>" +
59 "<File Id='HeatFilePackage.wixproj' KeyPath='yes' Source='SourceDir\\HeatFilePackage.wixproj' />" +
60 "</Component>" +
61 "</DirectoryRef>" +
62 "</Fragment>" +
63 "<Fragment>" +
64 "<ComponentGroup Id='ProductComponents'>" +
65 "<ComponentRef Id='HeatFilePackage.wixproj' />" +
66 "</ComponentGroup>" +
67 "</Fragment>" +
68 "</Wix>", testXml);
69
70 var pdbPath = Path.Combine(binFolder, "HeatFilePackage.wixpdb");
71 var intermediate = Intermediate.Load(pdbPath);
72 var section = intermediate.Sections.Single();
73
74 var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
75 WixAssert.StringEqual(@"SourceDir\HeatFilePackage.wixproj", fileSymbol[FileSymbolFields.Source].PreviousValue.AsPath()?.Path);
76 }
77 }
78
79 [Theory]
80 [InlineData(BuildSystem.DotNetCoreSdk)]
81 [InlineData(BuildSystem.MSBuild)]
82 [InlineData(BuildSystem.MSBuild64)]
83 public void CanBuildHeatFileWithMultipleFilesPackage(BuildSystem buildSystem)
84 {
85 var sourceFolder = TestData.Get(@"TestData", "HeatFileMultipleFilesSameFileName");
86
87 using (var fs = new DisposableFileSystem())
88 {
89 var baseFolder = fs.GetFolder();
90 var binFolder = Path.Combine(baseFolder, @"bin\");
91 var intermediateFolder = Path.Combine(baseFolder, @"obj\");
92 var projectPath = Path.Combine(sourceFolder, "HeatFileMultipleFilesSameFileName.wixproj");
93
94 var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[] {
95 "-Restore",
96 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "HeatTargetsPath", MsbuildHeatFixture.HeatTargetsPath),
97 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "BaseIntermediateOutputPath", intermediateFolder),
98 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "OutputPath", binFolder),
99 });
100 result.AssertSuccess();
101
102 var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "file", buildSystem, true);
103 Assert.Equal(2, heatCommandLines.Count());
104
105 var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
106 WixAssert.StringCollectionEmpty(warnings);
107
108 var generatedFilePath = Path.Combine(intermediateFolder, "Release", "_TxtProductComponents_INSTALLFOLDER_MyProgram.txt_file.wxs");
109 Assert.True(File.Exists(generatedFilePath));
110
111 var generatedContents = File.ReadAllText(generatedFilePath);
112 var testXml = generatedContents.GetTestXml();
113 WixAssert.StringEqual("<Wix>" +
114 "<Fragment>" +
115 "<DirectoryRef Id='INSTALLFOLDER'>" +
116 "<Component Id='MyProgram.txt' Guid='*'>" +
117 @"<File Id='MyProgram.txt' KeyPath='yes' Source='SourceDir\MyProgram.txt' />" +
118 "</Component>" +
119 "</DirectoryRef>" +
120 "</Fragment>" +
121 "<Fragment>" +
122 "<ComponentGroup Id='TxtProductComponents'>" +
123 "<ComponentRef Id='MyProgram.txt' />" +
124 "</ComponentGroup>" +
125 "</Fragment>" +
126 "</Wix>", testXml);
127
128 generatedFilePath = Path.Combine(intermediateFolder, "Release", "_JsonProductComponents_INSTALLFOLDER_MyProgram.json_file.wxs");
129 Assert.True(File.Exists(generatedFilePath));
130
131 generatedContents = File.ReadAllText(generatedFilePath);
132 testXml = generatedContents.GetTestXml();
133 WixAssert.StringEqual("<Wix>" +
134 "<Fragment>" +
135 "<DirectoryRef Id='INSTALLFOLDER'>" +
136 "<Component Id='MyProgram.json' Guid='*'>" +
137 @"<File Id='MyProgram.json' KeyPath='yes' Source='SourceDir\MyProgram.json' />" +
138 "</Component>" +
139 "</DirectoryRef>" +
140 "</Fragment>" +
141 "<Fragment>" +
142 "<ComponentGroup Id='JsonProductComponents'>" +
143 "<ComponentRef Id='MyProgram.json' />" +
144 "</ComponentGroup>" +
145 "</Fragment>" +
146 "</Wix>", testXml);
147
148 var pdbPath = Path.Combine(binFolder, "HeatFileMultipleFilesSameFileName.wixpdb");
149 Assert.True(File.Exists(pdbPath));
150
151 var intermediate = Intermediate.Load(pdbPath);
152 var section = intermediate.Sections.Single();
153
154 var fileSymbols = section.Symbols.OfType<FileSymbol>().ToArray();
155 WixAssert.StringEqual(@"SourceDir\MyProgram.txt", fileSymbols[0][FileSymbolFields.Source].PreviousValue.AsPath()?.Path);
156 WixAssert.StringEqual(@"SourceDir\MyProgram.json", fileSymbols[1][FileSymbolFields.Source].PreviousValue.AsPath()?.Path);
157 }
158 }
159
160 [Theory]
161 [InlineData(BuildSystem.DotNetCoreSdk, true)]
162 [InlineData(BuildSystem.DotNetCoreSdk, false)]
163 [InlineData(BuildSystem.MSBuild, true)]
164 [InlineData(BuildSystem.MSBuild, false)]
165 [InlineData(BuildSystem.MSBuild64, true)]
166 [InlineData(BuildSystem.MSBuild64, false)]
167 public void CanBuildHeatProjectPreSdkStyle(BuildSystem buildSystem, bool useToolsVersion)
168 {
169 var sourceFolder = TestData.Get(@"TestData", "HeatProject");
170
171 using (var fs = new TestDataFolderFileSystem())
172 {
173 fs.Initialize(sourceFolder);
174 File.Copy("global.json", Path.Combine(fs.BaseFolder, "global.json"));
175
176 var baseFolder = Path.Combine(fs.BaseFolder, "HeatProjectPreSdkStyle");
177 var binFolder = Path.Combine(baseFolder, @"bin\");
178 var intermediateFolder = Path.Combine(baseFolder, @"obj\");
179 var projectPath = Path.Combine(baseFolder, "HeatProjectPreSdkStyle.wixproj");
180
181 var result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[]
182 {
183 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "HeatTargetsPath", MsbuildHeatFixture.HeatTargetsPath),
184 useToolsVersion ? $"-p:HarvestProjectsUseToolsVersion=true" : String.Empty,
185 });
186 result.AssertSuccess();
187
188 var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem, true);
189 var heatCommandLine = Assert.Single(heatCommandLines);
190
191 if (useToolsVersion && buildSystem != BuildSystem.DotNetCoreSdk)
192 {
193 Assert.Contains("-usetoolsversion", heatCommandLine);
194 }
195 else
196 {
197 Assert.DoesNotContain("-usetoolsversion", heatCommandLine);
198 }
199
200 var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
201 WixAssert.StringCollectionEmpty(warnings);
202
203 var generatedFilePath = Path.Combine(intermediateFolder, "Release", "_ToolsVersion4Cs.wxs");
204 Assert.True(File.Exists(generatedFilePath));
205
206 var generatedContents = File.ReadAllText(generatedFilePath);
207 var testXml = generatedContents.GetTestXml();
208 WixAssert.StringEqual(@"<Wix>" +
209 "<Fragment>" +
210 "<DirectoryRef Id='ToolsVersion4Cs.Binaries'>" +
211 "<Component Id='ToolsVersion4Cs.Binaries.ToolsVersion4Cs.dll' Guid='*'>" +
212 "<File Id='ToolsVersion4Cs.Binaries.ToolsVersion4Cs.dll' Source='$(var.ToolsVersion4Cs.TargetDir)\\ToolsVersion4Cs.dll' />" +
213 "</Component>" +
214 "</DirectoryRef>" +
215 "</Fragment>" +
216 "<Fragment>" +
217 "<ComponentGroup Id='ToolsVersion4Cs.Binaries'>" +
218 "<ComponentRef Id='ToolsVersion4Cs.Binaries.ToolsVersion4Cs.dll' />" +
219 "</ComponentGroup>" +
220 "</Fragment>" +
221 "<Fragment>" +
222 "<DirectoryRef Id='ToolsVersion4Cs.Symbols'>" +
223 "<Component Id='ToolsVersion4Cs.Symbols.ToolsVersion4Cs.pdb' Guid='*'>" +
224 "<File Id='ToolsVersion4Cs.Symbols.ToolsVersion4Cs.pdb' Source='$(var.ToolsVersion4Cs.TargetDir)\\ToolsVersion4Cs.pdb' />" +
225 "</Component>" +
226 "</DirectoryRef>" +
227 "</Fragment>" +
228 "<Fragment>" +
229 "<ComponentGroup Id='ToolsVersion4Cs.Symbols'>" +
230 "<ComponentRef Id='ToolsVersion4Cs.Symbols.ToolsVersion4Cs.pdb' />" +
231 "</ComponentGroup>" +
232 "</Fragment>" +
233 "<Fragment>" +
234 "<DirectoryRef Id='ToolsVersion4Cs.Sources'>" +
235 "<Component Id='ToolsVersion4Cs.Sources.ToolsVersion4Cs.csproj' Guid='*'>" +
236 "<File Id='ToolsVersion4Cs.Sources.ToolsVersion4Cs.csproj' Source='$(var.ToolsVersion4Cs.ProjectDir)\\ToolsVersion4Cs.csproj' />" +
237 "</Component>" +
238 "<Directory Id='ToolsVersion4Cs.Sources.Properties' Name='Properties'>" +
239 "<Component Id='ToolsVersion4Cs.Sources.AssemblyInfo.cs' Guid='*'>" +
240 "<File Id='ToolsVersion4Cs.Sources.AssemblyInfo.cs' Source='$(var.ToolsVersion4Cs.ProjectDir)\\Properties\\AssemblyInfo.cs' />" +
241 "</Component>" +
242 "</Directory>" +
243 "</DirectoryRef>" +
244 "</Fragment>" +
245 "<Fragment>" +
246 "<ComponentGroup Id='ToolsVersion4Cs.Sources'>" +
247 "<ComponentRef Id='ToolsVersion4Cs.Sources.ToolsVersion4Cs.csproj' />" +
248 "<ComponentRef Id='ToolsVersion4Cs.Sources.AssemblyInfo.cs' />" +
249 "</ComponentGroup>" +
250 "</Fragment>" +
251 "<Fragment>" +
252 "<ComponentGroup Id='ToolsVersion4Cs.Content' />" +
253 "</Fragment>" +
254 "<Fragment>" +
255 "<ComponentGroup Id='ToolsVersion4Cs.Satellites' />" +
256 "</Fragment>" +
257 "<Fragment>" +
258 "<ComponentGroup Id='ToolsVersion4Cs.Documents' />" +
259 "</Fragment>" +
260 "</Wix>", testXml);
261
262 var pdbPath = Path.Combine(binFolder, "Release", "HeatProjectPreSdkStyle.wixpdb");
263 Assert.True(File.Exists(pdbPath));
264
265 var intermediate = Intermediate.Load(pdbPath);
266 var section = intermediate.Sections.Single();
267
268 var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
269 WixAssert.StringEqual(Path.Combine(fs.BaseFolder, "ToolsVersion4Cs", "bin", "Release\\\\ToolsVersion4Cs.dll"), fileSymbol[FileSymbolFields.Source].AsPath()?.Path);
270 }
271 }
272
273 [Theory]
274 [InlineData(BuildSystem.DotNetCoreSdk, true)]
275 [InlineData(BuildSystem.DotNetCoreSdk, false)]
276 [InlineData(BuildSystem.MSBuild, true)]
277 [InlineData(BuildSystem.MSBuild, false)]
278 [InlineData(BuildSystem.MSBuild64, true)]
279 [InlineData(BuildSystem.MSBuild64, false)]
280 public void CanBuildHeatProjectSdkStyle(BuildSystem buildSystem, bool useToolsVersion)
281 {
282 var sourceFolder = TestData.Get(@"TestData\HeatProject");
283
284 using (var fs = new TestDataFolderFileSystem())
285 {
286 fs.Initialize(sourceFolder);
287 File.Copy("global.json", Path.Combine(fs.BaseFolder, "global.json"));
288
289 var baseFolder = Path.Combine(fs.BaseFolder, "HeatProjectSdkStyle");
290 var binFolder = Path.Combine(baseFolder, @"bin\");
291 var intermediateFolder = Path.Combine(baseFolder, @"obj\");
292 var projectPath = Path.Combine(fs.BaseFolder, "HeatProjectSdkStyle", "HeatProjectSdkStyle.wixproj");
293 var referencedProjectPath = Path.Combine(fs.BaseFolder, "SdkStyleCs", "SdkStyleCs.csproj");
294
295 var result = MsbuildUtilities.BuildProject(buildSystem, referencedProjectPath, new[]
296 {
297 "-t:restore",
298 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "HeatTargetsPath", MsbuildHeatFixture.HeatTargetsPath),
299 });
300 result.AssertSuccess();
301
302 result = MsbuildUtilities.BuildProject(buildSystem, projectPath, new[]
303 {
304 MsbuildUtilities.GetQuotedPropertySwitch(buildSystem, "HeatTargetsPath", MsbuildHeatFixture.HeatTargetsPath),
305 useToolsVersion ? $"-p:HarvestProjectsUseToolsVersion=true" : String.Empty,
306 });
307 result.AssertSuccess();
308
309 var heatCommandLines = MsbuildUtilities.GetToolCommandLines(result, "heat", "project", buildSystem, true);
310 var heatCommandLine = Assert.Single(heatCommandLines);
311
312 if (useToolsVersion && buildSystem != BuildSystem.DotNetCoreSdk)
313 {
314 Assert.Contains("-usetoolsversion", heatCommandLine);
315 }
316 else
317 {
318 Assert.DoesNotContain("-usetoolsversion", heatCommandLine);
319 }
320
321 var warnings = result.Output.Where(line => line.Contains(": warning")).ToArray();
322 WixAssert.StringCollectionEmpty(warnings);
323
324 var generatedFilePath = Path.Combine(intermediateFolder, "Release", "_SdkStyleCs.wxs");
325 Assert.True(File.Exists(generatedFilePath));
326
327 var generatedContents = File.ReadAllText(generatedFilePath);
328 var testXml = generatedContents.GetTestXml();
329 WixAssert.StringEqual(@"<Wix>" +
330 "<Fragment>" +
331 "<DirectoryRef Id='SdkStyleCs.Binaries'>" +
332 "<Component Id='SdkStyleCs.Binaries.SdkStyleCs.dll' Guid='*'>" +
333 "<File Id='SdkStyleCs.Binaries.SdkStyleCs.dll' Source='$(var.SdkStyleCs.TargetDir)\\SdkStyleCs.dll' />" +
334 "</Component>" +
335 "</DirectoryRef>" +
336 "</Fragment>" +
337 "<Fragment>" +
338 "<ComponentGroup Id='SdkStyleCs.Binaries'>" +
339 "<ComponentRef Id='SdkStyleCs.Binaries.SdkStyleCs.dll' />" +
340 "</ComponentGroup>" +
341 "</Fragment>" +
342 "<Fragment>" +
343 "<DirectoryRef Id='SdkStyleCs.Symbols'>" +
344 "<Component Id='SdkStyleCs.Symbols.SdkStyleCs.pdb' Guid='*'>" +
345 "<File Id='SdkStyleCs.Symbols.SdkStyleCs.pdb' Source='$(var.SdkStyleCs.TargetDir)\\SdkStyleCs.pdb' />" +
346 "</Component>" +
347 "</DirectoryRef>" +
348 "</Fragment>" +
349 "<Fragment>" +
350 "<ComponentGroup Id='SdkStyleCs.Symbols'>" +
351 "<ComponentRef Id='SdkStyleCs.Symbols.SdkStyleCs.pdb' />" +
352 "</ComponentGroup>" +
353 "</Fragment>" +
354 "<Fragment>" +
355 "<DirectoryRef Id='SdkStyleCs.Sources'>" +
356 "<Component Id='SdkStyleCs.Sources.SdkStyleCs.cs' Guid='*'>" +
357 "<File Id='SdkStyleCs.Sources.SdkStyleCs.cs' Source='$(var.SdkStyleCs.ProjectDir)\\SdkStyleCs.cs' />" +
358 "</Component>" +
359 "<Component Id='SdkStyleCs.Sources.SdkStyleCs.csproj' Guid='*'>" +
360 "<File Id='SdkStyleCs.Sources.SdkStyleCs.csproj' Source='$(var.SdkStyleCs.ProjectDir)\\SdkStyleCs.csproj' />" +
361 "</Component>" +
362 "</DirectoryRef>" +
363 "</Fragment>" +
364 "<Fragment>" +
365 "<ComponentGroup Id='SdkStyleCs.Sources'>" +
366 "<ComponentRef Id='SdkStyleCs.Sources.SdkStyleCs.cs' />" +
367 "<ComponentRef Id='SdkStyleCs.Sources.SdkStyleCs.csproj' />" +
368 "</ComponentGroup>" +
369 "</Fragment>" +
370 "<Fragment>" +
371 "<ComponentGroup Id='SdkStyleCs.Content' />" +
372 "</Fragment>" +
373 "<Fragment>" +
374 "<ComponentGroup Id='SdkStyleCs.Satellites' />" +
375 "</Fragment>" +
376 "<Fragment>" +
377 "<ComponentGroup Id='SdkStyleCs.Documents' />" +
378 "</Fragment>" +
379 "</Wix>", testXml);
380
381 var pdbPath = Path.Combine(binFolder, "Release", "HeatProjectSdkStyle.wixpdb");
382 Assert.True(File.Exists(pdbPath));
383
384 var intermediate = Intermediate.Load(pdbPath);
385 var section = intermediate.Sections.Single();
386
387 var fileSymbol = section.Symbols.OfType<FileSymbol>().Single();
388 WixAssert.StringEqual(Path.Combine(fs.BaseFolder, "SdkStyleCs", "bin", "Release", "netstandard2.0\\\\SdkStyleCs.dll"), fileSymbol[FileSymbolFields.Source].AsPath()?.Path);
389 }
390 }
391
392 /// <summary>
393 /// This method exists to get the WixToolset.Sdk.nupkg into the NuGet package cache using the global.json
394 /// and nuget.config in the root of the repository. By pre-caching the WiX SDK, the rest of the tests will
395 /// pull the binaries out of the cache instead of needing to find the original .nupkg in the build artifacts
396 /// folder (which requires use of nuget.config found in the root of the repo)
397 /// </summary>
398 private static void EnsureWixSdkCached()
399 {
400 // This EnsureWixSdkCached project exists only to pre-cache the WixToolset.Sdk for use by later projects.
401 var sourceFolder = TestData.Get("TestData", "EnsureWixSdkCached");
402
403 var result = MsbuildUtilities.BuildProject(BuildSystem.DotNetCoreSdk, Path.Combine(sourceFolder, "EnsureWixSdkCached.wixproj"), new[]
404 {
405 "-t:restore",
406 });
407 result.AssertSuccess();
408 }
409 }
410}