Search code examples
.netvisual-studioresourcesvisual-studio-designer

Renaming resources in Visual Studio does not update their references


I have added some image files as resources to my project through the Resources.resx. But if I change the name of the image file after adding it, both in Resources.resx and in the "Resources" folder on the Solution Explorer window, Visual Studio does not update their references and instead flairs errors that the "old" resource is missing. I find it very odd and wonder if that is normal?


Solution

  • To rename the resource property name, it's enough to open your .resx file in designer and then simply rename the entry. This way, visual studio renames the property everywhere it has been used.

    To rename the file name, you have 2 options:

    • After renaming it to new desired name, delete entry from .resx file and add/paste a file with the same new name to the .resx file.
    • As another option, you can open .resx file using in code view (using f7 or view code) and then find the entry and use new file name, then save file and close it. The entry is somwthing like this:

      <data name="SomeName" type="System.Resources.ResXFileRef, System.Windows.Forms">
        <value>..\Resources\SomeName.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
      </data>
      

      as you can see, the file name is SomeName.png in Resources folder which can be replaced by a new file name.