使用 System.Deployment 不存在?

问题描述 投票:0回答:2

我尝试寻找

System.Deployment
在我的 Blazor 服务器应用程序中使用此代码:

但是 System.Deployment 不在我的项目系统中,也不在可用的项目参考中,我在 Google 上查找可下载的 .dll 链接,而 Microsoft 似乎没有。我缺少什么?我已经尝试过

using System.Deployment
using System.Deployment.Application
,但都不起作用。

c# asp.net version-control blazor libraries
2个回答
4
投票

只需将“FrameworkExtract.System.Deployment”nuget 引用到您的项目即可。

祝你有美好的一天,


0
投票

如果您不想依赖外部软件包,则可以依靠注册表来跟踪卸载时的应用程序版本。

基本上当您转到“添加/删除”并检查版本时。

RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Uninstall\");

if (registryKey != null) return;

var programKeys = registryKey.GetSubKeyNames();

foreach (var keyName in programKeys)
{
    RegistryKey? programKey = registryKey.OpenSubKey(keyName);

    object? displayName = programKey?.GetValue("DisplayName");
    object? version = programKey?.GetValue("DisplayVersion");

    if (displayName != null && $"{displayName}" == <YourApplicationName>)
        VersionText.Text = $"Version: {version}";
        
    programKey?.Close();
}

registryKey.Close();

我会使用上面的答案,只需通过 nuget 包安装缺少的功能,但我想我会将这个解决方案留在这里,供任何想要更多地控制如何获取版本信息的人使用。

© www.soinside.com 2019 - 2024. All rights reserved.