Roslyn itself cannot, but you can use MSBuild for this (using the build XamlBuildTask). Here is a code snippet illustrating:
var msbuildTask = new PartialClassGenerationTask()
{
ApplicationMarkup = new[] { new XamlItem(@"c:\path\to\your\xaml") },
AssemblyName = "AssemblyName",
BuildTaskPath = typeof(PartialClassGenerationTask).Assembly.Location,
Language = "cs",
OutputPath = @"C:\temp",
References = new[]
{
new XamlItem(typeof(Uri).Assembly.Location),
new XamlItem(typeof(XamlLanguage).Assembly.Location),
new XamlItem(typeof(System.Windows.Point).Assembly.Location),
new XamlItem(typeof(System.Windows.Application).Assembly.Location),
new XamlItem(typeof(ApplicationGesture).Assembly.Location)
},
RequiresCompilationPass2 = false
};
msbuildTask.Execute();
"" - . , typeof(ApplicationGesture).Assembly.Location.
, :
- System.Xaml
- WindowsBase
- PresentationFramework
- PresentationCore
, XamlItem ( ITaskItem):
private class XamlItem : ITaskItem
{
public XamlItem(string path)
{
ItemSpec = path;
}
public string ItemSpec { get; set; }
public string GetMetadata(string metadataName) { return ""; }
public void SetMetadata(string metadataName, string metadataValue) {}
public void RemoveMetadata(string metadataName) { }
public void CopyMetadataTo(ITaskItem destinationItem) { }
public IDictionary CloneCustomMetadata() { return null; }
public ICollection MetadataNames { get { return null; } }
public int MetadataCount { get { return 0; } }
}
. MSDN PartialClassGenerationTask