Search code examples
c#.netinternationalizationvisual-studio-2019

How to stop Visual Studio from creating language specific resources dll from resource file names?


After renaming embedded resource files from insignificant names (WelcomeA.rtf and WelcomeB.rtf) to contain language codes (Welcome.en-us.rtf and Welcome.de-de.rtf), the .NET build started splitting my resources off into [AppName].resources.dll files that are located in a language-coded subfolder of the output directory. The de-de and en-us folders have not been present before and all I did was rename source files, not changing project settings:

D:\[AppName]\BIN\DEBUG\NET5.0-WINDOWS
│   [AppName].deps.json
│   [AppName].dll
│   [AppName].exe
│   [AppName].pdb
│   [AppName].runtimeconfig.dev.json
│   [AppName].runtimeconfig.json
│
├───de-de
│       [AppName].resources.dll
│
├───en-us
│       [AppName].resources.dll
│
└───ref
        [AppName].dll

My Application does not support whatever I18N pattern Visual Studio is trying to implement here.
I was locating and loading the embedded document into a RichTextBox by doing something like this, which is now broken:

private void LoadWelcomeText(string langCode)
{
    Assembly assembly = Assembly.GetExecutingAssembly();
    richTextBox.Document.Blocks.Clear();

    foreach (string s in assembly.GetManifestResourceNames())
    {
        if (s.Contains("Welcome." + langCode + ".rtf"))
        {
            Stream stream = assembly.GetManifestResourceStream(s);
            richTextBox.Selection.Load(stream, DataFormats.Rtf);
            break;
        }
    }
}

How can I force the build process to not restructure my application architecture from source file names?
(I am aware that renaming the files to not match whatever pattern is used to guess the I18N intent here, but I'd like to fix the problem, not work around it.)


Solution

  • Set resource WithCulture in csproj file.

    <EmbeddedResource Include="Resources\Welcome.en-us.rtf" WithCulture="false" />