Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Handle .NET assembly custom action built to target Any CPU architecture of .Net Runtime

Hi,

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).
screen1.jpg
screen1.jpg (78.03 KiB) Viewed 42954 times
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)

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

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

screen2.jpg
screen2.jpg (51.34 KiB) Viewed 42952 times
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
screen3.jpg
screen3.jpg (137.48 KiB) Viewed 42954 times
3. save and build your setup project

That is all!

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
matthewshorten
Posts: 6
Joined: Wed Jan 17, 2024 3:27 pm

Re: Handle .NET assembly custom action built to target Any CPU architecture of .Net Runtime

Note: it is possible on an x64 platform to find both the .NET x86 Runtime and the .NET x64 Runtime installed. So I'd recommend that the conditions attached to each version of your custom action be as follows:

CallDotNetMethod_x86:

Code: Select all

( NET7_X86 ) AND ( NOT NET7_x64 )
CallDotNetMethod_x64:

Code: Select all

NET7_x64
Otherwise you'll find both versions of your custom action are executed if such an environment is encountered
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Handle .NET assembly custom action built to target Any CPU architecture of .Net Runtime

Hi Matthew,

You are right. This is a good catch!

Thank you for your contribution on this!

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Sample Projects”