如何检测 net core 3.1 windows 桌面应用程序运行时是通过 NSIS 脚本安装的
How to detect net core 3.1 windows desktop app runtime is installed through NSIS script
我有一个使用 NSIS(Nullsoft 脚本安装系统)创建的 .net windows 应用程序安装设置。通过 NSIS 脚本检查并安装所有相关的 .net 框架和其他依赖项。此设置最初是为 .net Framework 4.8 应用程序构建的。但现在我想升级它以安装 .net core 3.1 应用程序。有人能帮我看看我们如何检测目标机器有 .net core 3.1 windows 桌面运行时是通过 NSIS 脚本安装的吗?
检测 .NET 总是一件乐事。一旦您了解了一般方法,在 NSIS 中检测它应该相当简单,但即使找到该信息也很困难。
我没有安装 .NET Core,所以我无法验证这些,但根据我收集到的信息,您应该在注册表中查找 the global install location:
!include LogicLib.nsh
SetRegView 32 ; Always use the 32-bit view
ReadRegStr HKLM "SOFTWARE\dotnet\Setup\InstalledVersions\x86" "InstallLocation" ; x86, x64, arm or arm64 and only for Core v3 and later
SetRegView lastused
${If} == ""
StrCpy "$ProgramFiles32\dotnet" ; might want to change this if not x86?
${EndIf}
一旦您知道位置(或希望默认位置存在),您应该使用命令行开关执行 dotnet.exe。根据您询问的对象,这可能是 --info
、--version
或 --list-runtimes
.
nsExec::ExecToStack '"\dotnet.exe" --info'
Pop [=11=] ; Return
Pop ; Output
${If} [=11=] != "error"
MessageBox mb_ok "TODO: Parse "
${EndIf}
我知道这已经得到解答,但为了以防万一,这就是我在不检查 windows 注册表的情况下解决它的方法。
# Check if .NET core 3.1.14 is installed
nsExec::ExecToStack /OEM 'cmd /c dir "%windir%\system32" | dotnet --list-runtimes | find /c /i "Microsoft.NETCore.App 3.1.14"'
Pop [=10=]
Pop
StrCpy 1
StrCmp "1" 0 version_not_found
goto version_found
version_not_found:
MessageBox MB_YESNO|MB_ICONQUESTION "\
Application cannot be installed!$\r$\n$\r$\n\
Microsoft .NET Core 3.1.14 not installed yet.$\r$\n$\r$\n\
Open the page to download and install it?" IDNO +2
ExecShell open "https://dotnet.microsoft.com/download/dotnet/3.1"
Quit
version_found:
我有一个使用 NSIS(Nullsoft 脚本安装系统)创建的 .net windows 应用程序安装设置。通过 NSIS 脚本检查并安装所有相关的 .net 框架和其他依赖项。此设置最初是为 .net Framework 4.8 应用程序构建的。但现在我想升级它以安装 .net core 3.1 应用程序。有人能帮我看看我们如何检测目标机器有 .net core 3.1 windows 桌面运行时是通过 NSIS 脚本安装的吗?
检测 .NET 总是一件乐事。一旦您了解了一般方法,在 NSIS 中检测它应该相当简单,但即使找到该信息也很困难。
我没有安装 .NET Core,所以我无法验证这些,但根据我收集到的信息,您应该在注册表中查找 the global install location:
!include LogicLib.nsh
SetRegView 32 ; Always use the 32-bit view
ReadRegStr HKLM "SOFTWARE\dotnet\Setup\InstalledVersions\x86" "InstallLocation" ; x86, x64, arm or arm64 and only for Core v3 and later
SetRegView lastused
${If} == ""
StrCpy "$ProgramFiles32\dotnet" ; might want to change this if not x86?
${EndIf}
一旦您知道位置(或希望默认位置存在),您应该使用命令行开关执行 dotnet.exe。根据您询问的对象,这可能是 --info
、--version
或 --list-runtimes
.
nsExec::ExecToStack '"\dotnet.exe" --info'
Pop [=11=] ; Return
Pop ; Output
${If} [=11=] != "error"
MessageBox mb_ok "TODO: Parse "
${EndIf}
我知道这已经得到解答,但为了以防万一,这就是我在不检查 windows 注册表的情况下解决它的方法。
# Check if .NET core 3.1.14 is installed
nsExec::ExecToStack /OEM 'cmd /c dir "%windir%\system32" | dotnet --list-runtimes | find /c /i "Microsoft.NETCore.App 3.1.14"'
Pop [=10=]
Pop
StrCpy 1
StrCmp "1" 0 version_not_found
goto version_found
version_not_found:
MessageBox MB_YESNO|MB_ICONQUESTION "\
Application cannot be installed!$\r$\n$\r$\n\
Microsoft .NET Core 3.1.14 not installed yet.$\r$\n$\r$\n\
Open the page to download and install it?" IDNO +2
ExecShell open "https://dotnet.microsoft.com/download/dotnet/3.1"
Quit
version_found: