Compile Xaml to Baml?

How to convert xaml to baml?

thanks

+7
wpf xaml baml
source share
2 answers

You can compile XAML by creating an MSBuild project file that references it. This is what happens under the covers in Visual Studio when you compile in your project (it creates a temporary .proj file and builds it).

The pretty minimal project file (xamlcompile.csproj) looks something like this:

<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <ProductVersion>9.0.30729</ProductVersion> <SchemaVersion>2.0</SchemaVersion> <OutputType>library</OutputType> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <ProjectGuid>{6B8967FF-37B7-43E8-B866-FFD6F13FFC0A}</ProjectGuid> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="System.Core"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> <Reference Include="System.Xml.Linq"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> <Reference Include="System.Data.DataSetExtensions"> <RequiredTargetFramework>3.5</RequiredTargetFramework> </Reference> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> <Reference Include="WindowsBase" /> <Reference Include="PresentationCore" /> <Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework.Classic" /> </ItemGroup> <ItemGroup> <Page Include="Themes\Generic.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </Page> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project> 

And you can generate the BAML file by running the command:

 MSBuild /t:ResolveReferences;MarkupCompilePass1;MarkupCompilePass2 xamlcompile.csproj 

This will create a baml file in obj \ Debug, in the example above would be obj \ Debug \ Themes \ Generic.baml.

Hope this helps.

+11
source share

There is a Reflector plugin that loads assemblies containing BAML resources (for example, localized resource assemblies) and shows the corresponding XAML: BamlViewer

When you compile a WPF application in Visual Studio, all your XAML files are converted to BAML, and then BAML is injected as a resource into the final assembly of the DLL or EXE.

+2
source share

All Articles