0

I noticed a peculiar problem when I try to include a file as an EmbeddedResource in my project.

If the file contains a culture name substring (e.g. test.en.json), the C# compiler will completely ignore the EmbeddedResource directive from my project file and instead generate an external localization file (a satelite assembly, I believe), named MyProject.Resources.dll and output it in a subfolder called en.

This is most definitely not what I want! How can I persuade the compiler to just do the usual thing it would normally do, if the file name was different (e.g. test.json)?

Simply renaming my resource files to avoid such coincidences is not something I'd be happy with, because it has other side effects.

UPDATE

Maybe I wasn't clear enough... The reason I don't want any of this magic is because I'm going for a single executable application. Additional DLLs in a subfolder, even if automagically loaded, defeat my intended purpose. I just want the normal (i.e. no localization-related helpfulness) embedded resource behavior.

aoven
  • 2,248
  • 2
  • 25
  • 36
  • Please, share [mcve] – Pavel Anikhouski Oct 23 '20 at 12:11
  • I misunderstood the problem at first, [here](https://stackoverflow.com/q/27272085/1997232) is someone having similar issue. – Sinatr Oct 23 '20 at 12:19
  • @Sinatr: Thx. But let me just say, wow! It looks incredibly involved for such a simple little unwanted thing. I'll have to study that answer a bit, first. – aoven Oct 23 '20 at 12:24
  • Looks like a duplicate of item [How can I prevent embedded resource file culture being set based on its filename](https://stackoverflow.com/questions/39477616/how-can-i-prevent-embedded-resource-file-culture-being-set-based-on-its-filename) – TJ Galama May 23 '22 at 14:14

1 Answers1

2

This problem kept me busy for a few hours. I solved it with the attribute WithCulture. In the C# project file (.csproj) this looks something like below:

<Project Sdk="Microsoft.NET.Sdk">
   ...
   <ItemGroup>
      ...
      <EmbeddedResource Include="test.en.json" WithCulture="false" />
      ...
      <EmbeddedResource Include="Resources\**" WithCulture="false" />         
   <ItemGroup>
</Project>
TJ Galama
  • 457
  • 3
  • 12
  • 1
    Looks promising! I'll test it in the near future and accept this answer if it works! How did you manage to find this? – aoven May 21 '22 at 16:39