How to handle .NET assembly custom action built to target any CPU architecture of .Net Runtime

Let's assume you have built a .Net assembly custom action DLL that can be ran by both architectures of .NET Runtime (Any CPU build configuration).

Custom action

Now you may want the above custom action code be executed at install time by your setup package regardless the .NET Runtime architecture (x86 or x64) present on target machine.

In this case the solution is to create a registry search to detect the existing installed architecture of .NET Runtime. Then to create two sibling custom actions: one which will run using as condition the x86 registry search of .Net Runtime and the other which will run using as condition the x64 registry search of .Net Runtime.

This is because our built-in "Call method from .Net assembly custom action" type does not support targeting simultaneously both architectures ("Any CPU') of .NET Runtime. It can either target the x64 architecture or the x86 one.

To implement the above solution into your setup project you should proceed like this:

1. Go to Search page and create two extended searches like this (lets assume your .NET DLL targets .NET Runtime 7).

The first search should be configured like this:

Criteria: "Folder sub-folders enumeration contains version"
Folder: [ProgramFiles64Folder]dotnet\shared\Microsoft.WindowsDesktop.App
Minimum: 7.0.0
Search the 64-bit: checked

The second search should be configured like this:

Criteria: "Folder sub-folders enumeration contains version"
Folder: [ProgramFilesFolder]dotnet\shared\Microsoft.WindowsDesktop.App
Minimum: 7.0.0
Search the 64-bit: unchecked

Search page

2. Go to Custom Actions Page and create two duplicate custom actions that will call your .NET DLL and will be conditioned to run only when the x86, respectively x64 version of .NET Runtime is detected.

Custom actions page

3. The last step is to save and build your project.