Skip to content

Commit

Permalink
Wix4: #1587 Support for pulling in dlls for runtime dependencies
Browse files Browse the repository at this point in the history
      Added `Project.AddCastomActionRefAssembliesOf` to add CA referenced assemblies programmatically.
  • Loading branch information
oleg-shilo committed Jul 13, 2024
1 parent 9b5553a commit 49e2ccb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
31 changes: 31 additions & 0 deletions Source/src/WixSharp/CommonTasks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,37 @@ static public void Wxl3_to_Wxl4(this string source, string destination)
Encoding.UTF8);
}

/// <summary>
/// Adds the reference assemblies of a `Type` (typically from the custom action assembly) to the MSI project.
/// <p>Every managed CA requires its dependency assemblies to be referenced via
/// <see cref="WixSharp.ManagedAction.RefAssemblies"/>. This method is a convenient way to add all the
/// dependencies automatically. It analyzes the CA assembly dependencies and adds them to the
/// CA binary that is packaged with "WixToolset.Dtf.MakeSfxCA.exe".
/// </p>
/// <p>Note, this method may unnecessarily increase the size of the msi as not all CA dependency assemblies
/// may be required at runtime (during the installation).</p>
/// </summary>
/// <param name="project">The project.</param>
/// <param name="type">The Type from the managed CA.</param>
public static void AddCustomActionRefAssembliesOf(this Project project, Type type)
{
var dependencies = type.Assembly
.GetReferencedAssemblies()
.Where(x => !x.Name.StartsWith("System"))
.Select(x =>
{
try
{
return System.Reflection.Assembly.Load(x).Location;
}
catch { return null; }
})
.Where(x => x.IsNotEmpty() && !x.StartsWith(Environment.SpecialFolder.Windows.GetPath(), true))
.ToArray();

project.DefaultRefAssemblies.AddRange(dependencies);
}

/// <summary>
/// Sets the Project version from the file version of the file specified by it's ID.
/// <para>This method sets project WixSourceGenerated event handler and injects
Expand Down
1 change: 0 additions & 1 deletion Source/src/WixSharp/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3417,7 +3417,6 @@ static void PackageManagedAsm(string asm, string nativeDll, string[] refAssembli
(pdbFileArgument ?? " ") +
referencedAssemblies;

// makeSfxCA_args += $" \"{dtfWinInstaller}\" \"{wixToolsetMbaCore}\"";
makeSfxCA_args += $" \"{dtfWinInstaller}\"";

ProjectValidator.ValidateCAAssembly(asmFile);
Expand Down

0 comments on commit 49e2ccb

Please sign in to comment.