问题
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