Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

c# - Check if .NETCore is installed using CustomAction with Wix

I want to cancel the installation if the NetCore 3.1 (preview) is not installed

I create this CustomAction :

using Microsoft.Deployment.WindowsInstaller;
using Microsoft.Win32;

namespace WixCustomAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CheckDotNetCore31Installed(Session session)
        {
            session.Log("Begin CheckDotNetCore31Installed");

            RegistryKey lKey = Registry.LocalMachine.OpenSubKey(@"SOFTWAREdotnetSetupInstalledVersionsx64sharedhost");

            var version = (string)lKey.GetValue("Version");

            session["DOTNETCORE31"] = version == "3.1.0-preview3.19553.2" ? "1" : "0";

            return ActionResult.Success;
        }
    }
}

Then in the WXS file :

<<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">

   <Product ...>

  (...)

    <Property Id="DOTNETCORE31">0</Property>

    <Condition Message="You must first install the .NET Core 3.1 Runtime">
      Installed OR DOTNETCORE31="1"
    </Condition>

    <InstallExecuteSequence>
      <Custom Action="Check.NetCore" Before="LaunchConditions">NOT Installed</Custom>
    </InstallExecuteSequence>

  </Product>

  <Fragment>
    <Binary Id="WixCA.dll" SourceFile="$(var.WixCustomAction.TargetDir)$(var.WixCustomAction.TargetName).CA.dll" />
    <CustomAction Id="Check.NetCore" BinaryKey="WixCA.dll" DllEntry="CheckDotNetCore31Installed" Execute="immediate"  />
  </Fragment>

And this is where I have a problem because I always get the warning message. An idea ? thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Debugging: Are you attaching the debugger to your custom action so you can see what is going on there? I bet it is not setting your property correctly. The custom action might not be running at all? Show a message box to smoke test that? More involved (attaching Visual Studio debugger):

LaunchCondition: In an MSI database launch conditions are represented by records in the LaunchCondition table. This table has two columns. The Condition column contains an expression which must evaluate to True for installation to continue:

MSI

Conclusion: So your condition does not evaluate to true properly. What is the actual value of DOTNETCORE31? I bet it is 0. Double check please. Easiest way is obviously to set it to 1 instead of 0 directly - and then compile again and test. Hard coding temporarily like this:

<Property Id="DOTNETCORE31">1</Property>

Links: Here are some previous answer on launch conditions and other topics:


WiX Custom Action: You have the basic markup for calling the custom action? Check the compiled MSI with Orca to see if there are entries in the Binary, CustomAction and InstallExecuteSequence and InstallUISequence tables. Some mock-up WiX markup (pillage gihub.com for samples?):

<Binary Id="CustomActions" SourceFile="C:Test.CA.dll" />

<...>

<CustomAction Id="CustomAction1" BinaryKey="CustomActions" DllEntry="CustomAction1"/>

<...>

<InstallUISequence>
  <Custom Action="CustomAction1" After="CostFinalize" />
</InstallUISequence>

<...>

<InstallExecuteSequence>
  <Custom Action="CustomAction1" After="CostFinalize" />
</InstallExecuteSequence>

GUI & Silent Install: Obviously you could also run the custom action from a dialog event - like a button click - but that would make it NOT run in silent mode. The GUI is skipped in silent mode so you need to run the custom action in the InstallExecuteSequence as well as the GUI.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...