Skip to content

Commit

Permalink
Use ILMerge to repack binaries for net35, net45 and net461
Browse files Browse the repository at this point in the history
  • Loading branch information
zharkovstas committed Mar 2, 2020
1 parent d6f7302 commit 43fcd41
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions build.cake
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#tool "nuget:?package=ILMerge&version=2.12.803"
#addin "nuget:?package=Cake.Git&version=0.21.0"
#tool "nuget:?package=ILRepack.MSBuild.Task&version=2.0.13"
#tool "nuget:?package=protobuf-net&version=1.0.0.280"
Expand All @@ -16,7 +17,7 @@ var DiadocApiSolutionPath = "./DiadocApi.sln";
var binariesNet35Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-net35-binaries.zip");
var binariesNet45Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-net45-binaries.zip");
var binariesNet461Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-net461-binaries.zip");
var binariesNetStandard2Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-netstabdard2.0-binaries.zip");
var binariesNetStandard2Zip = buildDir.CombineWithFilePath("diadocsdk-csharp-netstandard2.0-binaries.zip");
var needSigning = false;

var packageVersion = "";
Expand Down Expand Up @@ -159,7 +160,7 @@ Task("Build")
}
});

Task("ILRepack")
Task("Repack")
.IsDependentOn("Build")
.Does(() =>
{
Expand All @@ -169,12 +170,35 @@ Task("ILRepack")
? new FilePath("./src/diadoc.snk")
: null;

Repack("net35", TargetPlatformVersion.v2, keyFile);
Repack("net45", TargetPlatformVersion.v4, keyFile);
Repack("net461", TargetPlatformVersion.v4, keyFile);
Repack("netstandard2.0", TargetPlatformVersion.v4, keyFile);
RepackWithILMerge("net35", TargetPlatformVersion.v2, keyFile);
RepackWithILMerge("net45", TargetPlatformVersion.v4, keyFile);
RepackWithILMerge("net461", TargetPlatformVersion.v4, keyFile);
RepackWithILRepack("netstandard2.0", TargetPlatformVersion.v4, keyFile);

void Repack(string targetFramework, TargetPlatformVersion targetPlatformVersion, FilePath signWithKeyFile)
void RepackWithILMerge(string targetFramework, TargetPlatformVersion targetPlatformVersion, FilePath signWithKeyFile)
{
var ilMergeSettings = new ILMergeSettings
{
Internalize = true
};

if (needSigning)
{
var keyFile = signWithKeyFile.MakeAbsolute(Context.Environment).FullPath;
ilMergeSettings.ArgumentCustomization = args => args.Append("/keyfile:" + keyFile);
}

ilMergeSettings.TargetPlatform = new TargetPlatform(targetPlatformVersion);

CreateDirectory(outputDir.Combine(targetFramework));
ILMerge(
outputDir.Combine(targetFramework).CombineWithFilePath("DiadocApi.dll"),
sourceDir.Combine(targetFramework).CombineWithFilePath("DiadocApi.dll"),
new FilePath[] { sourceDir.Combine(targetFramework).CombineWithFilePath("protobuf-net.dll") },
ilMergeSettings);
}

void RepackWithILRepack(string targetFramework, TargetPlatformVersion targetPlatformVersion, FilePath signWithKeyFile)
{
var ilRepackSettings = new ILRepackSettings
{
Expand All @@ -196,7 +220,7 @@ Task("ILRepack")

Task("PrepareBinaries")
.IsDependentOn("GenerateVersionInfo")
.IsDependentOn("ILRepack")
.IsDependentOn("Repack")
.Does(() =>
{
DeleteFiles(GetFiles(buildDir.FullPath + "/**/JetBrains.Annotations*"));
Expand Down Expand Up @@ -279,7 +303,7 @@ Task("Appveyor")
.IsDependentOn("PrepareBinaries")
.IsDependentOn("Build")
.IsDependentOn("Test")
.IsDependentOn("ILRepack")
.IsDependentOn("Repack")
.IsDependentOn("Nuget-Pack")
.IsDependentOn("PublishArtifactsToAppVeyor");

Expand Down

0 comments on commit 43fcd41

Please sign in to comment.