Compile Xaml into Baml?

后端 未结 2 1355
后悔当初
后悔当初 2021-02-09 03:06

How can I convert a xaml to baml?

thanks

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-09 03:22

    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:

    
    
      
        9.0.30729
        2.0
        library
        v3.5
        {6B8967FF-37B7-43E8-B866-FFD6F13FFC0A}
      
      
        
        
          3.5
        
        
          3.5
        
        
          3.5
        
        
        
        
        
        
        
      
      
        
          MSBuild:Compile
          Designer
        
      
      
    
    

    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.

提交回复
热议问题