Motivated by some old, less old, and recent forum threads about allowing compositional workflows in a rehosted designer scenario, with the ability to reuse activities created in XAML, I have finally played through some options for building assemblies directly from rehosted designer XAML.
First though, let’s look at the standard option for compiling workflow assemblies.
What normally happens when you build XAML files in an Activity Library project in VS? Your XAML file is compiled, and a new Activity type is created in the output assembly.
XamlBuildTask is the name of the key msbuild task involved in generating classes and assemblies from workflow XAML. In the process of compiling simplest possible Activity Library project, a single XAML file results in the generation of many intermediate files.
We can see them in Solution Explorer if we turn on ‘show hidden items’.
The hidden files are something I don’t normally look at, but if you have ever had something weird happen during workflow construction, you may have found yourself walking the stack and browsing through the InitializeComponent method in Activity1.g.cs. And thereby discovering at least that one file.
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
if ((this._contentLoaded == true)) {
return;
}
this._contentLoaded = true;
string resourceName = this.FindResource();
System.IO.Stream initializeXaml = typeof(Activity1).Assembly.GetManifestResourceStream(resourceName);
System.Xml.XmlReader xmlReader = null;
System.Xaml.XamlReader reader = null;
System.Xaml.XamlObjectWriter objectWriter = null;
try {
System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
xmlReader = System.Xml.XmlReader.Create(initializeXaml);
System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();
readerSettings.AllowProtectedMembersOnRoot = true;
Read more: The Activity Designer
First though, let’s look at the standard option for compiling workflow assemblies.
What normally happens when you build XAML files in an Activity Library project in VS? Your XAML file is compiled, and a new Activity type is created in the output assembly.
XamlBuildTask is the name of the key msbuild task involved in generating classes and assemblies from workflow XAML. In the process of compiling simplest possible Activity Library project, a single XAML file results in the generation of many intermediate files.
We can see them in Solution Explorer if we turn on ‘show hidden items’.
The hidden files are something I don’t normally look at, but if you have ever had something weird happen during workflow construction, you may have found yourself walking the stack and browsing through the InitializeComponent method in Activity1.g.cs. And thereby discovering at least that one file.
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
public void InitializeComponent() {
if ((this._contentLoaded == true)) {
return;
}
this._contentLoaded = true;
string resourceName = this.FindResource();
System.IO.Stream initializeXaml = typeof(Activity1).Assembly.GetManifestResourceStream(resourceName);
System.Xml.XmlReader xmlReader = null;
System.Xaml.XamlReader reader = null;
System.Xaml.XamlObjectWriter objectWriter = null;
try {
System.Xaml.XamlSchemaContext schemaContext = XamlStaticHelperNamespace._XamlStaticHelper.SchemaContext;
xmlReader = System.Xml.XmlReader.Create(initializeXaml);
System.Xaml.XamlXmlReaderSettings readerSettings = new System.Xaml.XamlXmlReaderSettings();
readerSettings.LocalAssembly = System.Reflection.Assembly.GetExecutingAssembly();
readerSettings.AllowProtectedMembersOnRoot = true;
Read more: The Activity Designer