如何使用WiX Bootstrapper从客户机获取.NET运行时版本?

huangapple go评论70阅读模式
英文:

how to fetch the .net runtime version from a client machine using wix bootstarper?

问题

我的要求是检查客户机器上最新的.NET运行时版本,以便我可以比较特定版本是否属于.NET 6运行时,我已经尝试了一些步骤来实现我的需求。

<util:RegistrySearch Id="DotNetVersionSearch" Variable="DOTNETVERSION"
                     Root="HKLM"
                     Key="SOFTWARE\Wow6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App"
                     Value="Version"
                     Result="value" />

我在片段的顶部声明了一个名为<Property Id="DOTNETVERSION" Secure="yes" />的特定变量。

我定义了一个自定义操作来验证.NET运行时版本是否属于.NET 6,如下所示。

<CustomAction  Id="CheckDotNetVersion"
                BinaryKey="CustomActionBinary"
                DllEntry="CheckDotNetVersion"
                Execute="immediate"
                Return="check" />

我在一个名为Customaction.cs的类中定义了该操作。

[CustomAction]
public static ActionResult CheckDotNetVersion(Session session)
{
    string dotNetVersion = session["DotNetVersion"];
    string dotNetVersionMin = session["DotNetVersionMin"];

    Version version;
    Version versionMin;

    if (!Version.TryParse(dotNetVersion, out version))
    {
        session.Log("Failed to parse DotNetVersion.");
        return ActionResult.Failure;
    }

    if (!Version.TryParse(dotNetVersionMin, out versionMin))
    {
        session.Log("Failed to parse DotNetVersionMin.");
        return ActionResult.Failure;
    }

    int result = version.CompareTo(versionMin);

    session["WIX_DOTNET_VERSION_COMPARE"] = result.ToString();

    return ActionResult.Success;
}

用于显示错误的bal:Condition标记如下所示。

<bal:Condition
        Message="This setup requires Microsoft .NET 6.0 or above."
        ><![CDATA[Installed OR (NOT Installed AND WIX_DOTNET_VERSION_COMPARE >= 0)]]>
    </bal:Condition>

但是这不起作用,有人能帮助我解决这个问题吗?

英文:

my requirement is to check the latest .net runtime version in client machine so that i can compare weather the particular version is belong to .net 6 runtimes or not ,i have tried some few steps to achieve my requirement

&lt;util:RegistrySearch Id=&quot;DotNetVersionSearch&quot; Variable=&quot;DOTNETVERSION&quot;
					 Root=&quot;HKLM&quot;
					 Key=&quot;SOFTWARE\Wow6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.WindowsDesktop.App&quot;
					 Value=&quot;Version&quot;
				     Result=&quot;value&quot; /&gt;

the paricular variable I have declared on top of fragement &lt;Property Id=&quot;DOTNETVERSION&quot; Secure=&quot;yes&quot; /&gt;

and I have define one custom action to verify weather the .net runtime version is belong to .net 6 or not like below .

 &lt;CustomAction  Id=&quot;CheckDotNetVersion&quot;
				BinaryKey=&quot;CustomActionBinary&quot;
				DllEntry=&quot;CheckDotNetVersion&quot;
				Execute=&quot;immediate&quot;
				Return=&quot;check&quot; /&gt;

and the action i have defined in a class named as Customaction.cs

    [CustomAction]
    public static ActionResult CheckDotNetVersion(Session session)
    {
        string dotNetVersion = session[&quot;DotNetVersion&quot;];
        string dotNetVersionMin = session[&quot;DotNetVersionMin&quot;];

        Version version;
        Version versionMin;

        if (!Version.TryParse(dotNetVersion, out version))
        {
            session.Log(&quot;Failed to parse DotNetVersion.&quot;);
            return ActionResult.Failure;
        }

        if (!Version.TryParse(dotNetVersionMin, out versionMin))
        {
            session.Log(&quot;Failed to parse DotNetVersionMin.&quot;);
            return ActionResult.Failure;
        }

        int result = version.CompareTo(versionMin);

        session[&quot;WIX_DOTNET_VERSION_COMPARE&quot;] = result.ToString();

        return ActionResult.Success;
    }

and for displaying the error I have used the bal:Condition tag like below

&lt;bal:Condition
        Message=&quot;This setup requires Microsoft .NET 6.0 or above.&quot;
        &gt;&lt;![CDATA[Installed OR (NOT Installed AND WIX_DOTNET_VERSION_COMPARE &gt;= 0)]]&gt;
    &lt;/bal:Condition&gt;

but this is not working , can somebody help me on this to fix the issue

答案1

得分: 3

Wix具有内置的.NET版本检查支持,您可以使用以下链接了解详情:

https://wixtoolset.org/docs/tools/wixext/dotnet/#net-and-net-core

Wix 3.x似乎不支持默认情况下检测.NET 6(但我不是完全确定),但Wix 4支持,所以您可能需要升级。

要找出您的代码有什么问题,您可以使用日志文件运行安装程序(msiexec yourfile.msi /l*v log.txt),然后在运行后检查日志中传递的变量的值。

除此之外,我不太确定为什么您要使用&lt;bal:Condition&gt;,这是为“bal”引导程序(在安装开始之前运行的程序)而设计的。自定义操作是在安装过程中执行的,而不是在引导程序中执行的。就我所见,这个条件没有机会生效。

英文:

Wix has a built-in support for .NET version check, you can use that:

https://wixtoolset.org/docs/tools/wixext/dotnet/#net-and-net-core

Wix 3.x does not seem to support .NET 6 detection out of the box (but I am not completely sure), but Wix 4 does, so you may need to upgrade.

To figure out what is not working with your code, you can run your installer with a log file (msiexec yourfile.msi /l*v log.txt), and check the values of your variables passed around in the log after run.

Other than that, not quite sure why you are using &lt;bal:Condition&gt;, it is for "bal", the bootstrapper (a program that runs before your installation starts). Custom actions are executed during the installation, not in a bootstrapper. So, there is no chance for this condition to work, as far as I can see?

huangapple
  • 本文由 发表于 2023年7月3日 17:31:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76603492.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定