I want to put some metadata in all resx files in a solution. Is seems like this could be accomplished using the metadata
element included in the embedded XSD for resx files:
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
I'm not 100% sure that the metadata
element should be used to store arbitrary metadata because I was unable to find any documentation about its intended purpose. But it works just fine as long the resx files are edited using a text editor.
The problem arises when editing the resx file in Visual Studio 2013. The default way to open the resource is the "Managed Resources Editor". Unfortunately, the Managed Resource Editor does not make a distinction between data and metadata. This causes the metadata to be silently changed to data on save. This bug (or perhaps intentional design) has existed since at least 2010.
We have also tried to add elements Managed Resources Editor wouldn't recognize, but these elements were removed on save. The same thing happened for XML comments. This behavior is more understandable, but doesn't leave us with a lot of good options.
Here are the possible solutions I'm aware of:
data
tag. This is an obvious hack.It seems like the failure here isn't with resx files themselves, it is with the Visual Studio tools around resx files. However, we are not moving away from Visual Studio any time soon. Are there any solutions I'm missing?
I was unable to find a good solution for adding metadata to files. I ended up going with my proposed solution #6: Store the metadata in data
tag.
More specifically, we essentially created a reserved key name by mandating that no resource files were allowed to use the key ResxFileMetadata
. Then in resx files which required metadata we added a resource with the name ResxFileMetadata
and no value. The actual metadata was stored as JSON inside the comment.
We further mandated that the code was never allowed to specifically read the ResxFileMetadata
resources. Functions which created dictionaries from resx files explicitly skippedResxFileMetadata
. These mandates are basically just internal documentation, they are not enforced by code.