Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding merge conflicts in resx files

Tags:

c#

resx

In our C# MVC project we are storing our localizable strings in .resx files. Every time we add a new string, Visual Studio puts it at the bottom of the file, which means that if two strings are added in different branches then we will get a merge conflict, because two different blocks of code are being added to the same place.

How can we reduce our merge conflicts? Sorting the strings alphabetically might help, but I can't see how to do this. Or maybe we could tell git to treat each <data>...</data> tag as an independent block?

We're currently using git, but had the same problem with TFS/TFVC.

like image 950
thelem Avatar asked Jun 23 '14 16:06

thelem


People also ask

What are RESX files?

resx resource file format consists of XML entries that specify objects and strings inside XML tags. One advantage of a . resx file is that when opened with a text editor (such as Notepad) it can be written to, parsed, and manipulated.

Are RESX files compiled?

resx file is compiled into a . resource file, which in turn is linked into a . resource. dll satellite file, referred to as a satellite DLL or Language Assembly.

How do I sort a RESX file?

Right click a resx file in Solution Explorer, and choose "Sort resx". Select any number of resx files (or any other files), right click and choose "Sort resx".


Video Answer


1 Answers

We have found the ResXManager Visual Studio extension that can sort ResX files on save.

In Visual Studio select Tools > Extensions and Updates. Click Online in the left panel and then search for "ResXManager" in the box in the top right and install it.

ResXManager install dialog

Once installed, choose Tools > ResXManager, go to the Configuration tab at the bottom and enable the "When saving a RESX file, sort the XML data nodes by the key".

There's also a button to "Sort all files now". Sorting the files will create lots of conflicts, so carefully choose a time in your release cycle to minimise these conflicts. All developers will need to have ResXManager installed, but the setting is applied to the solution so they will not need to change it themselves.

ResXManager configuration screen

Update

We've been using this for nearly 3 years now and our problem is solved - we hardly ever get resx merge conflicts any more. Even if a developer without the plugin adds a string at the end of the file, a few days later someone else working on an unrelated ticket will end up saving the same file and it will be sorted alphabetically.

like image 170
thelem Avatar answered Oct 09 '22 09:10

thelem