Search code examples
avaloniauiavalonia

Can Avalonia resource folder be in a common location outside of the project folder?


In my C# project file I have:

  <ItemGroup>
        <AvaloniaResource Include="Assets\**"/>
  </ItemGroup>

I can then successfully access image files at runtime as follows:

... AssetLoader.Open(new Uri("avares://" + assemblyName + "/Assets/Icons/" + imageFileName)) ...

However, I'd like to share an Assets folder among many applications - this folder would be independent of the project folder. How would I do this?


Solution

  • You are on the right track, but instead of just using a common folder, create a new project assembly to contain your assets that can be consumed by your applications as a common project reference, or if you want to be creative you can even make yourself a local NuGet package.

    Once that is done, add a reference to the assembly/package and use the avares to point at it's assembly name.

    <Image Source="avares://MyAssetAssembly/Assets/MyImageAsset.png"/>