Ehsan Ghorabian
Ehsan Ghorabian

Reputation: 21

How to Use CustomAction in Bootstrapper ExePackage DetectCondition to realize net core installed or not

I am trying to use customAction method in a Bootstrapper project to determined specific version of .net core is installed or not, but it not work

here is my wsx file code


<Fragment>

        <WixVariable Id="TargetFileName" Value="[WixBundleSourceProcessPath]" Overridable="yes" />

        <Binary Id="CustomAction.dll" SourceFile="$(var.CustomAction.TargetDir)CustomAction.CA.dll" />

        <CustomAction Id="CheckASPNETCore" Return="check" Execute="immediate" Impersonate="no" BinaryKey=".CustomAction.dll" DllEntry="TestMethod" />

        
        <WixVariable Id="ASPDOTNETCORE60" Value="[ASPDOTNETCORE60]" Overridable="yes" />


        <PackageGroup Id="NetRuntime6Web">
            <ExePackage
                Name="dotnet-hosting-6.0.8-win.exe"
                InstallCommand="/install /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
                RepairCommand="/repair /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
                UninstallCommand="/uninstall /quiet /norestart /log &quot;[AspNetCoreRuntime6Log]&quot;"
                PerMachine="yes"
                DetectCondition="[ASPDOTNETCORE60] = 1"
                Vital="yes"
                Permanent="yes"
                Protocol="burn"
                DownloadUrl="https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/runtime-aspnetcore-6.0.8-windows-hosting-bundle-installer"
                LogPathVariable="AspNetCoreRuntime6Log"
                SourceFile="C:\Net\dotnet-hosting-6.0.8-win.exe"
                Compressed="yes">

            </ExePackage>
        </PackageGroup>
    </Fragment>

[CustomAction]
    public static ActionResult TestMethod(Session session)
    {

        session.Log($"Test Method Run");

        session["ASPDOTNETCORE60"] = "1";

        return ActionResult.Success;
    }

and here is my customAction

and this is the error I'm getting where run exe file

[26A0:E8C4][2022-12-01T12:17:46]e000: Error 0x8007000d: Failed to parse condition "[ASPDOTNETCORE60] = 1". Unexpected character at position 0.

how can I use that customAction ???

Upvotes: 0

Views: 575

Answers (1)

Michal Diviš
Michal Diviš

Reputation: 2206

Each version of the .NET Runtime will create a directory in Program Files\dotnet\shared\Microsoft.NETCore.App\

The existance of the directory Program Files\dotnet\shared\Microsoft.NETCore.App\6.0.5 confirms the existance of .NET Runtime version 6.0.5. Using this knowledge, you can do a simple DirectorySearch in Wix to check whether a specific version of the runtime is installed like so:

<!-- Check if NET 6.0 Runtime already installed -->
<util:DirectorySearch
    Path="[ProgramFiles6432Folder]dotnet\shared\Microsoft.NETCore.App\6.0.5"
    Result="exists"
    Variable="Net6RuntimeExists"/>

Here's the (almost) full file for clarity:

<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  
    <Bundle ...>

    ... code removed for brevity
    
        <!-- Check if NET 6.0 Runtime already installed -->
        <util:DirectorySearch
            Path="[ProgramFiles6432Folder]dotnet\shared\Microsoft.NETCore.App\6.0.5"
            Result="exists"
            Variable="Net6RuntimeExists" />

        <Chain>

            <!--This will only be installed when the .NET 6 Runtime is not already installed-->
            <ExePackage
                Id="TheNet6Runtime"
                DisplayName=".NET 6 Desktop Runtime"
                Vital="no"
                Cache="no"
                Permanent="yes"
                InstallCommand="/install /quiet /norestart"
                SourceFile="windowsdesktop-runtime-6.0.5-win-x64.exe"
                DetectCondition="Net6RuntimeExists" />

                ... code removed for brevity
            
        </Chain>
    </Bundle>
</Wix>

Upvotes: 0

Related Questions