Xamarin Android - How to rebuild Resource.designer.cs

Xamarinxamarin.androidXamarin Studio

Xamarin Problem Overview


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?

Xamarin Solutions


Solution 1 - Xamarin

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.

Solution 2 - Xamarin

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.

Solution 3 - Xamarin

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.

Solution 4 - Xamarin

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

Solution 5 - Xamarin

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

Solution 6 - Xamarin

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

Solution 7 - Xamarin

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.

Solution 8 - Xamarin

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.

Solution 9 - Xamarin

Make sure that your root package name is correct.

Solution 10 - Xamarin

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.

Solution 11 - Xamarin

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.

Solution 12 - Xamarin

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

Solution 13 - Xamarin

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!

Solution 14 - Xamarin

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.

Solution 15 - Xamarin

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.

Solution 16 - Xamarin

in my case problem was solved by switching Access Modifier in Resource page from 'No code generation' to 'Public'

Solution 17 - Xamarin

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKarthik MurugesanView Question on Stackoverflow
Solution 1 - XamarinBrendan ZagaeskiView Answer on Stackoverflow
Solution 2 - XamarinAli YousefiView Answer on Stackoverflow
Solution 3 - XamarinAlexCView Answer on Stackoverflow
Solution 4 - XamarinchlaraView Answer on Stackoverflow
Solution 5 - XamarinJean-Daniel GasserView Answer on Stackoverflow
Solution 6 - XamarinROHIT MANDALAPUView Answer on Stackoverflow
Solution 7 - XamarinDevOragzView Answer on Stackoverflow
Solution 8 - XamarinYKaView Answer on Stackoverflow
Solution 9 - XamarinComeInView Answer on Stackoverflow
Solution 10 - XamarinMiiiteView Answer on Stackoverflow
Solution 11 - XamarinThe KirkView Answer on Stackoverflow
Solution 12 - XamarinMarco CastanheiraView Answer on Stackoverflow
Solution 13 - XamarinsgulerView Answer on Stackoverflow
Solution 14 - XamarinOsman GuerreroView Answer on Stackoverflow
Solution 15 - XamarinMushtaque NizamaniView Answer on Stackoverflow
Solution 16 - Xamarinuser2199593View Answer on Stackoverflow
Solution 17 - XamarinKrumelurView Answer on Stackoverflow