diff --git a/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs b/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs index 54db830f2f..4dedb218a1 100644 --- a/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs +++ b/src/Avalonia.Build.Tasks/CompileAvaloniaXamlTask.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using System.Threading; using Microsoft.Build.Framework; @@ -12,13 +13,23 @@ namespace Avalonia.Build.Tasks public bool Execute() { OutputPath = OutputPath ?? AssemblyFile; + var outputPdb = GetPdbPath(OutputPath); var input = AssemblyFile; + var inputPdb = GetPdbPath(input); // Make a copy and delete the original file to prevent MSBuild from thinking that everything is OK if (OriginalCopyPath != null) { File.Copy(AssemblyFile, OriginalCopyPath, true); input = OriginalCopyPath; File.Delete(AssemblyFile); + + if (File.Exists(inputPdb)) + { + var copyPdb = GetPdbPath(OriginalCopyPath); + File.Copy(inputPdb, copyPdb, true); + File.Delete(inputPdb); + inputPdb = copyPdb; + } } var res = XamlCompilerTaskExecutor.Compile(BuildEngine, input, @@ -27,14 +38,30 @@ namespace Avalonia.Build.Tasks if (!res.Success) return false; if (res.Data == null) - File.Copy(input, OutputPath); + { + File.Copy(input, OutputPath, true); + if(File.Exists(inputPdb)) + File.Copy(inputPdb, OutputPath, true); + } else + { File.WriteAllBytes(OutputPath, res.Data); + if (res.Symbols != null) + File.WriteAllBytes(outputPdb, res.Symbols); + } return true; } - - + + string GetPdbPath(string p) + { + var d = Path.GetDirectoryName(p); + var f = Path.GetFileNameWithoutExtension(p); + var rv = f + ".pdb"; + if (d != null) + rv = Path.Combine(d, rv); + return rv; + } [Required] public string AssemblyFile { get; set; } diff --git a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs index 63672ee98b..f3967e9bb3 100644 --- a/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs +++ b/src/Avalonia.Build.Tasks/XamlCompilerTaskExecutor.cs @@ -30,11 +30,13 @@ namespace Avalonia.Build.Tasks { public bool Success { get; set; } public byte[] Data { get; set; } + public byte[] Symbols { get; } - public CompileResult(bool success, byte[] data = null) + public CompileResult(bool success, byte[] data = null, byte[] symbols = null) { Success = success; Data = data; + Symbols = symbols; } } @@ -283,8 +285,15 @@ namespace Avalonia.Build.Tasks loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret)); var ms = new MemoryStream(); - asm.Write(ms); - return new CompileResult(true, ms.ToArray()); + var symbolStream = new MemoryStream(); + asm.Write(ms, new WriterParameters + { + SymbolStream = symbolStream, + WriteSymbols = true, + SymbolWriterProvider = new PortablePdbWriterProvider() + }); + + return new CompileResult(true, ms.ToArray(), symbolStream.Length == 0 ? null : symbolStream.ToArray()); } } diff --git a/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github b/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github index c28bd89bf4..22a7267a22 160000 --- a/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github +++ b/src/Markup/Avalonia.Markup.Xaml/XamlIl/xamlil.github @@ -1 +1 @@ -Subproject commit c28bd89bf4c315c188394139f500f7f4efed4b94 +Subproject commit 22a7267a22124cd2413f83082298b5c0e10a8c02