最近使用.NET发布独立的Linux x64程序,在CentOS7.9的最小化安装系统上运行,结果运行不了,启动就报异常“Process terminated. Couldn't find a valid ICU package installed on the system. Please install libicu (or icu-libs) using your package manager and try again. Alternatively you can set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support. Please see https://aka.ms/dotnet-missing-libicu for more information.”
在网上搜索了一下,这个是.NET 5.0及以上版本进行国际化的一个问题,需要libicu的支持,网上找到2个解决方案,确实都能解决问题,但都有一点点缺陷。
第1个解决办法是修改项目的csproj文件,将System.Globalization.Invariant设为true,也就是放弃对国际化的支持,这样就不会受到这个异常的影响了。我一开始使用的这个解决办法,但是后来遇到了一个问题,就是我用程序去连某个SQL SERVER的时候,报异常了,说必须启用对国际化的支持才能读取,我不想发布多个版本,遂放弃。
第2个解决