简体   繁体   English

如何检查.NET 6运行时是否安装

[英]How to check whether the .NET 6 runtime is installed

As part of installation of a WPF application using .NET 6 and a WiX installer, I would like to check whether the .NET 6 runtime is installed.作为使用 .NET 6 和 WiX 安装程序安装 WPF 应用程序的一部分,我想检查是否已安装 Z3036BB0EF9EDB908 运行时。

WiX provides pre-defined properties to check this for .NET framework but nothing for .NET Core and beyond so I am attempting to check for the presence of a registry key. WiX 提供了预定义的属性来检查 .NET 框架,但对于 .NET Core 及以上没有,所以我试图检查是否存在注册表项。

There is a registry key that can be checked under: HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost\Version有一个注册表项可以检查:HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost\Version

However, if I uninstall the runtime the registry key does not get removed, is there any other reliable way to check whether the runtime is installed, as well as which version is installed?但是,如果我卸载运行时注册表项不会被删除,是否有任何其他可靠的方法来检查运行时是否已安装以及安装了哪个版本?

WiX 3 currently doesn't handle this natively. WiX 3 目前不能原生处理这个问题。 It is being worked on for WiX v4 ( GitHub issue ).它正在为 WiX v4( GitHub 问题)开发。 Reading the issue led me to these tools as a current workaround.阅读该问题后,我将这些工具作为当前的解决方法。

https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x86 https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x86
https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x64 https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x64

You can use the files inside of these packages to check for a runtime.您可以使用这些包中的文件来检查运行时。 Either by running NetCoreCheck.exe directly or using the custom action DLL provided.通过直接运行NetCoreCheck.exe或使用提供的自定义操作 DLL。

NetCoreCheck.exe -h to see help. NetCoreCheck.exe -h查看帮助。 But you'll want something like this:但是你会想要这样的东西:

netcorecheck --runtimename Microsoft.NetCore.App --runtimeversion 6.0.0

I don't know how to use the custom action dll but I do see it has two DLL exports.我不知道如何使用自定义操作 dll,但我确实看到它有两个 DLL 导出。

 ordinal hint RVA      name

          1    0 00001500 CheckNETRuntime
          2    1 00002260 get_hostfxr_path

You may use the Custom Action DLL mentioned in Hank's answer if you want to integrate this in your WiX project.如果您想将其集成到您的 WiX 项目中,您可以使用 Hank 的回答中提到的自定义操作 DLL。

You can use the NuGet package to obtain the dll.您可以使用NuGet package 获取 dll。 Unfortunately there seems to be no documentation in existence for this DLL, so I used the source code to figure out how this works.不幸的是,似乎没有关于这个 DLL 的文档,所以我使用源代码来弄清楚它是如何工作的。

First you need to define a few properties that are used as input parameters for the .NET runtime check, and for the result of the check.首先,您需要定义一些属性,用作 .NET 运行时检查和检查结果的输入参数。

<Property Id="CheckNETRuntime_Framework" Value="Microsoft.AspNetCore.App" />
<Property Id="CheckNETRuntime_Version" Value="6.0.0" />
<Property Id="CheckNETRuntime_Result" />

CheckNETRuntime_Framework is the framework to search for. CheckNETRuntime_Framework是要搜索的框架。 There are currently 3 options:目前有3个选项:

  • Microsoft.NETCore.App Microsoft.NETCore.App
  • Microsoft.AspNetCore.App Microsoft.AspNetCore.App
  • Microsoft.WindowsDesktop.App Microsoft.WindowsDesktop.App

CheckNETRuntime_Version is the version of .NET to look for. CheckNETRuntime_Version是要查找的 .NET 的版本。 The result will be stored in CheckNETRuntime_Result .结果将存储在CheckNETRuntime_Result中。 A value of 0 indicates the runtime was found, any other value indicates it was not found.0表示已找到运行时,任何其他值表示未找到。

To run the custom action, do this:要运行自定义操作,请执行以下操作:

<Binary Id="CustomActions" SourceFile="NetCoreCheckCA.dll" /> <!-- This should be the path to the dll -->

<CustomAction Id="CheckRuntime" Return="ignore" BinaryKey="CustomActions" DllEntry="CheckNETRuntime" />

<InstallExecuteSequence>
    <Custom Action="CheckRuntime" Before="LaunchConditions"  />
</InstallExecuteSequence>
<InstallUISequence>
    <Custom Action="CheckRuntime" Before="LaunchConditions"  />
</InstallUISequence>

Note: you need to add Return="ignore" if you do not want the installer to fail when the runtime was not found (as the return value if not 0, which indicates a failure).注意:如果不希望安装程序在找不到运行时时失败,则需要添加Return="ignore" (如果不为 0,则作为返回值,表示失败)。

The CheckNETRuntime_Result property can be used elsewhere in your setup, for example you could use it in a condition: CheckNETRuntime_Result属性可以在您的设置中的其他地方使用,例如,您可以在以下条件下使用它:

<Condition Message=".NET 6 runtime is not installed">
    <![CDATA[CheckNETRuntime_Result=0]]>
</Condition>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 .NET 框架应用程序以编程方式检查安装在我的机器上的 .NET Core Runtime 版本? - How to programmatically check the .NET Core Runtime version installed on my machine from a .NET Framework app? 如何确定是否从CentOs 7安装了.NET Core Runtime - How to determine if .NET Core Runtime is installed from CentOs 7 如何找到 .NET Core Desktop Runtime 安装在 windows 机器上 - How to find the .NET Core Desktop Runtime is installed in a windows machine 如何检查 IIS 和 .NET Core Hosting Bundle 是否安装在 wix 工具集中? - How to check are IIS and .NET Core Hosting Bundle installed in wix toolset? 如果 .NET Core 应用程序通过 dotnet cli 启动,如何检查运行时 - How to check in runtime if .NET Core app is started via dotnet cli .NET Core应用程序是否需要在目标计算机上安装.NET运行时? - Do .NET Core apps require the .NET runtime installed on the target machine? 如何在 .net 核心中轻松检查提交查询的用户是否属于他们? - How can I easily check whether the user submitting a query belongs to them or not in .net core? 检查 Inno Setup 中是否安装了 .NET 5.0 - Check if .NET 5.0 is installed in Inno Setup 如何检查访问令牌是否有效? - How to check whether the access token is valid or not? 如何判断.NET Core是否安装 - How to determine if .NET Core is installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM