Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change CodeGenerator for resource file in Visual Studio C#

In my VS2015 project I'm using resource files for keeping track of my texts and corresponding translations. The texts are kept in resx files and for the main resx file a corresponding .designer.cs file is created automatically which exposes the texts through properties.

My problem now is that I have to modify the generated code in the .desginer.cs for some additional functionality. Of course this only makes sense when I modify the template that VS uses to generate the code - but how can I do that?

I noticed that I'm allowed to specify a 'Custom Tool' for my main resx file which is currently set to 'PublicResXFileCodeGenerator':

I did some research on the automatic code generation but could not find a basic tutorial for it but only some complicated examples that go back to VS2008. Unfortunately I still do not know where this 'PublicResXFileCodeGenerator' comes from so that I could use it as a base for my own approach to start from. I also do not know if my own template would then be a .rgt file and where I would have to put it (I saw those rgt files in one example but could not find out where they were assigned/used).

Could anyone please recommend me a way to modify the automatic code generation of my .Designer.cs?

Thanks!

like image 970
Ralf Avatar asked Oct 20 '25 14:10

Ralf


1 Answers

After doing a little more reseach I stumpled upon this MSDN article which explains how a "Custom Tool" or "Single-File generator" can be implemented. One part of this is that the generator needs to be registered as a COM component which does not sound very appealing to me (Would I have to register this on every team mate's computer to make it run on their system, too?).

As an alternative I decided to create a simple console application which takes 'SourceFile', 'DestinationFile' and 'NameSpace' as parameters. This small application will then be able to generate the .designer.cs for me.

Adding the tool to TFS and calling it from the 'Pre-Build event command line' of my resource project should be piece of cake.

Checking out the .designer.cs from TFS (or adding it) shoudl not be a big deal (so I was told).

Iterating through the RESX file is convenient when using the System.Resources.ResXResourceReader.

In the end this is not a very nice workaround, but I'd still prefer it over the other solutions that I found so far :-/

like image 108
Ralf Avatar answered Oct 22 '25 02:10

Ralf



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!