diff --git a/Dnn.CommunityMetrics.csproj b/Dnn.CommunityMetrics.csproj index 608ddb8..69a1b3c 100644 --- a/Dnn.CommunityMetrics.csproj +++ b/Dnn.CommunityMetrics.csproj @@ -9,7 +9,7 @@ Properties Dnn.CommunityMetrics Dnn.CommunityMetrics - v4.7.2 + v4.8 512 @@ -172,7 +172,7 @@ 9.11.1 - 0.32.0 + 10.0.0 diff --git a/Dnn.CommunityMetrics.dnn b/Dnn.CommunityMetrics.dnn index e566f43..4e3ca83 100644 --- a/Dnn.CommunityMetrics.dnn +++ b/Dnn.CommunityMetrics.dnn @@ -1,6 +1,6 @@ - + Dnn.CommunityMetrics Community Metrics ~/images/icon_extensions_32px.png @@ -17,7 +17,7 @@ 09.11.01 - + DesktopModules\Dnn.CommunityMetrics @@ -78,6 +78,11 @@ Dnn.CommunityMetrics.dll bin + + Octokit.dll + bin + 10.0.0 + diff --git a/build/Build.cs b/build/Build.cs index 48fca65..6041104 100644 --- a/build/Build.cs +++ b/build/Build.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Xml; +using BuildHelpers; using Microsoft.Build.Tasks; using Nuke.Common; using Nuke.Common.ChangeLog; @@ -99,8 +100,15 @@ class Build : NukeBuild .DependsOn(Compile) .Executes(() => { - var assembly = RootDirectory / "bin" / Configuration / $"{ProjectName}.dll"; - CopyFileToDirectory(assembly, DnnBinDirectory, policy: FileExistsPolicy.Overwrite); + var files = RootDirectory.GlobFiles( + $"bin/Debug/*{ProjectName}*.dll", + $"bin/Debug/*{ProjectName}*.pdb", + "bin/Debug/Octokit.dll"); + foreach (var file in files) + { + Helpers.CopyFileToDirectoryIfChanged(file, DnnBinDirectory); + } + }); Target Package => _ => _ @@ -112,7 +120,6 @@ class Build : NukeBuild var stagingDirectory = RootDirectory / "staging"; var rootFiles = RootDirectory.GlobFiles("*.dnn", "LICENSE"); var rootResourceFiles = RootDirectory.GlobFiles("*.ascx", "*.css"); - var assembly = RootDirectory / "bin" / Configuration / $"{ProjectName}.dll"; var appFolder = RootDirectory / "app"; var pluginsFolder = RootDirectory / "plugins"; var scriptsFolder = RootDirectory / "Scripts"; @@ -123,7 +130,22 @@ class Build : NukeBuild CopyDirectoryRecursively(scriptsFolder, stagingDirectory / "Scripts", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite); CopyDirectoryRecursively(appFolder, resourcesDirectory / "app", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite); CopyDirectoryRecursively(pluginsFolder, resourcesDirectory / "plugins", directoryPolicy: DirectoryExistsPolicy.Merge, filePolicy: FileExistsPolicy.Overwrite); - CopyFileToDirectory(assembly, stagingDirectory / "bin", policy: FileExistsPolicy.Overwrite, createDirectories: true); + + // Libraries + var manifest = RootDirectory.GlobFiles("*.dnn").FirstOrDefault(); + var binDirectory = RootDirectory / "bin" / Configuration; + var assemblies = binDirectory.GlobFiles("*.dll"); + var manifestAssemblies = Helpers.GetAssembliesFromManifest(manifest); + assemblies.ForEach(assembly => + { + var assemblyFile = new FileInfo(assembly); + var assemblyIncludedInManifest = manifestAssemblies.Any(a => a == assemblyFile.Name); + + if (assemblyIncludedInManifest) + { + CopyFileToDirectory(assembly, stagingDirectory / "bin", FileExistsPolicy.Overwrite); + } + }); resourcesDirectory.ZipTo(stagingDirectory / "resources.zip"); resourcesDirectory.DeleteDirectory(); diff --git a/build/Helpers.cs b/build/Helpers.cs new file mode 100644 index 0000000..7e72040 --- /dev/null +++ b/build/Helpers.cs @@ -0,0 +1,117 @@ +using Newtonsoft.Json; +using Nuke.Common; +using Nuke.Common.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Xml; +using static Nuke.Common.IO.FileSystemTasks; + +namespace BuildHelpers +{ + public class Helpers : NukeBuild + { + public static void CopyFileToDirectoryIfChanged(string source, string target) + { + var sourceFile = new FileInfo(source); + var destinationFile = new FileInfo(Path.Combine(target, sourceFile.Name)); + var destinationExists = destinationFile.Exists; + var sameSize = destinationExists ? sourceFile.Length == destinationFile.Length : false; + var sameContent = true; + + Serilog.Log.Debug("{0} is {1} Bytes", sourceFile.FullName, sourceFile.Length); + if (destinationExists) + { + Serilog.Log.Debug("{0} exists and is {1} Bytes", destinationFile.FullName, destinationFile.Length); + } + + if (destinationExists && sameSize) + { + sameContent = FilesAreEqual(sourceFile, destinationFile); + Serilog.Log.Debug(sameContent ? "Both files have the same content" : "The files have different contents"); + } + + if (!destinationExists || !sameSize || !sameContent) + { + CopyFileToDirectory(source, target, Nuke.Common.IO.FileExistsPolicy.OverwriteIfNewer); + Serilog.Log.Information("Copied {0} to {1}", sourceFile.Name, destinationFile.DirectoryName); + Serilog.Log.Debug("\n"); + } + else + { + Serilog.Log.Information("Skipped {0} since it is unchanged.", sourceFile.Name); + Serilog.Log.Debug("\n"); + } + } + + // Fast but accurate way to check if two files are difference (safer than write time for when rebuilding without changes). + private static bool FilesAreEqual(FileInfo first, FileInfo second) + { + const int BYTES_TO_READ = sizeof(long); + if (first.Length != second.Length) + { + return false; + } + + if (string.Equals(first.FullName, second.FullName, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + + int iterations = (int)Math.Ceiling((double)first.Length / BYTES_TO_READ); + + using (FileStream fs1 = first.OpenRead()) + { + using (FileStream fs2 = second.OpenRead()) + { + byte[] one = new byte[BYTES_TO_READ]; + byte[] two = new byte[BYTES_TO_READ]; + + for (int i = 0; i < iterations; i++) + { + fs1.Read(one, 0, BYTES_TO_READ); + fs2.Read(two, 0, BYTES_TO_READ); + + if (BitConverter.ToInt64(one, 0) != BitConverter.ToInt64(two, 0)) + { + return false; + } + } + } + } + return true; + } + + public static void AddFilesToZip(string zipPath, IReadOnlyCollection files) + { + if (files == null || files.Count == 0) + { + return; + } + + using (var zipArchive = ZipFile.Open(zipPath, ZipArchiveMode.Update)) + { + foreach (var file in files) + { + var fileInfo = new FileInfo(file); + zipArchive.CreateEntryFromFile(fileInfo.FullName, fileInfo.Name); + } + } + } + + public static IEnumerable GetAssembliesFromManifest(string manifestFilePath) + { + var doc = new XmlDocument(); + doc.Load(manifestFilePath); + var nodes = doc.SelectNodes("dotnetnuke/packages/package/components/component[@type='Assembly']/assemblies/assembly/name"); + List assemblies = new List(); + foreach (XmlNode node in nodes) + { + assemblies.Add(node.InnerText); + } + + return assemblies; + } + } +} \ No newline at end of file