From 0b9fd5ae84460d943e685b9821473f356a66bd3b Mon Sep 17 00:00:00 2001 From: paulomorgado <470455+paulomorgado@users.noreply.github.com> Date: Mon, 25 May 2020 13:13:25 +0100 Subject: Allow more than one harvested file and files differing by extension add component and directory for more disambiguation Fix HarvestFile Ouput added unit tests --- src/WixToolset.BuildTasks/wix.harvest.targets | 4 +- .../MsbuildHeatFixture.cs | 79 +++++++++++++++++++++- .../HeatFileMultpleFilesSameFileName.wixproj | 61 +++++++++++++++++ .../MyProgram.json | 1 + .../HeatFileMultpleFilesSameFileName/MyProgram.txt | 1 + .../HeatFileMultpleFilesSameFileName/Package.wxs | 22 ++++++ .../WixToolsetTest.BuildTasks.csproj | 6 +- 7 files changed, 170 insertions(+), 4 deletions(-) create mode 100644 src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/HeatFileMultpleFilesSameFileName.wixproj create mode 100644 src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.json create mode 100644 src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.txt create mode 100644 src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/Package.wxs (limited to 'src') diff --git a/src/WixToolset.BuildTasks/wix.harvest.targets b/src/WixToolset.BuildTasks/wix.harvest.targets index a8be17df..5dd2f729 100644 --- a/src/WixToolset.BuildTasks/wix.harvest.targets +++ b/src/WixToolset.BuildTasks/wix.harvest.targets @@ -415,7 +415,7 @@ line.Contains(": warning")); Assert.Empty(warnings); - var generatedFilePath = Path.Combine(intermediateFolder, @"_HeatFilePackage_file.wxs"); + var generatedFilePath = Path.Combine(intermediateFolder, @"_ProductComponents_INSTALLFOLDER_HeatFilePackage.wixproj_file.wxs"); Assert.True(File.Exists(generatedFilePath)); var generatedContents = File.ReadAllText(generatedFilePath); @@ -71,5 +71,82 @@ namespace WixToolsetTest.BuildTasks Assert.Equal(@"SourceDir\HeatFilePackage.wixproj", fileTuple[FileTupleFields.Source].PreviousValue.AsPath().Path); } } + + [Fact] + public void CanBuildHeatFileWithMultipleFilesPackage() + { + var projectPath = TestData.Get(@"TestData\HeatFileMultpleFilesSameFileName\HeatFileMultpleFilesSameFileName.wixproj"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var binFolder = Path.Combine(baseFolder, @"bin\"); + var intermediateFolder = Path.Combine(baseFolder, @"obj\"); + + var result = MsbuildRunner.Execute(projectPath, new[] + { + $"-p:WixTargetsPath={WixTargetsPath}", + $"-p:IntermediateOutputPath={intermediateFolder}", + $"-p:OutputPath={binFolder}" + }); + result.AssertSuccess(); + + var heatCommandLines = result.Output.Where(line => line.TrimStart().StartsWith("heat.exe file")); + Assert.Equal(2, heatCommandLines.Count()); + + var warnings = result.Output.Where(line => line.Contains(": warning")); + Assert.Empty(warnings); + + var generatedFilePath = Path.Combine(intermediateFolder, @"_TxtProductComponents_INSTALLFOLDER_MyProgram.txt_file.wxs"); + Assert.True(File.Exists(generatedFilePath)); + + var generatedContents = File.ReadAllText(generatedFilePath); + var testXml = generatedContents.GetTestXml(); + Assert.Equal("" + + "" + + "" + + "" + + @"" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", testXml); + + generatedFilePath = Path.Combine(intermediateFolder, @"_JsonProductComponents_INSTALLFOLDER_MyProgram.json_file.wxs"); + Assert.True(File.Exists(generatedFilePath)); + + generatedContents = File.ReadAllText(generatedFilePath); + testXml = generatedContents.GetTestXml(); + Assert.Equal("" + + "" + + "" + + "" + + @"" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", testXml); + + var pdbPath = Path.Combine(binFolder, "HeatFileMultpleFilesSameFileName.wixpdb"); + Assert.True(File.Exists(pdbPath)); + + var intermediate = Intermediate.Load(pdbPath); + var section = intermediate.Sections.Single(); + + var fileTuples = section.Tuples.OfType().ToArray(); + Assert.Equal(@"SourceDir\MyProgram.txt", fileTuples[0][FileTupleFields.Source].PreviousValue.AsPath().Path); + Assert.Equal(@"SourceDir\MyProgram.json", fileTuples[1][FileTupleFields.Source].PreviousValue.AsPath().Path); + } + } } } diff --git a/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/HeatFileMultpleFilesSameFileName.wixproj b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/HeatFileMultpleFilesSameFileName.wixproj new file mode 100644 index 00000000..860fc2dd --- /dev/null +++ b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/HeatFileMultpleFilesSameFileName.wixproj @@ -0,0 +1,61 @@ + + + + Debug + x86 + + + + 7fb77005-c6e0-454f-8c2d-0a4a79c918ba + + + + $(Platform) + bin\$(Platform)\$(Configuration)\ + Debug + + + $(Platform) + bin\$(Platform)\$(Configuration)\ + + + $(Platform) + bin\$(Platform)\$(Configuration)\ + Debug + + + $(Platform) + bin\$(Platform)\$(Configuration)\ + + + + + + + + + + + + true + + + + + TxtProductComponents + INSTALLFOLDER + true + + + JsonProductComponents + INSTALLFOLDER + true + + + + + + + + + \ No newline at end of file diff --git a/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.json b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.json new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.json @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.txt b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.txt new file mode 100644 index 00000000..5f282702 --- /dev/null +++ b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/MyProgram.txt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/Package.wxs b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/Package.wxs new file mode 100644 index 00000000..884da274 --- /dev/null +++ b/src/test/WixToolsetTest.BuildTasks/TestData/HeatFileMultpleFilesSameFileName/Package.wxs @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj b/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj index 3909cc79..333c7c79 100644 --- a/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj +++ b/src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj @@ -1,4 +1,4 @@ - + @@ -12,6 +12,10 @@ + + + + -- cgit v1.2.3-55-g6feb