-
Thank you all so very much for all of your fantastic work on Avalonia! I am a little stuck and I could really use some guidance on how to proceed! If given the source of various .cs & .axaml files I would like to use Roslyn and the Avalonia Xaml Compiler to build the said files into an Assembly at runtime and then run them inside of my app. I have so far developed a primitive (and very hacky at the moment) proof of concept using Roslyn that works with the .cs files. I am able to build Views with C# code directly in my code-behind. I have not yet tried Avalonia.Xaml.Declarative; however, I feel that building views in C# is a bit clunky and violates the MVVM pattern I am going for so I would really like to next be able to support .AXAML files in my build process... Does anyone know where I might find documentation on using the Avalonia XAML compiler with Roslyn? I know that Avalonia uses a Source Generator to generate a partial code-behind with an InitializeComponent() method in it; however, I really do not understand how Avalonia embeds the actual XAML into the assembly. AvaloniaXamlLoader.Load(this) is rather magical to me. I really do not want to have to resort to hard-coding the XAML as a string in my code-behind before compiling :o At the end of the day I'd like the Assemblies I generate to work just like an Assembly built in Visual Studio. So an example (or documentation) on how to use the built in Source Generators rather than the primitive string based hack I am trying to use now and how to use the Avalonia Xaml Compiler would be super helpful! Thank you all so very much and GOD bless! |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
XamlPlayground already implements this. You can check the described feature which can load XAML and optional code-behind.
It doesn't, but declarative UI is clunky syntax (IMO) at a fundamental level. |
Beta Was this translation helpful? Give feedback.
-
@stevemonaco Thank you, sadly I am not finding where XamlPlayground embeds the XAML into the Assembly! Basically, I am working on a Prism Shell and the idea is that I want to be able to build my own Prism Modules within my Shell Application. Think ACCESS! So when I compile my Module to a .DLL it needs to have everything it requires to run embedded inside of it so that it can be loaded by the Prism Module Loader. |
Beta Was this translation helpful? Give feedback.
-
Roslyn allows you to add Resource files to the compilation during Emit(), I am thinking that somehow I need to be able to compile the XAML and then embed it in some kind of Resource object that gets added to the Assembly? |
Beta Was this translation helpful? Give feedback.
-
We don't ship "offline" compiler as a separate library, but you can just use Avalonia's MSBuild task to process the generated assembly. |
Beta Was this translation helpful? Give feedback.
-
@stevemonaco @kekekeks Thank you both very much! I am still learning and I feel that I am rather far away from full MSBuild integration! The application is really more about learning and ultimately showing other people how to do really cool stuff with Avalonia so I am not sure if I will ever get that far; however, thank you for the point in the right direction if/when I proceed! As far a my learning adventures go learning how to bundle resource files into my assemblies actually seems like a far more enlightening next step! Thank you again and GOD Bless! |
Beta Was this translation helpful? Give feedback.
We don't ship "offline" compiler as a separate library, but you can just use Avalonia's MSBuild task to process the generated assembly.