将Xaml编译成Baml吗? [英] Compile Xaml into Baml?

查看:156
本文介绍了将Xaml编译成Baml吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将xaml转换为baml?

How can I convert a xaml to baml?

谢谢

推荐答案

您可以通过创建引用XAML的MSBuild项目文件来编译XAML.当您在项目上进行编译时(这会创建一个临时的.proj文件并进行构建),这就是Visual Studio在幕后"发生的情况.

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).

一个相当小的项目文件(xamlcompile.csproj)是这样的:

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>

然后您可以通过运行以下命令来生成BAML文件:

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

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

这将在obj \ Debug下创建一个baml文件,在上面的示例中,它将是obj \ Debug \ Themes \ Generic.baml.

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

希望有帮助.

这篇关于将Xaml编译成Baml吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆