Jason Nadal

Restless C#ding

Manually Compile your XAML into BAML

For those of you who are hardcore console compilers, here's how you can manually compile your BAML partial classes, using the Windows Application Compiler:

The file, ac.exe, can be found in the %installdrive%:\WINDOWS\Microsoft.NET\Avalon directory. You can either apecify the project (*.lhproj) file or XAML. If you choose XAML, you can specify whether to compile to “full code” (instead of BAML) using the -code directive, all XAML files in the directory (the -dir ), or perhaps the strangest, “Create a combined source file only  (No IL)”, using the -so directive.

Update - from the comments, Rob Relyea writes that ac.exe is obselete, and XamlC.exe (available at the LHSDK prompt) should be used instead.  Thanks for the correction!

Update2 - Rob Relyea posts more on why to compile your XAML, when you don't have to compile, and what you need to have in order to do so here.

Posted: Nov 17 2003, 09:08 PM by thejay2 | with 8 comment(s)
Filed under:

Comments

Rob Relyea [MSFT] said:

Don't use AC.exe! That is obsolete.
As Chris has written, we did a major rearchitecture, AC.exe is part of the old architecture.

What you should use is XamlC.exe (which is currently installed with the LHSDK). When you run the Longhorn SDK Command Prompt - it will be in the path.
# November 18, 2003 5:05 AM

Henry Erich III said:

So, the only way to properly compile is to use xamlc and not ac. Which also would mean I have to get the SDK and couldnt complile with just a LH install?
# April 7, 2004 11:42 PM

Jason said:

To use precompiled XAML, yes, however there is a runtime environment built into Longhorn that runs non-compiled XAML.
# April 8, 2004 9:20 AM

Rob Relyea [msft] said:

We want to get to a model that will allow building in LH without the sdk having to be installed.

Here is what works now:
1) Msbuild.exe is shipping with LH, becuase the .net redist is part of LH.

Here are problems now:
1) set lapi=c:\windows\microsoft.net\windows\v6.0.4030
2) resgen.exe and al.exe need to be installed currently...i forget the path we are looking for it (perhaps %sdktoolpath% ????)
# April 8, 2004 7:36 PM

TrackBack said:

# April 8, 2004 7:37 PM

Henry Erich III said:

Ok, last night I put on the SDK (finally) and compiled a simple XAML with xamlc.exe. Awesome! I cant wait to do more!
# April 9, 2004 11:02 AM

Stanimir Stoyanov said:

Can someone tell me a good way to read BAML files? I tried the System.Windows.Serialization.BamlReader class, but it seemed not to work correctly - it gives some UIContext exception.

Thank you in advance,
Stan
# July 1, 2004 10:06 AM

w0lfshad3 said:

The first step is to compile the XAML files into BAML using the xamlc.exe compiler.For example, if your project includes a file name Window1.xaml, the compiler will create a

temporary file named Window1.baml and place it in the obj\Debug subfolder (in your project

folder). At the same time, a partial class is created for your window, using the language of

your choice. For example, if you’re using C#, the xamlc.exe compiler will create a file named

Window1.g.cs in the obj\Debug folder. The g stands for generated.

The partial class includes three things:

• Fields for all the controls in your window.

• Code that loads the BAML from the assembly, thereby creating the tree of objects. This

happens when the constructor calls InitializeComponent().

• Code that assigns the appropriate control object to each field and connects all the

event handlers. This happens in a method named Connect(), which the BAML parser

calls every time it finds a named object.

The partial class does not include code to instantiate and initialize your controls because

that task is performed by the WPF engine when the BAML is processed by the

Application.LoadComponent() method.

■Note As part of the XAML compilation process, the XAML compiler needs to create a partial class. This is

only possible if the language you’re using supports the .NET Code DOM model. C# and VB support Code

DOM, but if you’re using a third-party language you’ll need to make sure this support exists before you can

create compiled XAML applications.

...so read the filename.g.cs, it's how BAML is loaded.

# October 30, 2007 12:40 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)