diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs
index 890967ae4f..fe877dc49c 100644
--- a/nukebuild/Build.cs
+++ b/nukebuild/Build.cs
@@ -268,6 +268,8 @@ partial class Build : NukeBuild
.DependsOn(CreateIntermediateNugetPackages)
.Executes(() =>
{
+ BuildTasksPatcher.PatchBuildTasksInPackage(Parameters.NugetIntermediateRoot / "Avalonia.Build.Tasks." +
+ Parameters.Version + ".nupkg");
var config = Numerge.MergeConfiguration.LoadFile(RootDirectory / "nukebuild" / "numerge.config");
EnsureCleanDirectory(Parameters.NugetRoot);
if(!Numerge.NugetPackageMerger.Merge(Parameters.NugetIntermediateRoot, Parameters.NugetRoot, config,
diff --git a/nukebuild/BuildTasksPatcher.cs b/nukebuild/BuildTasksPatcher.cs
new file mode 100644
index 0000000000..44f01da669
--- /dev/null
+++ b/nukebuild/BuildTasksPatcher.cs
@@ -0,0 +1,76 @@
+using System;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using ILRepacking;
+using Mono.Cecil;
+
+public class BuildTasksPatcher
+{
+ public static void PatchBuildTasksInPackage(string packagePath)
+ {
+ using (var archive = new ZipArchive(File.Open(packagePath, FileMode.Open, FileAccess.ReadWrite),
+ ZipArchiveMode.Update))
+ {
+
+ foreach (var entry in archive.Entries.ToList())
+ {
+ if (entry.Name == "Avalonia.Build.Tasks.dll")
+ {
+ var temp = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".dll");
+ var output = temp + ".output";
+ var patched = new MemoryStream();
+ try
+ {
+ entry.ExtractToFile(temp, true);
+ var repack = new ILRepacking.ILRepack(new RepackOptions()
+ {
+ Internalize = true,
+ InputAssemblies = new[]
+ {
+ temp, typeof(Mono.Cecil.AssemblyDefinition).Assembly.GetModules()[0]
+ .FullyQualifiedName
+ },
+ SearchDirectories = new string[0],
+ OutputFile = output
+ });
+ repack.Repack();
+
+
+ // 'hurr-durr assembly with the same name is already loaded' prevention
+ using (var asm = AssemblyDefinition.ReadAssembly(output,
+ new ReaderParameters { ReadWrite = true, InMemory = true, }))
+ {
+ asm.Name = new AssemblyNameDefinition(
+ "Avalonia.Build.Tasks."
+ + Guid.NewGuid().ToString().Replace("-", ""),
+ new Version(0, 0, 0));
+ asm.Write(patched);
+ patched.Position = 0;
+ }
+ }
+ finally
+ {
+ try
+ {
+ if (File.Exists(temp))
+ File.Delete(temp);
+ if (File.Exists(output))
+ File.Delete(output);
+ }
+ catch
+ {
+ //ignore
+ }
+ }
+
+ var fn = entry.FullName;
+ entry.Delete();
+ var newEntry = archive.CreateEntry(fn, CompressionLevel.Optimal);
+ using (var s = newEntry.Open())
+ patched.CopyTo(s);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/nukebuild/_build.csproj b/nukebuild/_build.csproj
index 584c36d033..4c64d4ff93 100644
--- a/nukebuild/_build.csproj
+++ b/nukebuild/_build.csproj
@@ -14,6 +14,9 @@
+
+
+
diff --git a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
index 449c1b483a..65dcfd21d2 100644
--- a/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
+++ b/src/Avalonia.Build.Tasks/Avalonia.Build.Tasks.csproj
@@ -49,25 +49,6 @@
-
-
-
-
-
- $(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework)
-
-
-
-
-
-
-
-
-
-
-
-
-