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