Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET 8 ResourceFile not working when using period in folder name

Tags:

c#

.net-8.0

I want to use a ResourceFile within a folder with a period in the foldername ("R4.3") This was working in .NET Framework 4.8 But now we upgraded to .NET 8, and now it's not working anymore. I tried adding a folder with a underscore (R4_3) and that does work. But I'm hoping for another solution, because otherwise I have to rename a lot of folders.

For an example see: See https://github.com/janssenr/ResourceFile

like image 482
Rob Janssen Avatar asked Dec 12 '25 00:12

Rob Janssen


1 Answers

It's not the period/dot that is causing the issue, but the numeric only segment.

That is because the folders will be part of the namespace of the class generated in the .designer.cs file, and a namespace cannot have a numeric only segment.

ConsoleApp1.SF.R4.3.OUT.Internal is not a valid namespace.

Even the .resources file built in the obj\Debug\net8.0 folder has that numeric segment replaced in it's name. Notice that .3. became ._3..

enter image description here


In case renaming those folders is not an option, then you can set the CustomToolNamespace of the affected .resx file(s) to a valid namespace; e.g. that ConsoleApp1.SF.R4._3.OUT.Internal or any other valid one.

enter image description here

This gives below in your .csproj file. Notice the <CustomToolNamespace>ConsoleApp1.SF.R4._3.OUT.Internal</CustomToolNamespace>.

<ItemGroup>
  <Compile Update="SF\R4.3\OUT\Internal\ResourceFile.Designer.cs">
    <DesignTime>True</DesignTime>
    <AutoGen>True</AutoGen>
    <DependentUpon>ResourceFile.resx</DependentUpon>
  </Compile>
  <Compile Update="SF\R4_3\OUT\Internal\ResourceFile.Designer.cs">
    <DesignTime>True</DesignTime>
    <AutoGen>True</AutoGen>
    <DependentUpon>ResourceFile.resx</DependentUpon>
  </Compile>
</ItemGroup>

<ItemGroup>
  <Resource Include="SF\R4.3\OUT\Internal\ResourceFile.resx">
   <Generator>ResXFileCodeGenerator</Generator>
    <CustomToolNamespace>ConsoleApp1.SF.R4._3.OUT.Internal</CustomToolNamespace>
    <LastGenOutput>ResourceFile.Designer.cs</LastGenOutput>
  </Resource>
</ItemGroup>

<ItemGroup>
  <EmbeddedResource Update="SF\R4_3\OUT\Internal\ResourceFile.resx">
    <Generator>ResXFileCodeGenerator</Generator>
    <LastGenOutput>ResourceFile.Designer.cs</LastGenOutput>
  </EmbeddedResource>
</ItemGroup>

Instead of having to rename a lot of folders, you end up with a namespace change/refactoring, which might be easier to accomplish.

That code fragment from within your mentioned GitHub repo then becomes

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string xslt = SF.R4._3.OUT.Internal.ResourceFile.Product;
        }
    }
}

Result in Visual Studio

enter image description here

like image 64
pfx Avatar answered Dec 13 '25 14:12

pfx