Important
This library is no longer needed for .NET 8 and higher.
Please remove it from your projects when you migrate.
MSBuild task to expose resources to F# Xamarin.Android / .NET Android projects up until .NET 7.
Starting .NET 8, F# Android projects work out of the box without the need for this library.
Microsoft improved access to assets in your Android apps. They generate an assembly named _Microsoft.Android.Resource.Designer
which contains all your Android assets, instead of silently injecting C# code into your F# projects.
- Replace the old type provider with the new package for your Android project
- <PackageReference Include="Xamarin.Android.FSharp.ResourceProvider" />
+ <PackageReference Include="FSharp.Android.Resource" />
- Remove the following properties from your Android project fsproj file. They are managed by FSharp.Android.Resource
<PropertyGroup>
- <AndroidResgenFile>Resources/Resource.designer.cs</AndroidResgenFile>
- <AndroidUseIntermediateDesignerFile>false</AndroidUseIntermediateDesignerFile>
</PropertyGroup>
- Run the build one time; it will fail but it's ok. This generates the resource assembly.
- Reload your project to be able to see the new resource assembly
- Add
do Resource.UpdateIdValues()
to your MainActivity (or whichever activity is the first one to display)
type MainActivity() =
inherit Activity()
// This is required for the app to pick up the right resources
do Resource.UpdateIdValues()
member _.OnCreate(bundle) =
base.OnCreate(bundle)
// Now you can use Resource like usual
this.SetContentView(Resource.Layout.Main)
- Build one more time. This time it should complete successfully.
- Everything should be working, enjoy!
Given the first build will always fail, you can use the following steps to workaround it:
- Execute a build using the target
CompileResourceDesignerForFSharp
- Execute a normal build
msbuild -t:CompileResourceDesignerForFSharp
msbuild -t:Build