I would like to embed compiled XAML into an assembly as BAML2006.
If the Embedded Resource MSBuild action is selected, the XAML file gets embedded into the assembly as a text resource that can be read like any other loose XAML resource. However, loose XAML has some serious limitations when it comes to referenced namespaces, most cripplingly, any namespace referred to by its [XmlnsDefinitionAttribute]
must be loaded into the AppDomain
before the loose XAML is parsed. In contrast, embedded BAML does not suffer from this, as the assembly containing the namespace is added to the list of referenced assemblies and is loaded by the AppDomain
automatically before any code starts running.
If the Page MSBuild task is selected, XAML gets "compiled" into BAML2006 and is embedded to the .resources.g
of the containing assembly. However, compilation will fail if the WindowsBase
, PresentationCode
and PresentationFramework
assemblies are not referenced. As I am working on a project which uses XAML but not WPF (we load object graphs with XamlObjectWriter
and custom markup extensions, but reuse the Visual Studio some of XAML editor infrastructure for IntelliSense support), I would like to avoid depending on these libraries.
Is there any way to make MSBuild embed BAML and add required assembly references without depending on WPF?
I guess Workflow Foundation uses a similar approach, but I haven't been able to find any information.