.net - 如何可靠地以编程方式检查是否安装了 net5 AspnetCore Hosting Bundle?
问题描述
尝试使用 powershell 命令:
dotnet --list-runtimes
dotnet --list-sdks
但是,如果安装了 net5,无论是否安装了 Windows Hosting Bundle,两者都会输出相同的行。
试图在注册表中找到 AspnetCoreModuleV2,找到了它......但在卸载托管包并重新启动 PC 后也找到了它。
在微软网站上搜索了很多。
有没有人有办法解决吗 ?
解决方案
终于找到了。
首先检查“AspNetCoreModuleV2”是否与 ServerManager 一起列出:
using ServerManager serverManager = new ();
var config = serverManager.GetApplicationHostConfiguration();
var globalModulesSection = config.GetSection("system.webServer/globalModules");
var globalModulesCollection = globalModulesSection.GetCollection();
return globalModulesCollection.Any(m => m.GetAttributeValue("name")?.Equals("AspNetCoreModuleV2") == true);
然后,使用命令检查 dotnet 所需版本
dotnet --list-runtimes