Allow more than one harvested file and files differing by extension add component and directory for more disambiguation Fix HarvestFile Ouput added unit tests
Allow more than one harvested file and files differing by extension add component and directory for more disambiguation Fix HarvestFile Ouput added unit tests
paulomorgado committed
May 25, 2020 at 13:13 UTC
0b9fd5ae84460d943e685b9821473f356a66bd3b
7 files changed
+170
-4
src/WixToolset.BuildTasks/wix.harvest.targets
+2
-2
@@ -415,7 +415,7 @@
415
<Target Name="HarvestFile"
416
DependsOnTargets="$(HarvestFileDependsOn)"
417
Inputs="@(HarvestFile);%(HarvestFile.Transforms)"
418
- Outputs="$(IntermediateOutputPath)_%(HarvestFile.Filename)_file.wxs"
418
+ Outputs="@(HarvestFile->'$(IntermediateOutputPath)_%(ComponentGroupName)_%(DirectoryRefId)_%(Filename)%(Extension)_file.wxs')"
419
Condition=" '@(HarvestFile)' != '' ">
420
421
<HeatFile
@@ -427,7 +427,7 @@
427
VerboseOutput="$(HarvestFileVerboseOutput)"
428
AutogenerateGuids="$(HarvestFileAutogenerateGuids)"
429
GenerateGuidsNow="$(HarvestFileGenerateGuidsNow)"
430
- OutputFile="$(IntermediateOutputPath)_%(HarvestFile.Filename)_file.wxs"
430
+ OutputFile="$(IntermediateOutputPath)_%(HarvestFile.ComponentGroupName)_%(HarvestFile.DirectoryRefId)_%(HarvestFile.Filename)%(HarvestFile.Extension)_file.wxs"
431
SuppressFragments="$(HarvestFileSuppressFragments)"
432
SuppressUniqueIds="$(HarvestFileSuppressUniqueIds)"
433
Transforms="%(HarvestFile.Transforms)"
src/test/WixToolsetTest.BuildTasks/MsbuildHeatFixture.cs
+78
-1
@@ -41,7 +41,7 @@ namespace WixToolsetTest.BuildTasks
41
var warnings = result.Output.Where(line => line.Contains(": warning"));
42
Assert.Empty(warnings);
43
44
- var generatedFilePath = Path.Combine(intermediateFolder, @"_HeatFilePackage_file.wxs");
44
+ var generatedFilePath = Path.Combine(intermediateFolder, @"_ProductComponents_INSTALLFOLDER_HeatFilePackage.wixproj_file.wxs");
45
Assert.True(File.Exists(generatedFilePath));
46
47
var generatedContents = File.ReadAllText(generatedFilePath);
@@ -71,5 +71,82 @@ namespace WixToolsetTest.BuildTasks
71
Assert.Equal(@"SourceDir\HeatFilePackage.wixproj", fileTuple[FileTupleFields.Source].PreviousValue.AsPath().Path);
72
}
73
}
74
+
75
+ [Fact]
76
+ public void CanBuildHeatFileWithMultipleFilesPackage()
77
+ {
78
+ var projectPath = TestData.Get(@"TestData\HeatFileMultpleFilesSameFileName\HeatFileMultpleFilesSameFileName.wixproj");
79
+
80
+ using (var fs = new DisposableFileSystem())
81
+ {
82
+ var baseFolder = fs.GetFolder();
83
+ var binFolder = Path.Combine(baseFolder, @"bin\");
84
+ var intermediateFolder = Path.Combine(baseFolder, @"obj\");
85
+
86
+ var result = MsbuildRunner.Execute(projectPath, new[]
87
+ {
88
+ $"-p:WixTargetsPath={WixTargetsPath}",
89
+ $"-p:IntermediateOutputPath={intermediateFolder}",
90
+ $"-p:OutputPath={binFolder}"
91
+ });
92
+ result.AssertSuccess();
93
+
94
+ var heatCommandLines = result.Output.Where(line => line.TrimStart().StartsWith("heat.exe file"));
95
+ Assert.Equal(2, heatCommandLines.Count());
96
+
97
+ var warnings = result.Output.Where(line => line.Contains(": warning"));
98
+ Assert.Empty(warnings);
99
+
100
+ var generatedFilePath = Path.Combine(intermediateFolder, @"_TxtProductComponents_INSTALLFOLDER_MyProgram.txt_file.wxs");
101
+ Assert.True(File.Exists(generatedFilePath));
102
+
103
+ var generatedContents = File.ReadAllText(generatedFilePath);
104
+ var testXml = generatedContents.GetTestXml();
105
+ Assert.Equal("<Wix>" +
106
+ "<Fragment>" +
107
+ "<DirectoryRef Id='INSTALLFOLDER'>" +
108
+ "<Component Id='MyProgram.txt' Guid='*'>" +
109
+ @"<File Id='MyProgram.txt' KeyPath='yes' Source='SourceDir\MyProgram.txt' />" +
110
+ "</Component>" +
111
+ "</DirectoryRef>" +
112
+ "</Fragment>" +
113
+ "<Fragment>" +
114
+ "<ComponentGroup Id='TxtProductComponents'>" +
115
+ "<ComponentRef Id='MyProgram.txt' />" +
116
+ "</ComponentGroup>" +
117
+ "</Fragment>" +
118
+ "</Wix>", testXml);
119
+
120
+ generatedFilePath = Path.Combine(intermediateFolder, @"_JsonProductComponents_INSTALLFOLDER_MyProgram.json_file.wxs");
121
+ Assert.True(File.Exists(generatedFilePath));
122
+
123
+ generatedContents = File.ReadAllText(generatedFilePath);
124
+ testXml = generatedContents.GetTestXml();
125
+ Assert.Equal("<Wix>" +
126
+ "<Fragment>" +
127
+ "<DirectoryRef Id='INSTALLFOLDER'>" +
128
+ "<Component Id='MyProgram.json' Guid='*'>" +
129
+ @"<File Id='MyProgram.json' KeyPath='yes' Source='SourceDir\MyProgram.json' />" +
130
+ "</Component>" +
131
+ "</DirectoryRef>" +
132
+ "</Fragment>" +
133
+ "<Fragment>" +
134
+ "<ComponentGroup Id='JsonProductComponents'>" +
135
+ "<ComponentRef Id='MyProgram.json' />" +
136
+ "</ComponentGroup>" +
137
+ "</Fragment>" +
138
+ "</Wix>", testXml);
139
+
140
+ var pdbPath = Path.Combine(binFolder, "HeatFileMultpleFilesSameFileName.wixpdb");
141
+ Assert.True(File.Exists(pdbPath));
142
+
143
+ var intermediate = Intermediate.Load(pdbPath);
144
+ var section = intermediate.Sections.Single();
145
+
146
+ var fileTuples = section.Tuples.OfType<FileTuple>().ToArray();
147
+ Assert.Equal(@"SourceDir\MyProgram.txt", fileTuples[0][FileTupleFields.Source].PreviousValue.AsPath().Path);
148
+ Assert.Equal(@"SourceDir\MyProgram.json", fileTuples[1][FileTupleFields.Source].PreviousValue.AsPath().Path);
149
+ }
150
+ }
151
}
152
}
src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/HeatFileMultpleFilesSameFileName.wixproj
new
+61
@@ -0,0 +1,61 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <PropertyGroup>
4
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5
+ <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
6
+ </PropertyGroup>
7
+
8
+ <PropertyGroup>
9
+ <ProjectGuid>7fb77005-c6e0-454f-8c2d-0a4a79c918ba</ProjectGuid>
10
+ </PropertyGroup>
11
+
12
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
13
+ <PlatformName>$(Platform)</PlatformName>
14
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
15
+ <DefineConstants>Debug</DefineConstants>
16
+ </PropertyGroup>
17
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
18
+ <PlatformName>$(Platform)</PlatformName>
19
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
20
+ </PropertyGroup>
21
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
22
+ <PlatformName>$(Platform)</PlatformName>
23
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
24
+ <DefineConstants>Debug</DefineConstants>
25
+ </PropertyGroup>
26
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
27
+ <PlatformName>$(Platform)</PlatformName>
28
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
29
+ </PropertyGroup>
30
+
31
+ <ItemGroup>
32
+ <Compile Include="Package.wxs" />
33
+ </ItemGroup>
34
+
35
+ <ItemGroup>
36
+ <BindInputPaths Include="." />
37
+ </ItemGroup>
38
+
39
+ <PropertyGroup>
40
+ <HarvestFileSuppressUniqueIds>true</HarvestFileSuppressUniqueIds>
41
+ </PropertyGroup>
42
+
43
+ <ItemGroup>
44
+ <HarvestFile Include="MyProgram.txt">
45
+ <ComponentGroupName>TxtProductComponents</ComponentGroupName>
46
+ <DirectoryRefId>INSTALLFOLDER</DirectoryRefId>
47
+ <SuppressRootDirectory>true</SuppressRootDirectory>
48
+ </HarvestFile>
49
+ <HarvestFile Include="MyProgram.json">
50
+ <ComponentGroupName>JsonProductComponents</ComponentGroupName>
51
+ <DirectoryRefId>INSTALLFOLDER</DirectoryRefId>
52
+ <SuppressRootDirectory>true</SuppressRootDirectory>
53
+ </HarvestFile>
54
+ </ItemGroup>
55
+
56
+ <Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
57
+ <Import Project="$(MSBuildExtensionsPath32)\WixToolset\v4.x\wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\WixToolset\v4.x\wix.targets') " />
58
+ <Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
59
+ <Error Text="WiX Toolset build tools (v4.0 or later) must be installed to build this project. To download the WiX Toolset, go to http://wixtoolset.org/releases/." />
60
+ </Target>
61
+</Project>
\ No newline at end of file
src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.json
new
+1
@@ -0,0 +1 @@
1
+
\ No newline at end of file
src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.txt
new
+1
@@ -0,0 +1 @@
1
+
\ No newline at end of file
src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/Package.wxs
new
+22
@@ -0,0 +1,22 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
4
+ <Product Id="*" Name="HeatFilePackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
5
+ <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
6
+
7
+ <MediaTemplate />
8
+
9
+ <Feature Id="ProductFeature" Title="HeatFileFeature">
10
+ <ComponentGroupRef Id="TxtProductComponents" />
11
+ <ComponentGroupRef Id="JsonProductComponents" />
12
+ </Feature>
13
+ </Product>
14
+
15
+ <Fragment>
16
+ <Directory Id="TARGETDIR" Name="SourceDir">
17
+ <Directory Id="ProgramFilesFolder">
18
+ <Directory Id="INSTALLFOLDER" Name="MsiPackage" />
19
+ </Directory>
20
+ </Directory>
21
+ </Fragment>
22
+</Wix>
src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj
+5
-1
@@ -1,4 +1,4 @@
1
-<?xml version="1.0" encoding="utf-8"?>
1
+<?xml version="1.0" encoding="utf-8"?>
2
<!-- 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. -->
3
4
<Project Sdk="Microsoft.NET.Sdk">
@@ -12,6 +12,10 @@
12
<ItemGroup>
13
<Content Include="TestData\HeatFilePackage\HeatFilePackage.wixproj" CopyToOutputDirectory="PreserveNewest" />
14
<Content Include="TestData\HeatFilePackage\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
15
+ <Content Include="TestData\HeatFileMultpleFilesSameFileName\HeatFileMultpleFilesSameFileName.wixproj" CopyToOutputDirectory="PreserveNewest" />
16
+ <Content Include="TestData\HeatFileMultpleFilesSameFileName\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
17
+ <Content Include="TestData\HeatFileMultpleFilesSameFileName\MyProgram.txt" CopyToOutputDirectory="PreserveNewest" />
18
+ <Content Include="TestData\HeatFileMultpleFilesSameFileName\MyProgram.json" CopyToOutputDirectory="PreserveNewest" />
19
<Content Include="TestData\MultiCulturalMsiPackage\MsiPackage\MsiPackage.wixproj" CopyToOutputDirectory="PreserveNewest" />
20
<Content Include="TestData\MultiCulturalMsiPackage\MsiPackage\Package.de-de.wxl" CopyToOutputDirectory="PreserveNewest" />
21
<Content Include="TestData\MultiCulturalMsiPackage\MsiPackage\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" />