migrate from .net3.1 to net6.0 results in 4 letter DateTime abbreviation instead of 3

Viewed 14

After migrating from .netcore3.1 to .net6.0 a simple console app now prints out some months with a 4 letter abberviation:

        Console.WriteLine(DateTime.Parse("1-Jul-2022").ToString("MMM"));
        //outputs July, used to be Jul
        Console.WriteLine(DateTime.Parse("1-Sep-2022").ToString("MMM"));
        //outputs Sept, used to be Sep

How to make it revert to the netcore3.1 behaviour? Please note I would like a global solution not one that 'fixes' an invidiual instance of DateTime.ToString( )

My DateTimeFormatInfo.CurrentInfo has Culture en-AU - nothing else has changed on my OS

1 Answers

After following the steps from the link provided by @Hans here are the steps

  1. create a file runtimeconfig.template.json at the root of your project
  2. insert
{
  "configProperties": {
    "System.Globalization.UseNls": true
  }
}
  1. Rebuild project - ensure you see the config changes in the output directory file ConsoleApp.runtimeconfig.json

  2. Check ICUMode is false

public static bool ICUMode()
{
    SortVersion sortVersion = CultureInfo.InvariantCulture.CompareInfo.Version;
    byte[] bytes = sortVersion.SortId.ToByteArray();
    int version = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
    return version != 0 && version == sortVersion.FullVersion;
}
Related