Compile xaml using Roslyn

蹲街弑〆低调 提交于 2019-12-07 08:08:36

问题


Short story: is there a way to use Roslyn compiler to compile a WPF UserControl?

  • Let's say you'd want to compile an assembly containing standard C# code and WPF controls (XAML and xaml.cs files) without any csproj of course.

  • I've found a lot on the web on how to compile a DLL using Roslyn, nothing on how to handle XAML files?

  • I know that Visual Studio (or MSBuild) creates a temporary generated file and embed a BAML file in the resulting assembly. So maybe if I could find a way to generate this intermediate file I could use it, but all I have found is PresentationBuildTasks.MarkupCompilePass that needs in the end a csproj (ok, I may generate a project on the fly, but I hope to find something simpler).

Thanks for any help.


回答1:


If your goal is to compile XAML to C#, check out the XAML Code Behind Generator, see http://xamlgenerator.codeplex.com/.

Its a plugin for Visual Studio 2010 that allows you to compile XAML into the equivalent C#.



来源:https://stackoverflow.com/questions/23106561/compile-xaml-using-roslyn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!