58

In Xamarin Android - How to regenerate the Resource.designer.cs

I tried to mark all the XML file's Build Action as "AndroidResource" and still the Resource.designer.cs won't get updated with new values.

What event trigger generating this file?

AlexC
  • 10,146
  • 4
  • 34
  • 54
Karthik Murugesan
  • 1,000
  • 3
  • 12
  • 23
  • 1
    rebuild didn't help and that's why I'm posting here :( not sure if it's a known bug – Karthik Murugesan Aug 22 '13 at 23:39
  • Unfortunately, you're going to just have to try every workaround in the answers here. It's a bug (well, it's probably a series of bugs over the years), and it's often not straightforward to fix. – James Moore Oct 06 '16 at 18:59

16 Answers16

80

As recently as Xamarin Studio 5.6 (build 273) with Xamarin.Android 4.18.0, if you have manually deleted the Resource.designer.cs file from the project, rebuilding will regenerate Resource.designer.cs, but will not add it back into the project. So after attempting to rebuild once, the file will be present in the file system, but not in the project. To fix this, manually add the newly generated file into the Resources folder in the project.

Brendan Zagaeski
  • 2,792
  • 3
  • 18
  • 33
  • 2
    This does work - just make sure your project builds successfully - it will not regenerate if there are build errors (even if the errors are related to resources that will be picked up when the Resource.designer.cs file is regenerated) – Aaron Jan 07 '14 at 20:11
  • +1 Xamarin Studio 5.5.2 / Xamarin.Android 4.18.0 still broken – Richard Le Mesurier Oct 30 '14 at 11:24
  • 1
    I get the file back, but the size of the file is 0Kb, that means there is nothing visual studio doing besides generating the files. this file should be containing all the information of my layouts – Jamshaid K. Apr 10 '17 at 21:27
  • On a hunch I ignored it. After a while it was fine. I worked on another layout and went on developing. In 5 minutes the red squiggly lines were gone. – pdschuller Aug 28 '19 at 15:02
23

1.Click Resource.designer.cs file from your project.

2.Click CTRL+A (Select All)

3.Click Del (Delete all)

4.Clean and Rebuild your project(if you get message for modified Resource.designer.cs click "Yes to All" button).

you are now get error for first buildings. but your Resource.designer.cs file is regenerated.you can now second build. its works.

Ali Yousefi
  • 2,099
  • 2
  • 26
  • 40
18

I have found that Xamarin studio will stop regenerating the Resources file due to changes in the project file. The top build PropertyGroup should contain entries for

<RootNamespace>**Your_Root_Namespace**</RootNamespace>
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>True</AndroidUseLatestPlatformSdk>
<AndroidApplication>True</AndroidApplication>
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
<AndroidResgenClass>Resource</AndroidResgenClass>
<TargetFrameworkVersion>*your value here*</TargetFrameworkVersion>

and for some reason these just disappear. If you open the csproj of the Android project with a text editor and add these entries it seems to work. I grabbed these entries from a fresh new project I created in Xamarin Studio that was working, which is possibly the easiest way to do this.

AlexC
  • 10,146
  • 4
  • 34
  • 54
6

I solved this problem removing the character "-" from the name of images in Drawable folder.

chlara
  • 103
  • 2
  • 9
3

method1: Delete the file from the project and also delete bin and obj files and then build the project it should work 100% as i use to do that if i face the same problem if that doesn't work always there is another option

method2: close the application i.e, visual studio, map to c-> users-> -> AppData (Hidden File) -> delete xamarin file from local and roaming

ROHIT MANDALAPU
  • 428
  • 4
  • 16
  • Please Rohit can you explain what is this xamarin file for? – Elisabeth Dec 15 '17 at 18:31
  • Xamarin file mentioned above is a temp file created while running xamarin project. Some times this restric some functions. You can delete thus any time which will create when required by project. Sorry for the delayed reply I was quite busy with personal life and was away from work for a quite time. – ROHIT MANDALAPU Dec 26 '17 at 07:24
3

It would seem that this can happen for a number of reasons. One step that can help reveal the problem is to increase your build output verbosity in Visual studio: Tools -> Options -> Build and Run -> change the "MSBuild project build output verbosity" to "Diagnostic".

In my case, one of my controls did not have an Id so it led to the Resource.Designer.cs not updating (but failing to do so silently). enter image description here

The file started updating again once I added an Id.

NOTE: You will probably want to change the build output verbosity back to normal after you find your issue.

DevOragz
  • 131
  • 1
  • 6
  • This helped me! Diagnostic was too detailed for me but setting the verbosity to normal helped me find the resource that was causing the issue. – Ayana Sep 14 '17 at 16:34
1

The Resource.designer.cs folder would update as @Brendan Zagaeski mentioned.

However, since it seems like that didn't solve your problem it looks like Xamarin didn't recognize any of the changes you made. At least this is what happened to me.

I ended up solving it by renaming the generated "Layout" folder to "layout" ( I did the same for drawable and values). After that, just by building the project again the Resource.Designer updated successfully.

Hope this helps someone.

YKa
  • 3,618
  • 4
  • 18
  • 31
1

Make sure that your root package name is correct.

ComeIn
  • 1,313
  • 14
  • 11
1

It happened to me a few times, and every time the problem was not coming from the generation of the file itself, but from a malformed android resource. So if that happens after you merged something from your repository, double check your android resources (colors, strings, etc), for any malformed XML code.

Miiite
  • 1,418
  • 10
  • 14
1

In Visual Studio 2019, if you deleted Resources.Designer.cs, just right click "Resources.resx" file in solution explorer and choose "Run custom tool"

This will recreate the file.

"ResXFileCodeGenerator" must be set in Resources.resx file properties (but is set by default) enter image description here

0

It's easier than it seems...

http://docs.xamarin.com/recipes/android/general/projects/specify_default_namespace/

You can rename your project by using find/replace, but the resources file will use whatever is set for 'default namespace' in the Main Settings and will continue to revert to this name even if you manually edit the Resource.designer.cs file in or out of Xamarin.

The Kirk
  • 17
  • 1
0

For the rebuild project solution to work you have to edit the file that generates it and then rebuild the project.

0

I had the exact same issue and none of the answers here worked. Finally I figured that I had some image references in some layouts that did not exist yet. It seems if you have a broken source path, Resource.Designer.cs stops updating without any error. Finally after removing the reference images, the issue was resolved and the Resource.Designer.cs got updated.

Hope this helps someone!

sguler
  • 246
  • 1
  • 7
0

For people that are still having this issue, when you look at the error list some error might say something like "no resource found that matches the given 'toRightOf @id/(name of the resource)' (or any other position in relative layout)... you must highlight all the code of the resource (in the axml file) that has the id, cut, save all, then paste it and rebuilt... then your Resource.Designer.cs will regenerate! hope it helps.

1408786user
  • 1,564
  • 17
  • 35
0

I faced the same issue in Visual Studio. The resource designer file is only generated when there is a change in the resource I applied following steps to generate the required resource.designer.cs file * Added a dummy image in the resources * Cleaned the project * Rebuild the project New resource.designer.cs generated.

-4

The generated Resources.designer.cs class will be updated if you rebuild your project. You can find this information at: http://docs.xamarin.com/guides/android/getting_started/hello%2C_world

Krumelur
  • 29,920
  • 21
  • 114
  • 240
  • rebuild didn't help and that's why I'm posting here :( not sure if it's a known bug. Do you know if there a way to force it manually? – Karthik Murugesan Oct 22 '13 at 03:56
  • @KarthikMurugesan No, sorry. Any chance you can provide your solution or a test project that shows the issue so it can be analyzed? – Krumelur Oct 22 '13 at 06:35
  • It's true that it's _supposed_ to be regenerated. This feature often stops working. – James Moore Oct 06 '16 at 18:53