https://github.com/fabulous-dev/fsharp.android.resource
MSBuild task to expose resources to F# .NET Fx / .NET Android projects
https://github.com/fabulous-dev/fsharp.android.resource
android dotnet fsharp maui resources xamarin xamarin-forms
Last synced: 26 days ago
JSON representation
MSBuild task to expose resources to F# .NET Fx / .NET Android projects
- Host: GitHub
- URL: https://github.com/fabulous-dev/fsharp.android.resource
- Owner: fabulous-dev
- License: apache-2.0
- Created: 2022-02-02T11:36:28.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-23T13:13:19.000Z (over 1 year ago)
- Last Synced: 2024-04-26T20:20:17.656Z (about 1 year ago)
- Topics: android, dotnet, fsharp, maui, resources, xamarin, xamarin-forms
- Language: F#
- Homepage:
- Size: 92.8 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
FSharp.Android.Resource
--> [!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.
### Why is it no longer needed for .NET 8 and higher?
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.
### How to use
1. Replace the old type provider with the new package for your Android project
```diff
-
+
```2. Remove the following properties from your Android project fsproj file.
They are managed by FSharp.Android.Resource
```diff
- Resources/Resource.designer.cs
- false```
3. Run the build one time; **it will fail but it's ok**. This generates the resource assembly.
4. Reload your project to be able to see the new resource assembly
5. Add `do Resource.UpdateIdValues()` to your MainActivity (or whichever activity is the first one to display)```fsharp
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)
```6. Build one more time. This time it should complete successfully.
7. Everything should be working, enjoy!### How to use in a Continuous Integration environment
Given the first build will always fail, you can use the following steps to workaround it:
1. Execute a build using the target `CompileResourceDesignerForFSharp`
2. Execute a normal build```sh
msbuild -t:CompileResourceDesignerForFSharp
msbuild -t:Build
```