更新 2023-04-17

更新 2023-04-17

我使用 安装了 Zotero winget install Zotero.Zotero,它在 中安装得很好C:\Program Files (x86)\Zotero。但是当我运行 时winget upgrade,它显示两个 Zotero 版本,如下所示:

Name   Id            Version Available Source
---------------------------------------------
Zotero Zotero.Zotero 6.0.10  6.0.13    winget
Zotero Zotero.Zotero 6.0.9   6.0.13    winget
2 upgrades available.

我已确认当前安装的 Zotero 版本为。由于我之前安装过带和不带 winget 的 Zotero,我认为这些条目可能反映了这些安装。因此,我想卸载/删除这些条目,但不删除当前安装在 的6.0.13版本。6.0.13C:\Program Files (x86)\Zotero

我的问题是,如何让 winget 显示这两个版本的安装目录,以便我可以手动删除它们?

答案1

更新 2023-04-17

似乎 winget 版本v1.5.1081-preview及以上(包括PR3128),通过运行 包含有关默认目录的信息winget --info

winget --info 的输出

还有一个未解决的问题,即如何列出每个应用程序的目录(问题 2298)。

至于 Zotero 本身,我找不到 ID 为 的包Zotero.Zotero,但找到了数字学者.Zotero。这表明使用了默认安装程序,因此默认路径与应用程序的路径相同(从他们的文档中搜索似乎如此C:\Program Files (x86)\Zotero,但我没有看到任何明确的说明)。

注意:您的附加版本可能Zotero.Zotero不存在于磁盘上;但仅存在于 WinGet 的数据库中(例如,如果已安装,则路径会在 WinGet 不知情的情况下被删除)。有关如何查询该数据库的信息,请参阅“查找元数据失败尝试”。


原始答案

具体位置取决于包,据我所知,目前无法获取所有已安装的 winget 包的信息。

对于那些没有安装程序而只是下载的文件的应用程序,它们被放在以下文件夹下:%localappdata%\microsoft\winget\packages

当存在具有可移植命令别名的 exe 时(即避免必须将每个 exe 的路径添加到 PATH 变量中),将创建一个符号链接。该符号链接保存在 中%localappdata%\Microsoft\WinGet\Links\

注意:某些应用的清单可能会指定默认安装目录。该目录在其InstallLocation属性中给出(请参阅架构)。


寻找元数据的尝试失败

我想知道您是否可以找到 WinGet 存储已安装包的元数据的路径...我找不到 - 但下面注明了以帮助其他人更深入地探索(我的结论是 WinGet 不记得它在哪里安装了东西,只记得它安装了它们/安装了什么版本;其他一切都留给默认安装程序)。

winget settings您可以通过运行然后查看settings.json打开的文件的路径来获取其设置文件的路径。对我来说这是:C:\Users\myUsername\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json

通过在该目录中寻找,我找到了一个 SQLLite DB C:\Users\myUsername\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Microsoft.Winget.Source_8wekyb3d8bbwe\installed.db:。

我们可以使用以下 PowerShell 查询此文件/数据库:

# Load the System.Data.SQLite.dll assembly.  This is likely already somewhere on your machine, but if you can't find it, see https://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
Add-Type -Path 'C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\PrivateAssemblies\System.Data.SQLite.dll'

# Update this path with your install.db path
$installDbPath = 'C:\Users\myUsername\AppData\Local\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Microsoft.Winget.Source_8wekyb3d8bbwe\installed.db'

# create a connection to this db
$con = [System.Data.SQLite.SQLiteConnection]::new("Data Source=$installDbPath")
$con.Open()

# Create and execute a query to list all tables (thanks to https://stackoverflow.com/a/14623907/361842 for the SQL)
$command = $con.CreateCommand()
$command.CommandText = @"
SELECT name FROM sqlite_master
  WHERE type IN ('table','view') AND name NOT LIKE 'sqlite_%'
UNION ALL
SELECT name FROM sqlite_temp_master
  WHERE type IN ('table','view')
ORDER BY 1;
"@
$data = [System.Data.DataSet]::new()
$adapter = [System.Data.SQLite.SQLiteDataAdapter]::new($command)
$adapter.Fill($data) | Out-Null
$data.Tables.Rows

# channels
# commands
# commands_map
# ids
# manifest
# manifest_metadata
# metadata
# monikers
# names
# norm_names
# norm_names_map
# norm_publishers
# norm_publishers_map
# pathparts
# pfns
# pfns_map
# productcodes
# productcodes_map
# tags
# tags_map
# versions

# Now repeat over the IDs table to give the IDs of all installed packages
$command.CommandText = "SELECT * FROM ids"
$data = [System.Data.DataSet]::new() # reset this to avoid appending
$adapter.Fill($data) #note: adapter has a reference to $command, so by updating the command text the adapter's command is automatically updated
$data.Tables.Rows | ft -AutoSize

# sadly I hunted through all the other tables but couldn't find any hint of an installation directory being stored here

答案2

我找不到任何与winget命令行选项匹配的内容。

但部分解决方法是使用在哪里命令按可执行文件名称进行搜索。

喜欢where zotero

答案3

对于仍在寻找答案的人,这对我有用:

winget list -q $id | Out-Null
if ($?) {  echo "$id installed" }

答案4

我已经安装了winget install hurl

为了找到它的安装位置,我做了以下操作

  1. winget uninstall hurl
  2. 已经看到有关更改的警告(可能取决于所使用的 CLI)
  3. 我看到卸载弹出窗口,其中可以看到路径

这是一个卸载弹出窗口: 卸载弹出窗口

相关内容