From dd3ab394ec6e37c24827294605857730f8e7a1a5 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 15 Nov 2022 23:38:46 -0800 Subject: Expose bind variables from build command and via MSBuild WixVariables property Also, resolves bind variables in path fields. Fixes 6995 and 7017 --- src/api/wix/WixToolset.Data/ErrorMessages.cs | 24 +-- .../Data/ILibraryContext.cs | 5 + .../Data/IResolveContext.cs | 5 + src/wix/WixToolset.BuildTasks/WixBuild.cs | 22 +++ .../WixToolset.Core/Bind/ResolveFieldsCommand.cs | 50 +++--- .../WixToolset.Core/CommandLine/BuildCommand.cs | 81 +++++++--- src/wix/WixToolset.Core/Librarian.cs | 5 + src/wix/WixToolset.Core/LibraryContext.cs | 2 + src/wix/WixToolset.Core/Linker.cs | 2 +- src/wix/WixToolset.Core/LinkerErrors.cs | 6 + src/wix/WixToolset.Core/ResolveContext.cs | 7 +- src/wix/WixToolset.Core/Resolver.cs | 5 + src/wix/WixToolset.Core/VariableResolver.cs | 9 +- src/wix/WixToolset.Sdk/tools/wix.targets | 4 +- .../WixToolsetTest.Core/VariableResolverFixture.cs | 75 +++++++++ .../TestData/WixVariable/Bundle.wxs | 11 ++ .../WixVariable/PackageWithBindVariableVersion.wxs | 33 ++++ .../WixVariable/PackageWithReplaceableVersion.wxs | 22 +++ .../VariableResolverFixture.cs | 76 --------- .../WixVariableFixture.cs | 174 +++++++++++++++++++++ src/wix/test/WixToolsetTest.Sdk/MsbuildFixture.cs | 92 +++++++---- .../MsiPackageWithBindVariables.wixproj | 16 ++ .../MsiPackageWithBindVariables/Package.en-us.wxl | 11 ++ .../MsiPackageWithBindVariables/Package.wxs | 17 ++ .../MsiPackageWithBindVariables/data/test.txt | 1 + .../TestData/Wixlib/SimpleWixlib/Library.wxs | 2 +- .../Wixlib/SimpleWixlib/SimpleWixlib.wixproj | 29 +--- .../TestData/Wixlib/SimpleWixlib/data/Library.txt | 1 - .../Wixlib/SimpleWixlib/data/subfolder/Library.txt | 1 + 29 files changed, 591 insertions(+), 197 deletions(-) create mode 100644 src/wix/test/WixToolsetTest.Core/VariableResolverFixture.cs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/Bundle.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithBindVariableVersion.wxs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/TestData/WixVariable/PackageWithReplaceableVersion.wxs delete mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs create mode 100644 src/wix/test/WixToolsetTest.CoreIntegration/WixVariableFixture.cs create mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/MsiPackageWithBindVariables.wixproj create mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/Package.en-us.wxl create mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/Package.wxs create mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/data/test.txt delete mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/Library.txt create mode 100644 src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/subfolder/Library.txt (limited to 'src') diff --git a/src/api/wix/WixToolset.Data/ErrorMessages.cs b/src/api/wix/WixToolset.Data/ErrorMessages.cs index c447f89d..0c7511b9 100644 --- a/src/api/wix/WixToolset.Data/ErrorMessages.cs +++ b/src/api/wix/WixToolset.Data/ErrorMessages.cs @@ -598,9 +598,9 @@ namespace WixToolset.Data return Message(sourceLineNumbers, Ids.ExpectedVariable, "A required variable was missing in the expression '{0}'.", expression); } - public static Message ExpectedWixVariableValue(string variableId) + public static Message ExpectedBindVariableValue(string variableId) { - return Message(null, Ids.ExpectedWixVariableValue, "The WiX variable '{0}' was declared without a value. Please specify a value for the variable.", variableId); + return Message(null, Ids.ExpectedBindVariableValue, "The bind variable '{0}' was declared without a value. Please specify a value for the variable.", variableId); } public static Message FamilyNameTooLong(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string value, int length) @@ -1081,9 +1081,9 @@ namespace WixToolset.Data return Message(null, Ids.IllegalWarningIdAsError, "Illegal value '{0}' for the -wx command line option. Specify a particular warning number, like '-wx6' to display the warning with ID 6 as an error, or '-wx' alone to suppress all warnings.", warningId); } - public static Message IllegalWixVariablePrefix(SourceLineNumber sourceLineNumbers, string variableId) + public static Message IllegalBindVariablePrefix(SourceLineNumber sourceLineNumbers, string variableId) { - return Message(sourceLineNumbers, Ids.IllegalWixVariablePrefix, "The WiX variable $(wix.{0}) uses an illegal prefix '$'. Please use the '!' prefix instead.", variableId); + return Message(sourceLineNumbers, Ids.IllegalBindVariablePrefix, "The bind variable $(wix.{0}) uses an illegal prefix '$'. Please use the '!' prefix instead.", variableId); } public static Message IllegalYesNoAlwaysValue(SourceLineNumber sourceLineNumbers, string elementName, string attributeName, string value) @@ -2231,14 +2231,14 @@ namespace WixToolset.Data return Message(null, Ids.WixFileNotFound, "The file '{0}' cannot be found.", file); } - public static Message WixVariableCollision(SourceLineNumber sourceLineNumbers, string variableId) + public static Message BindVariableCollision(SourceLineNumber sourceLineNumbers, string variableId) { - return Message(sourceLineNumbers, Ids.WixVariableCollision, "The WiX variable '{0}' is declared in more than one location. Please remove one of the declarations.", variableId); + return Message(sourceLineNumbers, Ids.BindVariableCollision, "The bind variable '{0}' is declared in more than one location. Please remove one of the declarations.", variableId); } - public static Message WixVariableUnknown(SourceLineNumber sourceLineNumbers, string variableId) + public static Message BindVariableUnknown(SourceLineNumber sourceLineNumbers, string variableId) { - return Message(sourceLineNumbers, Ids.WixVariableUnknown, "The WiX variable !(wix.{0}) is unknown. Please ensure the variable is declared on the command line for light.exe, via a WixVariable element, or inline using the syntax !(wix.{0}=some value which doesn't contain parenthesis).", variableId); + return Message(sourceLineNumbers, Ids.BindVariableUnknown, "The bind variable !(wix.{0}) is unknown. Please ensure the variable is declared on the command line for wix.exe, via a BindVariable element, or inline using the syntax !(wix.{0}=some value which doesn't contain parenthesis).", variableId); } public static Message NoSourceFiles() @@ -2474,10 +2474,10 @@ namespace WixToolset.Data VersionIndependentProgIdsCannotHaveIcons = 192, IllegalAttributeValueWithOtherAttribute = 193, InvalidMergeLanguage = 194, - WixVariableCollision = 195, - ExpectedWixVariableValue = 196, - WixVariableUnknown = 197, - IllegalWixVariablePrefix = 198, + BindVariableCollision = 195, + ExpectedBindVariableValue = 196, + BindVariableUnknown = 197, + IllegalBindVariablePrefix = 198, InvalidWixXmlNamespace = 199, UnhandledExtensionElement = 200, UnhandledExtensionAttribute = 201, diff --git a/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs b/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs index f3c4db6e..9fc767f6 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/ILibraryContext.cs @@ -27,6 +27,11 @@ namespace WixToolset.Extensibility.Data /// IReadOnlyCollection BindPaths { get; set; } + /// + /// Bind variables used when binding files. + /// + IDictionary BindVariables { get; set; } + /// /// Collection of extensions used during creation of library. /// diff --git a/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs b/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs index bec689ba..a2158e4f 100644 --- a/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs +++ b/src/api/wix/WixToolset.Extensibility/Data/IResolveContext.cs @@ -22,6 +22,11 @@ namespace WixToolset.Extensibility.Data /// IReadOnlyCollection BindPaths { get; set; } + /// + /// Bind variables used during resolution. + /// + IDictionary BindVariables { get; set; } + /// /// Resolve extensions. /// diff --git a/src/wix/WixToolset.BuildTasks/WixBuild.cs b/src/wix/WixToolset.BuildTasks/WixBuild.cs index d725abff..4cadd7e0 100644 --- a/src/wix/WixToolset.BuildTasks/WixBuild.cs +++ b/src/wix/WixToolset.BuildTasks/WixBuild.cs @@ -45,6 +45,8 @@ namespace WixToolset.BuildTasks public ITaskItem[] BindPaths { get; set; } + public ITaskItem[] BindVariables { get; set; } + public bool BindFiles { get; set; } public ITaskItem BindTrackingFile { get; set; } @@ -77,6 +79,7 @@ namespace WixToolset.BuildTasks commandLineBuilder.AppendIfTrue("-bindFiles", this.BindFiles); commandLineBuilder.AppendArrayIfNotNull("-bindPath ", this.CalculateBindPathStrings()); + commandLineBuilder.AppendArrayIfNotNull("-bindVariable ", this.CalculateBindVariableStrings()); commandLineBuilder.AppendArrayIfNotNull("-loc ", this.LocalizationFiles); commandLineBuilder.AppendArrayIfNotNull("-lib ", this.LibraryFiles); commandLineBuilder.AppendTextIfNotWhitespace(this.AdditionalOptions); @@ -103,5 +106,24 @@ namespace WixToolset.BuildTasks } } } + + private IEnumerable CalculateBindVariableStrings() + { + if (null != this.BindVariables) + { + foreach (var item in this.BindVariables) + { + var value = item.ItemSpec; + + var variableName = item.GetMetadata("Name"); + if (!String.IsNullOrEmpty(variableName)) + { + value = String.Concat(variableName, "=", value); + } + + yield return value; + } + } + } } } diff --git a/src/wix/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/wix/WixToolset.Core/Bind/ResolveFieldsCommand.cs index acdf999a..1129d96f 100644 --- a/src/wix/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/wix/WixToolset.Core/Bind/ResolveFieldsCommand.cs @@ -88,25 +88,21 @@ namespace WixToolset.Core.Bind var beforeErrorCount = this.Messaging.ErrorCount; - // Check to make sure we're in a scenario where we can handle variable resolution. - if (null != delayedFields) + // resolve localization and wix variables + if (fieldType == IntermediateFieldType.String) { - // resolve localization and wix variables - if (fieldType == IntermediateFieldType.String) + var original = field.AsString(); + if (!String.IsNullOrEmpty(original)) { - var original = field.AsString(); - if (!String.IsNullOrEmpty(original)) + var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, original, !this.AllowUnresolvedVariables); + if (resolution.UpdatedValue) { - var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, original, !this.AllowUnresolvedVariables); - if (resolution.UpdatedValue) - { - field.Set(resolution.Value); - } - - if (resolution.DelayedResolve) - { - delayedFields.Add(new DelayedField(symbol, field)); - } + field.Set(resolution.Value); + } + + if (resolution.DelayedResolve) + { + delayedFields.Add(new DelayedField(symbol, field)); } } } @@ -136,13 +132,27 @@ namespace WixToolset.Core.Bind // If the file is embedded and if the previous value has a bind variable in the path // which gets modified by resolving the previous value again then switch to that newly // resolved path instead of using the embedded file. - if (fieldValue.Embed && field.PreviousValue != null) + if (fieldValue.Embed) + { + if (field.PreviousValue != null) + { + var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, field.PreviousValue.AsString(), errorOnUnknown: false); + + if (resolution.UpdatedValue && !resolution.IsDefault) + { + fieldValue = new IntermediateFieldPathValue { Path = resolution.Value }; + } + } + } + else // resolve path field for bind variables. { - var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, field.PreviousValue.AsString(), errorOnUnknown: false); + var resolution = this.VariableResolver.ResolveVariables(symbol.SourceLineNumbers, fieldValue.Path, errorOnUnknown: false); - if (resolution.UpdatedValue && !resolution.IsDefault) + if (resolution.UpdatedValue) { - fieldValue = new IntermediateFieldPathValue { Path = resolution.Value }; + field.Set(resolution.Value); + + fieldValue = field.AsPath(); } } diff --git a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs index 53c4f798..aaa14396 100644 --- a/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/wix/WixToolset.Core/CommandLine/BuildCommand.cs @@ -10,6 +10,7 @@ namespace WixToolset.Core.CommandLine using System.Threading.Tasks; using System.Xml.Linq; using WixToolset.Data; + using WixToolset.Data.Bind; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; @@ -115,7 +116,7 @@ namespace WixToolset.Core.CommandLine { using (new IntermediateFieldContext("wix.lib")) { - this.LibraryPhase(wixobjs, wxls, inputsOutputs.LibraryPaths, creator, this.commandLine.BindFiles, this.commandLine.BindPaths, inputsOutputs.OutputPath, cancellationToken); + this.LibraryPhase(wixobjs, wxls, inputsOutputs.LibraryPaths, creator, this.commandLine.BindFiles, this.commandLine.BindPaths, this.commandLine.BindVariables, inputsOutputs.OutputPath, cancellationToken); } } else @@ -148,7 +149,7 @@ namespace WixToolset.Core.CommandLine { using (new IntermediateFieldContext("wix.bind")) { - this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.CabbingThreadCount, this.commandLine.BindPaths, inputsOutputs, cancellationToken); + this.BindPhase(wixipl, wxls, filterCultures, this.commandLine.CabCachePath, this.commandLine.CabbingThreadCount, this.commandLine.BindPaths, this.commandLine.BindVariables, inputsOutputs, cancellationToken); } } } @@ -206,7 +207,7 @@ namespace WixToolset.Core.CommandLine return intermediates; } - private void LibraryPhase(IReadOnlyCollection intermediates, IReadOnlyCollection localizations, IEnumerable libraryFiles, ISymbolDefinitionCreator creator, bool bindFiles, IReadOnlyCollection bindPaths, string outputPath, CancellationToken cancellationToken) + private void LibraryPhase(IReadOnlyCollection intermediates, IReadOnlyCollection localizations, IEnumerable libraryFiles, ISymbolDefinitionCreator creator, bool bindFiles, IReadOnlyCollection bindPaths, Dictionary bindVariables, string outputPath, CancellationToken cancellationToken) { var libraries = this.LoadLibraries(libraryFiles, creator); @@ -218,6 +219,7 @@ namespace WixToolset.Core.CommandLine var context = this.ServiceProvider.GetService(); context.BindFiles = bindFiles; context.BindPaths = bindPaths; + context.BindVariables = bindVariables; context.Extensions = this.ExtensionManager.GetServices(); context.Localizations = localizations; context.IntermediateFolder = this.IntermediateFolder; @@ -266,12 +268,13 @@ namespace WixToolset.Core.CommandLine return linker.Link(context); } - private void BindPhase(Intermediate output, IReadOnlyCollection localizations, IReadOnlyCollection filterCultures, string cabCachePath, int cabbingThreadCount, IReadOnlyCollection bindPaths, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken) + private void BindPhase(Intermediate output, IReadOnlyCollection localizations, IReadOnlyCollection filterCultures, string cabCachePath, int cabbingThreadCount, IReadOnlyCollection bindPaths, Dictionary bindVariables, InputsAndOutputs inputsOutputs, CancellationToken cancellationToken) { IResolveResult resolveResult; { var context = this.ServiceProvider.GetService(); context.BindPaths = bindPaths; + context.BindVariables = bindVariables; context.Extensions = this.ExtensionManager.GetServices(); context.ExtensionData = this.ExtensionManager.GetServices(); context.FilterCultures = filterCultures; @@ -466,6 +469,8 @@ namespace WixToolset.Core.CommandLine public List BindPaths { get; } = new List(); + public Dictionary BindVariables { get; } = new Dictionary(); + public string CabCachePath { get; private set; } public int CabbingThreadCount { get; private set; } @@ -564,6 +569,24 @@ namespace WixToolset.Core.CommandLine return true; } + case "bv": + case "bindvariable": + { + var value = parser.GetNextArgumentOrError(arg); + if (value != null && TryParseNameValuePair(value, out var parsedName, out var parsedValue)) + { + if (this.BindVariables.TryGetValue(parsedName, out var collisionValue)) + { + parser.ReportErrorArgument(arg, LinkerErrors.DuplicateBindPathVariableOnCommandLine(arg, parsedName, parsedValue, collisionValue)); + } + else + { + this.BindVariables.Add(parsedName, parsedValue); + } + } + return true; + } + case "cc": case "cabcache": this.CabCachePath = parser.GetNextArgumentOrError(arg); @@ -651,20 +674,20 @@ namespace WixToolset.Core.CommandLine return true; case "pdbtype": + { + var value = parser.GetNextArgumentOrError(arg); + if (Enum.TryParse(value, true, out PdbType pdbType)) { - var value = parser.GetNextArgumentOrError(arg); - if (Enum.TryParse(value, true, out PdbType pdbType)) - { - this.PdbType = pdbType; - } - else if (!String.IsNullOrEmpty(value)) - { - parser.ReportErrorArgument(arg, ErrorMessages.IllegalCommandLineArgumentValue(arg, value, Enum.GetNames(typeof(PdbType)).Select(s => s.ToLowerInvariant()))); - } - - return true; + this.PdbType = pdbType; + } + else if (!String.IsNullOrEmpty(value)) + { + parser.ReportErrorArgument(arg, ErrorMessages.IllegalCommandLineArgumentValue(arg, value, Enum.GetNames(typeof(PdbType)).Select(s => s.ToLowerInvariant()))); } + return true; + } + case "resetacls": this.ResetAcls = true; return true; @@ -870,18 +893,16 @@ namespace WixToolset.Core.CommandLine private bool TryParseBindPath(string argument, string bindPath, out IBindPath bp) { - var namedPath = bindPath.Split(BindPathSplit, 2); - bp = this.ServiceProvider.GetService(); - if (1 == namedPath.Length) + if (TryParseNameValuePair(bindPath, out var name, out var path)) { - bp.Path = namedPath[0]; + bp.Name = name; + bp.Path = path; } else { - bp.Name = namedPath[0]; - bp.Path = namedPath[1]; + bp.Path = bindPath; } if (File.Exists(bp.Path)) @@ -892,6 +913,24 @@ namespace WixToolset.Core.CommandLine return true; } + + private static bool TryParseNameValuePair(string nameValuePair, out string key, out string value) + { + var split = nameValuePair.Split(BindPathSplit, 2); + + if (1 == split.Length) + { + key = null; + value = null; + + return false; + } + + key = split[0]; + value = split[1]; + + return true; + } } private class InputsAndOutputs diff --git a/src/wix/WixToolset.Core/Librarian.cs b/src/wix/WixToolset.Core/Librarian.cs index 968dd946..1f366d55 100644 --- a/src/wix/WixToolset.Core/Librarian.cs +++ b/src/wix/WixToolset.Core/Librarian.cs @@ -99,6 +99,11 @@ namespace WixToolset.Core { var variableResolver = this.ServiceProvider.GetService(); + foreach (var bindVariable in context.BindVariables) + { + variableResolver.AddVariable(null, bindVariable.Key, bindVariable.Value, false); + } + var bindPaths = context.BindPaths.Where(b => b.Stage == BindStage.Normal).ToList(); foreach (var symbol in sections.SelectMany(s => s.Symbols)) diff --git a/src/wix/WixToolset.Core/LibraryContext.cs b/src/wix/WixToolset.Core/LibraryContext.cs index a463844e..207e8e1b 100644 --- a/src/wix/WixToolset.Core/LibraryContext.cs +++ b/src/wix/WixToolset.Core/LibraryContext.cs @@ -25,6 +25,8 @@ namespace WixToolset.Core public IReadOnlyCollection BindPaths { get; set; } + public IDictionary BindVariables { get; set; } + public IReadOnlyCollection Extensions { get; set; } public string LibraryId { get; set; } diff --git a/src/wix/WixToolset.Core/Linker.cs b/src/wix/WixToolset.Core/Linker.cs index 9360c8d0..a3d99039 100644 --- a/src/wix/WixToolset.Core/Linker.cs +++ b/src/wix/WixToolset.Core/Linker.cs @@ -333,7 +333,7 @@ namespace WixToolset.Core } else if (!symbol.Overridable || (collidingSymbol.Overridable && symbol.Overridable)) { - this.Messaging.Write(ErrorMessages.WixVariableCollision(symbol.SourceLineNumbers, id)); + this.Messaging.Write(ErrorMessages.BindVariableCollision(symbol.SourceLineNumbers, id)); } } else diff --git a/src/wix/WixToolset.Core/LinkerErrors.cs b/src/wix/WixToolset.Core/LinkerErrors.cs index 1d9a5a07..cb13a344 100644 --- a/src/wix/WixToolset.Core/LinkerErrors.cs +++ b/src/wix/WixToolset.Core/LinkerErrors.cs @@ -6,6 +6,11 @@ namespace WixToolset.Core internal static class LinkerErrors { + public static Message DuplicateBindPathVariableOnCommandLine(string argument, string bindName, string bindValue, string collisionValue) + { + return Message(null, Ids.DuplicateBindPathVariableOnCommandLine, "", argument, bindName, bindValue, collisionValue); + } + public static Message OrphanedPayload(SourceLineNumber sourceLineNumbers, string payloadId) { return Message(sourceLineNumbers, Ids.OrphanedPayload, "Found orphaned Payload '{0}'. Make sure to reference it from a Package, the BootstrapperApplication, or the Bundle or move it into its own Fragment so it only gets linked in when actually used.", payloadId); @@ -55,6 +60,7 @@ namespace WixToolset.Core UnscheduledRollbackBoundary = 7004, UncompressedPayloadInContainer = 7005, BAContainerCannotContainRemotePayload = 7006, + DuplicateBindPathVariableOnCommandLine = 7007, } // last available is 7099. 7100 is WindowsInstallerBackendWarnings. } } diff --git a/src/wix/WixToolset.Core/ResolveContext.cs b/src/wix/WixToolset.Core/ResolveContext.cs index a56ce4c9..0d6d1925 100644 --- a/src/wix/WixToolset.Core/ResolveContext.cs +++ b/src/wix/WixToolset.Core/ResolveContext.cs @@ -8,8 +8,7 @@ namespace WixToolset.Core using WixToolset.Data; using WixToolset.Extensibility; using WixToolset.Extensibility.Data; - using WixToolset.Extensibility.Services; - + internal class ResolveContext : IResolveContext { internal ResolveContext(IServiceProvider serviceProvider) @@ -21,6 +20,8 @@ namespace WixToolset.Core public IReadOnlyCollection BindPaths { get; set; } + public IDictionary BindVariables { get; set; } + public IReadOnlyCollection Extensions { get; set; } public IReadOnlyCollection ExtensionData { get; set; } @@ -33,8 +34,6 @@ namespace WixToolset.Core public IReadOnlyCollection Localizations { get; set; } - public IVariableResolver VariableResolver { get; set; } - public bool AllowUnresolvedVariables { get; set; } public string OutputPath { get; set; } diff --git a/src/wix/WixToolset.Core/Resolver.cs b/src/wix/WixToolset.Core/Resolver.cs index f7aa6ff9..2eebc80a 100644 --- a/src/wix/WixToolset.Core/Resolver.cs +++ b/src/wix/WixToolset.Core/Resolver.cs @@ -187,6 +187,11 @@ namespace WixToolset.Core variableResolver.AddLocalization(localization); } + foreach (var bindVariable in context.BindVariables) + { + variableResolver.AddVariable(null, bindVariable.Key, bindVariable.Value, false); + } + // Gather all the wix variables. var wixVariableSymbols = context.IntermediateRepresentation.Sections.SelectMany(s => s.Symbols).OfType(); foreach (var symbol in wixVariableSymbols) diff --git a/src/wix/WixToolset.Core/VariableResolver.cs b/src/wix/WixToolset.Core/VariableResolver.cs index 437cabb7..987a2290 100644 --- a/src/wix/WixToolset.Core/VariableResolver.cs +++ b/src/wix/WixToolset.Core/VariableResolver.cs @@ -23,7 +23,6 @@ namespace WixToolset.Core /// internal VariableResolver(IServiceProvider serviceProvider) { - this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); this.locVariables = new Dictionary(); @@ -31,8 +30,6 @@ namespace WixToolset.Core this.localizedControls = new Dictionary(); } - private IServiceProvider ServiceProvider { get; } - private IMessaging Messaging { get; } public int VariableCount => this.wixVariables.Count; @@ -47,7 +44,7 @@ namespace WixToolset.Core } } - foreach (KeyValuePair localizedControl in localization.LocalizedControls) + foreach (var localizedControl in localization.LocalizedControls) { if (!this.localizedControls.ContainsKey(localizedControl.Key)) { @@ -62,7 +59,7 @@ namespace WixToolset.Core if (!TryAddWixVariable(this.wixVariables, bindVariable)) { - this.Messaging.Write(ErrorMessages.WixVariableCollision(sourceLineNumber, name)); + this.Messaging.Write(ErrorMessages.BindVariableCollision(sourceLineNumber, name)); } } @@ -166,7 +163,7 @@ namespace WixToolset.Core } else if ("wix" == variableNamespace && errorOnUnknown) // unresolved wix variable { - this.Messaging.Write(ErrorMessages.WixVariableUnknown(sourceLineNumbers, variableId)); + this.Messaging.Write(ErrorMessages.BindVariableUnknown(sourceLineNumbers, variableId)); } start = parsed.Index + parsed.Length; diff --git a/src/wix/WixToolset.Sdk/tools/wix.targets b/src/wix/WixToolset.Sdk/tools/wix.targets index 067fa412..ff9b2eb1 100644 --- a/src/wix/WixToolset.Sdk/tools/wix.targets +++ b/src/wix/WixToolset.Sdk/tools/wix.targets @@ -41,7 +41,7 @@ - + + + + + + + diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/Package.wxs b/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/Package.wxs new file mode 100644 index 00000000..c11ef3ba --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/Package.wxs @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/data/test.txt b/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/data/test.txt new file mode 100644 index 00000000..cd0db0e1 --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/MsiPackageWithBindVariables/data/test.txt @@ -0,0 +1 @@ +This is test.txt. \ No newline at end of file diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/Library.wxs b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/Library.wxs index 8ffb3e8a..95cc8cb3 100644 --- a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/Library.wxs +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/Library.wxs @@ -8,7 +8,7 @@ - + diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/SimpleWixlib.wixproj b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/SimpleWixlib.wixproj index 88dfdc39..415bacc7 100644 --- a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/SimpleWixlib.wixproj +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/SimpleWixlib.wixproj @@ -1,34 +1,11 @@ - + + - Debug - x86 Library true - - - - {9F84998B-7F45-4CB3-8795-915801DBBB74} - - - - $(Platform) - bin\$(Platform)\$(Configuration)\ - Debug - - - $(Platform) - bin\$(Platform)\$(Configuration)\ - - - $(Platform) - bin\$(Platform)\$(Configuration)\ - Debug - - - $(Platform) - bin\$(Platform)\$(Configuration)\ + SubfolderVar=subfolder diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/Library.txt b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/Library.txt deleted file mode 100644 index 19a811ae..00000000 --- a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/Library.txt +++ /dev/null @@ -1 +0,0 @@ -This is Library.txt. diff --git a/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/subfolder/Library.txt b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/subfolder/Library.txt new file mode 100644 index 00000000..19a811ae --- /dev/null +++ b/src/wix/test/WixToolsetTest.Sdk/TestData/Wixlib/SimpleWixlib/data/subfolder/Library.txt @@ -0,0 +1 @@ +This is Library.txt. -- cgit v1.2.3-55-g6feb