34

I have Resources.resx, which is used to generate Resources.designer.cs. Should Resources.designer.cs be checked in, or can I rely on Visual Studio generating it when required?

Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
  • 10
    [Microsoft says](http://connect.microsoft.com/VisualStudio/feedback/details/285765/resources-designer-cs-doesnt-automatically-get-rebuilt-despite-it-being-an-auto-generated-file) "custom tools are run at design-time and not at build-time, and therefore the dependent file needs to be checked into source control." – Rich C Feb 07 '14 at 04:20

3 Answers3

21

My preference is: If it's modified by the build system, ensure the build process will create it and don't check it in.

For autogenerated files like 'designer', I check them in. They only get modified when other components get changed (by me). It's generated by VS and not modified by the build system.

QuinnG
  • 6,346
  • 2
  • 39
  • 47
8

I ran across your post for a problem I am experiencing, not quite the same, but it helped me find a temporary solution. This is what I found that might help you…

I am creating a simple string resource file. I then use a modified CodeProject program that translates it into foreign languages. (We will use professional services once we stabilize the code) The utility does not create the designer.cs files. Doing a rebuild all did not re-create the files either. It appears that any time you use an external tool (not the Visual Studio designer) to modify an resx file, you will lose those synced changes. In my case the designer file is used merely to strongly type the strings to property names. If you are using the ID’s to pull the string (age old method) then you won’t need these files at all and thus wouldn’t need to check them in to source control. However, if you are using the strongly typed access to these string (more modern method) you should check them in.

As an aside… I did find a way to re-sync those designer.cs files with their resx counter parts as that was my problem… I needed them. Selecting a resx file in the Solution Explorer and setting the CustomTool property to PublicResXFileCodeGenerator instantly created the designer.cs file. Unfortunately, if it is already set, you have to un-set it and then re-set it to create the file. If anyone knows a way to force a re-creation of these via some automated means… I would really appreciate it.

Thanks.

Dennis Cox
  • 89
  • 1
  • 2
  • 9
    Hello Dennis. You can run the ResX Code Generator manually by right-clicking on the resx-File and choosing "Run Custom Tool". – theDmi Jul 04 '12 at 09:28
  • More on invoking **Run Custom Tool** in [this answer](https://stackoverflow.com/a/16428739/1497596). – DavidRR Nov 05 '18 at 15:44
  • @theDmi Is there a way to regenerate `Resource.designer.cs` in the android project? I have deleted it. – Naveed Hematmal Jul 01 '21 at 08:43
4

I'm not 100% sure about the build scenarios around this file. I think that it's likely Studio, or more appropriately msbuild, will re-generate the file every time you build your application but not sure.

Either way, I would still check this file in for a couple of reasons

  1. It's the default for most source control providers in Visual Studio. They've thought a lot harder about this problem than I have and likely have good reasons for doing this
  2. Debugging: It's unlikely there would ever be a issue in the Resource.Designer.cs but if there was you'd be forced to build before you could attach / debug
  3. Source Control should be a history of your sources. What good is it doing if you can't see all of the sources related to your application.

The first reason being the most important

JaredPar
  • 733,204
  • 149
  • 1,241
  • 1,454
  • 1
    On point 1, that may be the case but the Xamarin team themselves in their GitHub projects have it ignored, so I feel like at best that's just one side of the argument. – Trevor Hart Jul 30 '17 at 03:19
  • @TrevorHart I have deleted the `Resource.designer.cs` file, and now the project throws errors, so that means we can't exclude this file from source control. – Naveed Hematmal Jul 01 '21 at 08:39
  • @NaveedHematmal I never specified to delete it, it's a vital file. You only need the file to exist though, from there, xamarin will fill it out, so you can ignore future changes to the file after an initial commit. – Trevor Hart Jul 01 '21 at 15:16