Skip to content

Commit 9c53f72

Browse files
committed
Add support for hexadecimal values (like 0xFF) ​​to msbuild property BaseAddress
This was a bug, because loading a project with <BaseAddress>0x06800000</BaseAddress> the property value was silently ignored
1 parent 67829f1 commit 9c53f72

File tree

2 files changed

+36
-21
lines changed

2 files changed

+36
-21
lines changed

vsintegration/src/unittests/Tests.ProjectSystem.Miscellaneous.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,15 @@ type Utilities() =
768768
()
769769

770770

771+
[<Test>]
772+
member public this.``Parse MSBuild property of type Int64`` () =
773+
Assert.AreEqual(123L, ProjectNode.ParsePropertyValueToInt64("123"))
774+
Assert.AreEqual(255L, ProjectNode.ParsePropertyValueToInt64("0xFF"))
775+
Assert.AreEqual(null, ProjectNode.ParsePropertyValueToInt64(""))
776+
Assert.AreEqual(null, ProjectNode.ParsePropertyValueToInt64(null))
777+
Assert.Throws<Exception>(fun () -> ignore (ProjectNode.ParsePropertyValueToInt64("abc"))) |> ignore
778+
Assert.Throws<Exception>(fun () -> ignore (ProjectNode.ParsePropertyValueToInt64("12333333333333333333333333"))) |> ignore
779+
771780

772781
#if DEBUGGERVISUALIZER
773782
module internal DebugViz =

vsintegration/src/vs/FsPkgs/FSharp.Project/Common.Source.CSharp/Project/ProjectNode.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,24 @@ public virtual void SetOrCreateBuildEventProperty(string propertyName, string pr
25602560
}
25612561
}
25622562

2563+
/// <remarks>Support hex format (like 0xFF)</remarks>
2564+
/// <exception cref="System.Exception">
2565+
/// Raise if invalid format
2566+
/// The inner exception contains the real exception, of type FormatException, StackOverflowException
2567+
/// </exception>
2568+
public static long? ParsePropertyValueToInt64(string s)
2569+
{
2570+
if (string.IsNullOrWhiteSpace(s))
2571+
return null;
2572+
2573+
var converter = new System.ComponentModel.Int64Converter();
2574+
var result = converter.ConvertFromInvariantString(s);
2575+
if (result == null)
2576+
return null;
2577+
2578+
return (long) result;
2579+
}
2580+
25632581
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase")]
25642582
internal virtual ProjectOptions GetProjectOptions(ConfigCanonicalName configCanonicalName)
25652583
{
@@ -2638,28 +2656,16 @@ internal virtual ProjectOptions GetProjectOptions(ConfigCanonicalName configCano
26382656
options.AllowUnsafeCode = true;
26392657
}
26402658

2641-
if (GetProjectProperty("BaseAddress", false) != null)
2659+
string baseAddressPropertyString = GetProjectProperty("BaseAddress", false);
2660+
try
26422661
{
2643-
try
2644-
{
2645-
options.BaseAddress = Int64.Parse(GetProjectProperty("BaseAddress", false), CultureInfo.InvariantCulture);
2646-
}
2647-
catch (ArgumentNullException e)
2648-
{
2649-
Trace.WriteLine("Exception : " + e.Message);
2650-
}
2651-
catch (ArgumentException e)
2652-
{
2653-
Trace.WriteLine("Exception : " + e.Message);
2654-
}
2655-
catch (FormatException e)
2656-
{
2657-
Trace.WriteLine("Exception : " + e.Message);
2658-
}
2659-
catch (OverflowException e)
2660-
{
2661-
Trace.WriteLine("Exception : " + e.Message);
2662-
}
2662+
var result = ParsePropertyValueToInt64(baseAddressPropertyString);
2663+
if (result.HasValue)
2664+
options.BaseAddress = result.Value;
2665+
}
2666+
catch (Exception e)
2667+
{
2668+
Trace.WriteLine(string.Format("Exception parsing property {0}='{1}': {2}", "BaseAddress", baseAddressPropertyString, e.Message));
26632669
}
26642670

26652671
if (GetBoolAttr("CheckForOverflowUnderflow"))

0 commit comments

Comments
 (0)