Allow unresolved variables during resolution.
Bob Arnson committed
Mar 18, 2020 at 21:45 UTC
c5df86a7caaa1cbff9adde6396925383ba9a2e4e
5 files changed
+13
-10
src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+3
-1
@@ -32,6 +32,8 @@ namespace WixToolset.Core.Bind
32
33
public bool SupportDelayedResolution { private get; set; }
34
35
+ public bool AllowUnresolvedVariables { private get; set; }
36
+
37
public IEnumerable<DelayedField> DelayedFields { get; private set; }
38
39
public void Execute()
@@ -62,7 +64,7 @@ namespace WixToolset.Core.Bind
64
var original = field.AsString();
65
if (!String.IsNullOrEmpty(original))
66
{
65
- var resolution = this.VariableResolver.ResolveVariables(tuple.SourceLineNumbers, original);
67
+ var resolution = this.VariableResolver.ResolveVariables(tuple.SourceLineNumbers, original, !this.AllowUnresolvedVariables);
68
if (resolution.UpdatedValue)
69
{
70
field.Set(resolution.Value);
src/WixToolset.Core/ResolveContext.cs
+2
@@ -33,5 +33,7 @@ namespace WixToolset.Core
33
public IEnumerable<Localization> Localizations { get; set; }
34
35
public IVariableResolver VariableResolver { get; set; }
36
+
37
+ public bool AllowUnresolvedVariables { get; set; }
38
}
39
}
src/WixToolset.Core/Resolver.cs
+1
@@ -87,6 +87,7 @@ namespace WixToolset.Core
87
command.IntermediateFolder = context.IntermediateFolder;
88
command.Intermediate = context.IntermediateRepresentation;
89
command.SupportDelayedResolution = true;
90
+ command.AllowUnresolvedVariables = context.AllowUnresolvedVariables;
91
command.Execute();
92
93
delayedFields = command.DelayedFields;
src/WixToolset.Core/VariableResolver.cs
+1
-8
@@ -77,14 +77,7 @@ namespace WixToolset.Core
77
return this.localizedControls.TryGetValue(key, out localizedControl);
78
}
79
80
- /// <summary>
81
- /// Resolve the wix variables in a value.
82
- /// </summary>
83
- /// <param name="sourceLineNumbers">The source line information for the value.</param>
84
- /// <param name="value">The value to resolve.</param>
85
- /// <param name="errorOnUnknown">true if unknown variables should throw errors.</param>
86
- /// <returns>The resolved value.</returns>
87
- internal IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool errorOnUnknown)
80
+ public IVariableResolution ResolveVariables(SourceLineNumber sourceLineNumbers, string value, bool errorOnUnknown)
81
{
82
var matches = Common.WixVariableRegex.Matches(value);
83
src/test/WixToolsetTest.CoreIntegration/VariableResolverFixture.cs
+6
-1
@@ -50,7 +50,12 @@ namespace WixToolsetTest.CoreIntegration
50
Assert.False(result.UpdatedValue);
51
Assert.True(result.DelayedResolve);
52
53
- Assert.Throws<WixException>(() => variableResolver.ResolveVariables(null, "Welcome to !(loc.UnknownLocalizationVariable)"));
53
+ var withUnknownLocString = "Welcome to !(loc.UnknownLocalizationVariable)";
54
+ Assert.Throws<WixException>(() => variableResolver.ResolveVariables(null, withUnknownLocString));
55
+
56
+ result = variableResolver.ResolveVariables(null, withUnknownLocString, errorOnUnknown: false);
57
+ Assert.Equal(withUnknownLocString, result.Value);
58
+ Assert.False(result.UpdatedValue);
59
60
result = variableResolver.ResolveVariables(null, "Welcome to !!(loc.UnknownLocalizationVariable)");
61
Assert.Equal("Welcome to !(loc.UnknownLocalizationVariable)", result.Value);