【问题标题】:How to fix Obj Folder Assembly Error: "Executables cannot be satellite assemblies; culture should always be empty"如何修复 Obj 文件夹程序集错误:“可执行文件不能是附属程序集;区域性应始终为空”
【发布时间】:2019-12-11 13:41:53
【问题描述】:

这是我在代码中添加的导致我遇到此错误的内容:

我正在使用 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 文件夹出现错误,“可执行文件不能是附属程序集;区域性应始终为空”

对象

调试

netcoreapp2.2

zh-CN

xxx.resources.cs

xxx.resources.dll

[assembly: System.Reflection.AssemblyCultureAttribute("en-US")]

该项目将运行,但此行会给您一个错误并且不会被识别。

我想做的是在每次构建项目时完全消除这个错误。

我也认为这可能是一个智能感知错误。

【问题讨论】:

    标签: asp.net-core localization .net-assembly cultureinfo


    【解决方案1】:

    我有同样的问题。通过禁用obj/* 文件夹中的文件解析,通过在omnisharp.json 文件中添加排除模式来解决。

      "fileOptions": {
        "systemExcludeSearchPatterns": [
          "**/bin/**/*",
          "**/obj/**/*"
        ]
      }
    

    我认为这是正确的方法,因为obj 文件夹不是项目的一部分(就源代码而言),而是某种我认为是黑盒的生成。

    详情请见Omnisharp configuration documentation。

    【讨论】:

    • 这不是一个正确的答案,我认为它有效,但最终它没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多