[wix-users] .NET 7 NativeAOT Custom Actions appear to work

Bob Arnson bob at firegiant.com
Tue Nov 15 08:43:43 PST 2022


https://github.com/heaths/msica-rs


From: Edwin Young <the.edwin.young at gmail.com>
Sent: Tuesday, 15 November, 2022 10:47
To: Bob Arnson <bob at firegiant.com>
Cc: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Subject: Re: [wix-users] .NET 7 NativeAOT Custom Actions appear to work

Rust ought to work - anyone know of an example of actually doing that? A web search didn't turn up any.

One of the things that interested me with the .NET approach is that a convenient wrapper over the unmanaged windows installer API already exists.

On Tue, Nov 15, 2022, 5:19 AM Bob Arnson <bob at firegiant.com<mailto:bob at firegiant.com>> wrote:
That it's only 3MB is actually pretty impressive.

But Rust can do better. 😊

> -----Original Message-----
> From: wix-users <wix-users-bounces at lists.wixtoolset.org<mailto:wix-users-bounces at lists.wixtoolset.org>> On Behalf Of
> Edwin Young via wix-users
> Sent: Tuesday, 15 November, 2022 01:45
> To: wix-users at lists.wixtoolset.org<mailto:wix-users at lists.wixtoolset.org>
> Cc: Edwin Young <the.edwin.young at gmail.com<mailto:the.edwin.young at gmail.com>>
> Subject: [wix-users] .NET 7 NativeAOT Custom Actions appear to work
>
> Hi,
>
> I've long found it a bit frustrating to write custom actions - writing HRESULT-
> style C++ makes me sad, and managed custom actions, despite the awesome
> work the Wix team has put in, have some drawbacks, like the dependency on
> having a compatible framework installed.
>
> So I was quite excited to see that .NET 7 has the ability to output DLLs which
> have no dependencies and can be called from unmanaged code :-) See
> samples/core/nativeaot/NativeLibrary
> at main · dotnet/samples · GitHub
> <https://github.com/dotnet/samples/tree/main/core/nativeaot/NativeLibrar
> y>
>
> I wanted to see if this would work for Custom Actions, and according to my
> very first experiment, the answer appears to be yes!
>
> edyoung/net7ca: Experiment to see if I can write Custom Actions in .NET 7
> (github.com<http://github.com>) <https://github.com/edyoung/net7ca>
>
> I can write a custom action in C#:
>
> using System.Runtime.InteropServices;
> using WixToolset.Dtf.WindowsInstaller;
>
> namespace CustomAction;
> public class Class1
> {
>     [UnmanagedCallersOnly(EntryPoint = "CustomAction2")]
>     public static uint CustomAction2(IntPtr handle)
>     {
>         using Session session = Session.FromHandle(handle, false);
>
>         session.Log("Custom Action 2 Called");
>         return 0;
>     }
> }
>
> Compile it with .NET 7, publish it, and call it from an installer. The log
> message appears in the MSI log!
>
> The binary DLL which is output contains all the bits of the CLR which are
> required, which turns out to be about 3MB - painfully large, but not
> impossible if you have a largish install package.
>
> So obviously, this is a very long way from a production solution - there are
> likely all sorts of problems ahead - but I'm quite excited about the
> possibilities, so I wanted to share.
>
> Also, Wix4 worked beautifully first time for this experiment. Thanks Rob &
> co!
>
> Happy installing!
> --
> Edwin
>
> ________________________________________________________________
> ____
> WiX Toolset Users Mailing List provided by FireGiant
> http://www.firegiant.com/


More information about the wix-users mailing list