Generating *.Designer.cs from .resx

Hi,
I’m using C# on a project and I have resx files that generate some Designer.cs files, however since they are generated I would like to not push them on Git.
However the Build phase of GitHub action doesn’t generate them, but the Test phase do
I’m building with

dotnet build --configuration Release --no-restore

And testing with

dotnet test --no-restore --verbosity normal --collect:"XPlat Code Coverage" --settings coverlet.runsettings

I noticed that resgen.exe is used to generate them but I wasn’t able to call it.

So my question is, would someone know how I can generate Designer files from resx in GitHub Actions?

@xwilarg,

I’m afraid you can’t generate a .Designer.cs from a .resx in your WinForm application.
To understand this point, you need to understand what is resource file and what is designer file at first:

  1. The .resx is one of the resource file types. The resource file types include text-based resource file (.txt and .restext), XML-based resource file (.resx).
    A resource is any nonexecutable data that is logically deployed with an app. Resources can contain data in a number of forms, including strings, images, and persisted objects. Storing your data in a resource file enables you to change the data without recompiling your entire app. It also enables you to store data in a single location, and eliminates the need to rely on hard-coded data that is stored in multiple locations. More deatils, see “Resources in .NET apps”.

  2. The designer file (.Designer.cs) is a code file automatically generated by your designer to hold the form’s layout information that was created using the Visual Studio IDE. Once you add a new form in your application, VS will automatically generate the designer file for this form.

According to the above introductions, logically, there is no relationship between the resource file and the designer file. The designer file (.Designer.cs) is required for the WinForm application, you can’t ignore it in your project.

I noticed that resgen.exe is used to generate them but I wasn’t able to call it.

The Resource File Generator (Resgen.exe) is used to convert the resource files to common language runtime binary (.resources) files that can be embedded in a runtime binary executable or satellite assembly.
This tool is automatically installed with Visual Studio. To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7).
It can’t be used to generate the designer files from a the resource files. More details, see “Resgen.exe (Resource File Generator)”.

1 Like

Thanks for your answer,
My application is a console application and not a WinForm one (but I’m not sure if that really matters)
I’m using it because it’s easier and faster for me than creating a dictionary or a JSON file.
Visual Studio already generate the Designer file from the resx file thanks to this code in the csproj

  <ItemGroup>
    <Compile Update="LanguageResources\Hiragana.Designer.cs">
      <DesignTime>True</DesignTime>
      <AutoGen>True</AutoGen>
      <DependentUpon>Hiragana.resx</DependentUpon>
    </Compile>
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Update="LanguageResources\Hiragana.resx">
      <Generator>ResXFileCodeGenerator</Generator>
      <LastGenOutput>Hiragana.Designer.cs</LastGenOutput>
    </EmbeddedResource>
  </ItemGroup>

As you said, it’s generated by VS and I would have like to force the generation by GitHub CI
But maybe I’m not doing things the right way?

@xwilarg,

If you can use the .resx file to generate the .Designer.cs file on your local environment, maybe you can try to list the completed steps you have used, and check the command lines you were using to execute these steps. Then you can try to run these command lines in your workflow to see if it can work.

The issue is that I’m not using any command, they are automatically generated.

@xwilarg,

Of course, as mentioned above, it is generally the .Designer.cs file is automatically generated by VS, it is not generated from the .resx file. You may have some misunderstandings about the .resx file.

Yeah I’m indeed a bit confused by that, since the .Designer.cs contains what is inside the .resx and a way to access it in C#, why isn’t it “generated from it”?

@xwilarg,

Sometimes, the .Designer.cs may reference some strings defined in the resource file to set the contents displayed on the application UI. But this does not mean the .Designer.cs is generated from the resource file.
Other files in the project may also reference the data defined in the resource file, that also does not mean these files are generated from the resource file.

In the .csproj file, normally it will list all the required source files of the application.

  • The .Designer.cs defines the UI of the application, it is required. Maybe, sometimes the .Designer.cs defines an empty or blank UI when the application does not need a UI.

  • The .resx file defines some data may be referenced by other source files in the same project.

Essentially, there is no relationship between the .Designer.cs and the .resx.
The .Designer.cs can reference the data defined in the .resx, or no need to reference .resx. you can directly define all the needed UI strings in the .Designer.cs.

1 Like