Compile Xaml into Baml?
Asked Answered
E

2

9

How can I convert a xaml to baml?

thanks

Elijaheliminate answered 1/6, 2009 at 13:59 Comment(0)
O
11

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

A fairly minimal project file (xamlcompile.csproj) is 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 then generate the BAML file by running the command:

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

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

Hope that helps.

Ottar answered 11/11, 2009 at 9:23 Comment(0)
P
2

There is a Reflector plug-in that loads assemblies containing BAML resources (e.g. localized resource assemblies) and shows the corresponding XAML: BamlViewer

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

Paediatrician answered 1/6, 2009 at 14:40 Comment(2)
Look in your project's obj\Debug directory Hans. Visual Studio is generating BAML files and putting them there before embedding them in the final DLL or EXE.Farmhouse
Would the downvoter (to this very old answer) please leave a comment. Thanks.Paediatrician

© 2022 - 2024 — McMap. All rights reserved.