Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 45 additions & 3 deletions Build/Tasks/PreparePackaging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
namespace DotNetNuke.Build.Tasks
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;

using Cake.Common.Diagnostics;
using Cake.Common.IO;
using Cake.Core.IO;
using Cake.Frosting;
using Cake.Json;
using Dnn.CakeUtils;
Expand Down Expand Up @@ -60,14 +64,52 @@ private static void CreateWebConfig(Context context)

context.PackagingPatterns = context.DeserializeJsonFromFile<PackagingPatterns>("./Build/Tasks/packaging.json");
var files = context.GetFilesByPatterns(context.WebsiteDir, BinFolderInclude, context.PackagingPatterns.InstallExclude);
var parsedAssemblies = files.ParseAssemblies();
parsedAssemblies.RemoveAll(a => a.PublicKeyToken is null);
var redirects = parsedAssemblies.ConvertAll(a => a.AssemblyBindingRedirect());
var redirects = BuildBindingRedirects(files);
assemblyBinding.Add(redirects.ToArray<object>());

// save XML document to target file
var targetFile = context.WebsiteDir + context.File("web.config");
doc.Save(targetFile);
}

private static List<XElement> BuildBindingRedirects(IEnumerable<FilePath> files)
{
XNamespace asm = "urn:schemas-microsoft-com:asm.v1";
var redirects = new List<XElement>();

foreach (var file in files)
{
AssemblyName assemblyName;
try
{
assemblyName = AssemblyName.GetAssemblyName(file.FullPath);
}
catch
{
continue;
}

var tokenBytes = assemblyName.GetPublicKeyToken();
if (tokenBytes == null || tokenBytes.Length == 0 || string.IsNullOrEmpty(assemblyName.Name) || assemblyName.Version == null)
{
continue;
}

var token = string.Concat(tokenBytes.Select(static b => b.ToString("x2", CultureInfo.InvariantCulture)));
redirects.Add(
new XElement(
asm + "dependentAssembly",
new XElement(
asm + "assemblyIdentity",
new XAttribute("name", assemblyName.Name),
new XAttribute("publicKeyToken", token)),
new XElement(
asm + "bindingRedirect",
new XAttribute("oldVersion", "0.0.0.0-32767.32767.32767.32767"),
new XAttribute("newVersion", assemblyName.Version.ToString()))));
}

return redirects;
}
}
}
Comment thread
mitchelsellers marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/************************************************************/
/***** SqlDataProvider *****/
/***** *****/
/***** *****/
/***** Note: To manually execute this script you must *****/
/***** perform a search and replace operation *****/
/***** for {databaseOwner} and {objectQualifier} *****/
/***** *****/
/************************************************************/
Loading