简体   繁体   English

.Net 5 日本文化月缩写

[英].Net 5 Japanese culture month abbreviation

I'm using .Net 5.0.403 to format a Japanese date, and I'm getting a different value on two hosts.我正在使用 .Net 5.0.403 来格式化日语日期,并且我在两台主机上得到了不同的值。 I'm running the following code:我正在运行以下代码:

using System;
using System.Globalization;

var locale = new CultureInfo("ja-JP");
CultureInfo.CurrentCulture = locale;
var formatted = DateTime.Now.ToString("dd MMM yyyy H:mm");
Console.WriteLine(formatted);

Console.WriteLine("Month abbreviations:");
foreach (var month in locale.DateTimeFormat.AbbreviatedMonthNames)
    Console.WriteLine("* {0}", month);

Which locally gives the output:其中本地给出了输出:

09 11月 2021 16:21
Month abbreviations:
* 1月
* 2月
* 3月
* 4月
* 5月
* 6月
* 7月
* 8月
* 9月
* 10月
* 11月
* 12月
*

However, when running on a build server with Windows 2019, I get the following output:但是,在使用 Windows 2019 的构建服务器上运行时,我得到以下输出:

09 11 2021 16:22
Month abbreviations:
* 1
* 2
* 3
* 4
* 5
* 6
* 7
* 8
* 9
* 10
* 11
* 12
* 

It seems that the MMM format string corresponds to a different value on the build server.似乎MMM格式字符串对应于构建服务器上的不同值。 Are there any configuration options that can be set on a host to control this?是否可以在主机上设置任何配置选项来控制它?

This was caused by the inclusion of ICU lib in .net 5. It relied on the version available on the host machine, and this could vary between environments.这是由 .net 5 中包含 ICU 库引起的。它依赖于主机上可用的版本,这可能因环境而异。 This is detailed in this bug https://github.com/dotnet/runtime/issues/60845 .此错误https://github.com/dotnet/runtime/issues/60845中对此进行了详细说明。 The solution was to embed a fixed version of ICU libs for use in all environments by adding the following to the csproj file of the assembly that is executing:解决方案是通过将以下内容添加到正在执行的程序集的 csproj 文件中,嵌入一个固定版本的 ICU 库以在所有环境中使用:

  <ItemGroup>
        <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2.0.6" />
        <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.6" />
  </ItemGroup>

This is referred to app-local ICU, and is further documented here: https://docs.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#app-local-icu这被称为应用本地 ICU,并在此处进一步记录: https : //docs.microsoft.com/en-us/dotnet/core/extensions/globalization-icu#app-local-icu

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM