我正在使用VSCode。
在StartUp.cs-ConfigureServices中
services.AddLocalization (options => options.ResourcesPath = "Resources");
services.AddMvc ().SetCompatibilityVersion (Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1)
.AddViewLocalization (LanguageViewLocationExpanderFormat.Suffix, opts => { opts.ResourcesPath = "Resources"; });
在StartUp.cs中-配置
var localizationOptions = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
};
localizationOptions.RequestCultureProviders.Clear();
localizationOptions.RequestCultureProviders.Add(new QueryStringRequestCultureProvider());
app.UseRequestLocalization(localizationOptions);
我已经在此文件夹中创建了资源文件:
资源
视图
赠款
Index.en-US.resx
Index.hu-HU.resx
并在此视图中称为值:
查看
赠款
Index.cshtml
[构建项目时,我在xxx.Resources.cs文件中新创建的OBJ文件夹中收到错误,“可执行文件不能是附属程序集;区域性应始终为空”
obj
调试
netcoreapp2.2
zh-CN
xxx.resources.cs
xxx.resources.dll
[assembly: System.Reflection.AssemblyCultureAttribute("en-US")]
该项目将运行,但是此行将给您一个错误,并且不会被识别。
我想做的是每次构建项目时都完全消除此错误。
我还认为这可能是一个智能错误。
我有同样的问题。通过禁用obj/*
文件夹中的文件解析,通过在omnisharp.json
文件中添加排除模式来解决。
"fileOptions": {
"systemExcludeSearchPatterns": [
"**/bin/**/*",
"**/obj/**/*"
]
}
我认为这是正确的方法,因为obj
文件夹不是项目的一部分(就源代码而言),而是我认为是黑盒的某种生成方式。
有关详细信息,请参见Omnisharp configuration documentation。