Fix MSBuild handling of cultures plus add unit tests
Fixes #5847
Rob Mensching committed
Jul 13, 2018 at 15:08 UTC
06835732a8e6e9d18d548fbb4487bcaf5c8e1725
20 files changed
+260
-16
src/WixToolset.BuildTasks/DoIt.cs
+2
-2
@@ -28,7 +28,7 @@ namespace WixToolset.BuildTasks
28
29
public string AdditionalOptions { get; set; }
30
31
- public string Cultures { get; set; }
31
+ public string[] Cultures { get; set; }
32
33
public string[] DefineConstants { get; set; }
34
@@ -145,7 +145,7 @@ namespace WixToolset.BuildTasks
145
commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
146
commandLineBuilder.AppendSwitchIfNotNull("-outputType ", this.OutputType);
147
commandLineBuilder.AppendIfTrue("-nologo", this.NoLogo);
148
- commandLineBuilder.AppendSwitchIfNotNull("-cultures ", this.Cultures);
148
+ commandLineBuilder.AppendArrayIfNotNull("-culture ", this.Cultures);
149
commandLineBuilder.AppendArrayIfNotNull("-d ", this.DefineConstants);
150
commandLineBuilder.AppendArrayIfNotNull("-I ", this.IncludeSearchPaths);
151
commandLineBuilder.AppendExtensions(this.Extensions, this.ExtensionDirectory, this.ReferencePaths);
src/WixToolset.BuildTasks/WixAssignCulture.cs
+3
-5
@@ -174,8 +174,6 @@ namespace WixToolset.BuildTasks
174
175
private class CultureGroup
176
{
177
- private List<string> cultures = new List<string>();
178
-
177
/// <summary>
178
/// TargetPath already has a '\', do not double it!
179
/// </summary>
@@ -193,11 +191,11 @@ namespace WixToolset.BuildTasks
191
Debug.Assert(!String.IsNullOrEmpty(cultureGroupString));
192
foreach (string cultureString in cultureGroupString.Split(','))
193
{
196
- this.cultures.Add(cultureString);
194
+ this.Cultures.Add(cultureString);
195
}
196
}
197
200
- public List<string> Cultures { get { return cultures; } }
198
+ public List<string> Cultures { get; } = new List<string>();
199
200
public string OutputFolder
201
{
@@ -218,7 +216,7 @@ namespace WixToolset.BuildTasks
216
{
217
if (this.Cultures.Count > 0)
218
{
221
- return String.Join(",", this.Cultures.ToArray());
219
+ return String.Join(";", this.Cultures);
220
}
221
222
// We use a keyword for a null culture because MSBuild cannnot handle "" items
src/WixToolset.Core/Resolver.cs
+1
-1
@@ -232,7 +232,6 @@ namespace WixToolset.Core
232
233
var localizations = context.Localizations.Concat(context.IntermediateRepresentation.Localizations).ToList();
234
235
- // If there still is no filter, return all localizations.
235
AddFilteredLocalizations(result, filter, localizations);
236
237
// Filter localizations provided by extensions with data.
@@ -270,6 +269,7 @@ namespace WixToolset.Core
269
270
private static void AddFilteredLocalizations(List<Localization> result, IEnumerable<string> filter, IEnumerable<Localization> localizations)
271
{
272
+ // If there is no filter, return all localizations.
273
if (!filter.Any())
274
{
275
result.AddRange(localizations);
src/test/WixToolsetTest.BuildTasks/FakeBuildEngine.cs
new
+29
@@ -0,0 +1,29 @@
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.BuildTasks
4
+{
5
+ using System.Collections;
6
+ using System.Diagnostics;
7
+ using Microsoft.Build.Framework;
8
+
9
+ internal class FakeBuildEngine : IBuildEngine
10
+ {
11
+ public int ColumnNumberOfTaskNode => 0;
12
+
13
+ public bool ContinueOnError => false;
14
+
15
+ public int LineNumberOfTaskNode => 0;
16
+
17
+ public string ProjectFileOfTaskNode => "fake_wix.targets";
18
+
19
+ public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs) => throw new System.NotImplementedException();
20
+
21
+ public void LogCustomEvent(CustomBuildEventArgs e) => Debug.Write(e.Message);
22
+
23
+ public void LogErrorEvent(BuildErrorEventArgs e) => Debug.Write(e.Message);
24
+
25
+ public void LogMessageEvent(BuildMessageEventArgs e) => Debug.Write(e.Message);
26
+
27
+ public void LogWarningEvent(BuildWarningEventArgs e) => Debug.Write(e.Message);
28
+ }
29
+}
src/test/WixToolsetTest.BuildTasks/MsbuildFixture.cs
new
+62
@@ -0,0 +1,62 @@
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.BuildTasks
4
+{
5
+ using System.IO;
6
+ using System.Linq;
7
+ using Microsoft.Build.Utilities;
8
+ using WixBuildTools.TestSupport;
9
+ using WixToolset.BuildTasks;
10
+ using WixToolset.Data;
11
+ using WixToolset.Data.Tuples;
12
+ using Xunit;
13
+
14
+ public partial class MsbuildFixture
15
+ {
16
+ [Fact]
17
+ public void CanBuildSingleFile()
18
+ {
19
+ var folder = TestData.Get(@"TestData\SimpleMsiPackage\MsiPackage");
20
+
21
+ using (var fs = new DisposableFileSystem())
22
+ {
23
+ var baseFolder = fs.GetFolder();
24
+ var intermediateFolder = Path.Combine(baseFolder, "obj");
25
+
26
+ var task = new DoIt
27
+ {
28
+ BuildEngine = new FakeBuildEngine(),
29
+ SourceFiles = new[]
30
+ {
31
+ new TaskItem(Path.Combine(folder, "Package.wxs")),
32
+ new TaskItem(Path.Combine(folder, "PackageComponents.wxs")),
33
+ },
34
+ LocalizationFiles = new[]
35
+ {
36
+ new TaskItem(Path.Combine(folder, "Package.en-us.wxl")),
37
+ },
38
+ BindInputPaths = new[]
39
+ {
40
+ new TaskItem(Path.Combine(folder, "data")),
41
+ },
42
+ IntermediateDirectory = new TaskItem(intermediateFolder),
43
+ OutputFile = new TaskItem(Path.Combine(baseFolder, @"bin\test.msi")),
44
+ };
45
+
46
+ var result = task.Execute();
47
+ Assert.True(result, "MSBuild task failed unexpectedly.");
48
+
49
+ Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.msi")));
50
+ Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\test.wixpdb")));
51
+ Assert.True(File.Exists(Path.Combine(baseFolder, @"bin\cab1.cab")));
52
+
53
+ var intermediate = Intermediate.Load(Path.Combine(baseFolder, @"bin\test.wir"));
54
+ var section = intermediate.Sections.Single();
55
+
56
+ var wixFile = section.Tuples.OfType<WixFileTuple>().Single();
57
+ Assert.Equal(Path.Combine(folder, @"data\test.txt"), wixFile[WixFileTupleFields.Source].AsPath().Path);
58
+ Assert.Equal(@"test.txt", wixFile[WixFileTupleFields.Source].PreviousValue.AsPath().Path);
59
+ }
60
+ }
61
+ }
62
+}
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/MsiPackage.wixproj
new
+57
@@ -0,0 +1,57 @@
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
+ <ProductVersion>0.9</ProductVersion>
7
+ <ProjectGuid>7fb77005-c6e0-454f-8c2d-0a4a79c918ba</ProjectGuid>
8
+ <OutputName>MsiPackage</OutputName>
9
+ <OutputType>Package</OutputType>
10
+ <Name>MsiPackage</Name>
11
+ <RootNamespace>MsiPackage</RootNamespace>
12
+ <Cultures>en-US,en;de-DE</Cultures>
13
+ </PropertyGroup>
14
+
15
+ <PropertyGroup>
16
+ <WixTargetsPath>..\..\..\..\..\..\build\Release\publish\net461\wix.targets</WixTargetsPath>
17
+ </PropertyGroup>
18
+
19
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
20
+ <PlatformName>$(Platform)</PlatformName>
21
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
22
+ <DefineConstants>Debug</DefineConstants>
23
+ </PropertyGroup>
24
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
25
+ <PlatformName>$(Platform)</PlatformName>
26
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
27
+ </PropertyGroup>
28
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
29
+ <PlatformName>$(Platform)</PlatformName>
30
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
31
+ <DefineConstants>Debug</DefineConstants>
32
+ </PropertyGroup>
33
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
34
+ <PlatformName>$(Platform)</PlatformName>
35
+ <OutputPath>bin\$(Platform)\$(Configuration)\</OutputPath>
36
+ </PropertyGroup>
37
+
38
+ <ItemGroup>
39
+ <Compile Include="Package.wxs" />
40
+ <Compile Include="PackageComponents.wxs" />
41
+ </ItemGroup>
42
+
43
+ <ItemGroup>
44
+ <EmbeddedResource Include="Package.en-us.wxl" />
45
+ <EmbeddedResource Include="Package.de-de.wxl" />
46
+ </ItemGroup>
47
+
48
+ <ItemGroup>
49
+ <BindInputPaths Include="data" />
50
+ </ItemGroup>
51
+
52
+ <Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
53
+ <Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets') " />
54
+ <Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
55
+ <Error Text="WiX Toolset build tools (v3.11 or later) must be installed to build this project. To download the WiX Toolset, go to http://wixtoolset.org/releases/." />
56
+ </Target>
57
+</Project>
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/Package.de-de.wxl
new
+11
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<!--
4
+This file contains the declaration of all the localizable strings.
5
+-->
6
+<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="de-DE">
7
+
8
+ <String Id="DowngradeError">German DowngradeError</String>
9
+ <String Id="FeatureTitle">German FeatureTitle</String>
10
+
11
+</WixLocalization>
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/Package.en-us.wxl
renamed
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/Package.wxs
renamed
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/PackageComponents.wxs
renamed
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MsiPackage/data/test.txt
renamed
src/test/WixToolsetTest.BuildTasks/TestData/MultiCulturalMsiPackage/MultiCulturalMsiPackage.sln
renamed
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/MsiPackage.wixproj
renamed
+1
-1
@@ -50,6 +50,6 @@
50
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
51
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\wix.targets') " />
52
<Target Name="EnsureWixToolsetInstalled" Condition=" '$(WixTargetsImported)' != 'true' ">
53
- <Error Text="FG-WiX or WiX Toolset build tools (v3.11 or later) must be installed to build this project. To download FG-WiX, go to https://www.firegiant.com/downloads/. To download the WiX Toolset, go to http://wixtoolset.org/releases/." />
53
+ <Error Text="WiX Toolset build tools (v3.11 or later) must be installed to build this project. To download the WiX Toolset, go to http://wixtoolset.org/releases/." />
54
</Target>
55
</Project>
\ No newline at end of file
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/Package.en-us.wxl
new
+11
@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+
3
+<!--
4
+This file contains the declaration of all the localizable strings.
5
+-->
6
+<WixLocalization xmlns="http://wixtoolset.org/schemas/v4/wxl" Culture="en-US">
7
+
8
+ <String Id="DowngradeError">A newer version of [ProductName] is already installed.</String>
9
+ <String Id="FeatureTitle">MsiPackage</String>
10
+
11
+</WixLocalization>
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/Package.wxs
new
+21
@@ -0,0 +1,21 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
+ <Product Id="*" Name="MsiPackage" Language="1033" Version="1.0.0.0" Manufacturer="Example Corporation" UpgradeCode="047730a5-30fe-4a62-a520-da9381b8226a">
4
+ <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
5
+
6
+ <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
7
+ <MediaTemplate />
8
+
9
+ <Feature Id="ProductFeature" Title="!(loc.FeatureTitle)">
10
+ <ComponentGroupRef Id="ProductComponents" />
11
+ </Feature>
12
+ </Product>
13
+
14
+ <Fragment>
15
+ <Directory Id="TARGETDIR" Name="SourceDir">
16
+ <Directory Id="ProgramFilesFolder">
17
+ <Directory Id="INSTALLFOLDER" Name="MsiPackage" />
18
+ </Directory>
19
+ </Directory>
20
+ </Fragment>
21
+</Wix>
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/PackageComponents.wxs
new
+10
@@ -0,0 +1,10 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
3
+ <Fragment>
4
+ <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
5
+ <Component>
6
+ <File Source="test.txt" />
7
+ </Component>
8
+ </ComponentGroup>
9
+ </Fragment>
10
+</Wix>
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/MsiPackage/data/test.txt
new
+1
@@ -0,0 +1 @@
1
+This is test.txt.
\ No newline at end of file
src/test/WixToolsetTest.BuildTasks/TestData/SimpleMsiPackage/SimpleMsiPackage.sln
new
+31
@@ -0,0 +1,31 @@
1
+
2
+Microsoft Visual Studio Solution File, Format Version 12.00
3
+# Visual Studio 15
4
+VisualStudioVersion = 15.0.26730.8
5
+MinimumVisualStudioVersion = 10.0.40219.1
6
+Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "MsiPackage", "MsiPackage\MsiPackage.wixproj", "{7FB77005-C6E0-454F-8C2D-0A4A79C918BA}"
7
+EndProject
8
+Global
9
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
10
+ Debug|x64 = Debug|x64
11
+ Debug|x86 = Debug|x86
12
+ Release|x64 = Release|x64
13
+ Release|x86 = Release|x86
14
+ EndGlobalSection
15
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
16
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Debug|x64.ActiveCfg = Debug|x64
17
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Debug|x64.Build.0 = Debug|x64
18
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Debug|x86.ActiveCfg = Debug|x86
19
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Debug|x86.Build.0 = Debug|x86
20
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Release|x64.ActiveCfg = Release|x64
21
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Release|x64.Build.0 = Release|x64
22
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Release|x86.ActiveCfg = Release|x86
23
+ {7FB77005-C6E0-454F-8C2D-0A4A79C918BA}.Release|x86.Build.0 = Release|x86
24
+ EndGlobalSection
25
+ GlobalSection(SolutionProperties) = preSolution
26
+ HideSolutionNode = FALSE
27
+ EndGlobalSection
28
+ GlobalSection(ExtensibilityGlobals) = postSolution
29
+ SolutionGuid = {585B0599-4EB5-4AB6-BC66-819CC78B63D5}
30
+ EndGlobalSection
31
+EndGlobal
src/test/WixToolsetTest.BuildTasks/WixToolsetTest.BuildTasks.csproj
+19
-6
@@ -1,19 +1,32 @@
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">
5
<PropertyGroup>
6
- <TargetFramework>netcoreapp2.1</TargetFramework>
7
- <Description></Description>
8
- <Title>WiX Toolset Tests for MSBuild Tasks</Title>
6
+ <TargetFramework>net461</TargetFramework>
7
+ <IsPackable>false</IsPackable>
8
<DebugType>embedded</DebugType>
9
</PropertyGroup>
10
+
11
+ <ItemGroup>
12
+ <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.en-us.wxl" CopyToOutputDirectory="PreserveNewest" />
13
+ <Content Include="TestData\SimpleMsiPackage\MsiPackage\Package.wxs" CopyToOutputDirectory="PreserveNewest" />
14
+ <Content Include="TestData\SimpleMsiPackage\MsiPackage\PackageComponents.wxs" CopyToOutputDirectory="PreserveNewest" />
15
+ <Content Include="TestData\SimpleMsiPackage\MsiPackage\data\test.txt" CopyToOutputDirectory="PreserveNewest" />
16
+ </ItemGroup>
17
+
18
+ <ItemGroup>
19
+ <ProjectReference Include="..\..\WixToolset.BuildTasks\WixToolset.BuildTasks.csproj" />
20
+ </ItemGroup>
21
22
<ItemGroup>
13
- <!-- <ProjectReference Include="..\..\WixToolset.BuildTasks\WixToolset.BuildTasks.csproj" /> -->
23
+ <PackageReference Include="Microsoft.Build.Tasks.Core" Version="14.3" PrivateAssets="All" />
24
+ <PackageReference Include="WixBuildTools.TestSupport" Version="4.0.*" />
25
</ItemGroup>
26
27
<ItemGroup>
17
- <PackageReference Include="Nerdbank.GitVersioning" Version="2.1.65" PrivateAssets="all" />
28
+ <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.2" />
29
+ <PackageReference Include="xunit" Version="2.3.1" />
30
+ <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
31
</ItemGroup>
32
</Project>
src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj
+1
-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">