配置winget本地源及清单更新

winget-source本地配置

官方的winget source add 目前(2023年4月29日)似乎仅支持https ,[官方文档](使用 winget 工具安装和管理应用程序 | Microsoft Learn)中指出-a参数支持URL或 UNC,也许是未来支持完善吧。

准备

官方的公开库winget-pkgs中的manifest文件

使用官方工具winget-create进行对自己的软件集进行生成

wingetcreate使用

官方文档

github文档

  1. winget中安装
winget install wingetcreate
  1. wingetcreate帮助
> wingetcreate --help
Windows 程序包管理器清单创建程序 v1.2.5.0

Copyright (c) Microsoft Corporation. All rights reserved.

清单创建命令行实用工具会生成用于将应用提交到 Windows 程序包管理器存储库的清单。

  new         启动一系列问题以帮助生成新清单
  update      更新现有清单的字段
  submit      直接将有效清单提交到 Windows 程序包管理器存储库
  settings    打开设置
  token       修改 GitHub 身份验证令牌缓存
  cache       管理存储在缓存中的已下载安装程序

可在以下位置找到更多帮助: https://aka.ms/winget-create
隐私声明: https://aka.ms/privacy

  1. wingetcreate创建清单

创建清单命令:

wingetcreate new https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe

然后一直选择默认值就可以。当然在最后选项中你的程序也可以添加到微软的库中。

正在下载和分析: https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe...

此工具将引导你完成一系列问题,以帮助你创建程序包清单。

有关每个字段限制的信息,请访问 https://aka.ms/winget-manifest-schema

按 ENTER 提交每个问题的值,包括接受 (默认) 值。

请为以下字段输入值:
程序包唯一标识符 |例如 Microsoft.VisualStudio|
 PackageIdentifier 值为: ZhikeOnline.DocBoxReaderInstaller
程序包版本 |例如 1.2.3.4|
 PackageVersion 值为: 2.12.36
程序包元数据默认区域设置 |例如 en-US|
 DefaultLocale 值为: en-US

安装程序所需的其他元数据来自 https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe
无提示安装程序开关
 Silent 值为: /s
无提示及进度安装程序开关
 SilentWithProgress 值为: /s
安装程序目标体系结构
 Architecture 值为: X86
发布者名 |例如 Microsoft|
 Publisher 值为: Zhike Online
程序包名 |例如 Visual Studio|
 PackageName 值为: DocBox Reader Installer
程序包许可证 |e.g. MIT License|
 License 值为: e.g. MIT License
简短程序包说明
 ShortDescription 值为: 稻壳阅读器 安装程序

 是否要修改可选的默认区域设置字段?: No
 是否要修改可选安装程序字段?: No

正在生成清单预览...
版本清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.4.0.schema.json

PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.4.0

安装程序清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.4.0.schema.json

PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
Installers:
- Architecture: x86
  InstallerType: exe
  InstallerUrl: https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe
  InstallerSha256: D42322ACAFEDB3BB68365FEC48848858ADD25E7D0627ACD0A8180F78A1ABEB2A
  InstallerSwitches:
    Silent: /s
    SilentWithProgress: /s
ManifestType: installer
ManifestVersion: 1.4.0

默认区域设置清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.4.0.schema.json

PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
PackageLocale: en-US
Publisher: Zhike Online
PackageName: DocBox Reader Installer
License: e.g. MIT License
Copyright: Copyright 2016-2022 Beijing Zhike Online
ShortDescription: 稻壳阅读器 安装程序
ManifestType: defaultLocale
ManifestVersion: 1.4.0

清单验证成功: True

是否要对此清单进行更改?: No

清单已保存到 D:\manifests\z\ZhikeOnline\DocBoxReaderInstaller\2.12.36

 是否要将清单提交到 Windows 程序包管理器存储库?: No
> wingetcreate new --help
Windows 程序包管理器清单创建程序 v1.2.5.0

Copyright (c) Microsoft Corporation. All rights reserved.

清单创建命令行实用工具会生成用于将应用提交到 Windows 程序包管理器存储库的清单。

USAGE:
从头开始:
  wingetcreate.exe new
下载安装程序并提取元数据:
  wingetcreate.exe new <InstallerUrl1> "<InstallerUrl2>, .."
在本地保存并提交拉取请求:
  wingetcreate.exe new --out <OutputDirectory> --token <GitHubPersonalAccessToken> <InstallerUrl1>
  "<InstallerUrl2>, ..."

  -o, --out        将新创建的清单保存到本地的输出目录
  -t, --token      GitHub 个人访问令牌,用于直接提交到 Windows 程序包管理器库。如果未提供任何令牌,工具将提示 GitHub 登 录凭据。
  urls (pos. 0)    安装程序 URL(用于提取用于生成清单的相关元数据)

可在以下位置找到更多帮助: https://aka.ms/winget-create
隐私声明: https://aka.ms/privacy

wingetcreate详细使用

wingetcreate修改校验的源

wingetcreate进行update时会与校验的源进行比较,默认为微软的GitHub开放源。

wingetcreate Settings
{
  "$schema": "https://aka.ms/wingetcreate-settings.schema.0.1.json",
  "Telemetry": {
    "disable": false
  },
  "WindowsPackageManagerRepository": {
    "owner": "microsoft",
    "name": "winget-pkgs"
  }
}

可以修改owner值和name的值,具体以自己的GitHub库为准,如https://github.com/microsoft/winget-create,owner为microsoft,name为winget-create.

更新清单

文档

wingetcreate.exe update --urls

PackageIdentifier 可以使用winget search 查询,例如:

>winget search docbox -s rewinged-local
名称                    ID                                版本
-----------------------------------------------------------------
DocBox Reader Installer ZhikeOnline.DocBoxReaderInstaller 2.12.36
wingetcreate update -u https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe -v testversion ZhikeOnline.DocBoxReaderInstaller

本地配置

使用工具rewinged进行本地源的配置。因winget仅支持https的源所有首先进行证书生成然后启动https服务。

  1. 使用powershell命令行进行证书生成

    # Because we are adding a certificate to the local machine store, this has to be run in an elevated PowerShell session
    
    $SelfSignedCertificateParameters = @{
        'DnsName'         = 'localhost'
        'NotAfter'        = (Get-Date).AddYears(1)
        'FriendlyName'    = 'rewinged HTTPS'
        'KeyAlgorithm'    = 'RSA'
        'KeyExportPolicy' = 'Exportable'
    }
    $cert = New-SelfSignedCertificate @SelfSignedCertificateParameters
    
    $RSAPrivateKey    = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)
    $PrivateKeyBytes  = $RSAPrivateKey.Key.Export([System.Security.Cryptography.CngKeyBlobFormat]::Pkcs8PrivateBlob)
    $PrivateKeyBase64 = [System.Convert]::ToBase64String($PrivateKeyBytes, [System.Base64FormattingOptions]::InsertLineBreaks)
    
    $CertificateBase64 = [System.Convert]::ToBase64String($cert.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks)
    
    Set-Content -Path private.key -Encoding Ascii -Value @"
    -----BEGIN RSA PRIVATE KEY-----`r`n${PrivateKeyBase64}`r`n-----END RSA PRIVATE KEY-----
    "@
    
    Set-Content -Path cert.pem -Encoding Ascii -Value @"
    -----BEGIN CERTIFICATE-----`r`n${CertificateBase64}`r`n-----END CERTIFICATE-----
    "@
    
    $store = [System.Security.Cryptography.X509Certificates.X509Store]::new('Root', 'LocalMachine')
    $store.Open('ReadWrite')
    $store.Add($cert)
    $store.Close()
    
    Remove-Item $cert.PSPath
    
  2. 开启https服务并且指定manifest路径

rewinged.exe  -https -listen localhost:8443 -manifestPath "D:\test"
Searching for manifests...
Searching directory: D:\test/manifests
Searching directory: D:\test/manifests/z
Searching directory: D:\test/manifests/z/ZhikeOnline
Searching directory: D:\test/manifests/z/ZhikeOnline/DocBoxReaderInstaller
Searching directory: D:\test/manifests/z/ZhikeOnline/DocBoxReaderInstaller/2.12.36
  1. 在winget中添加源
winget source add -n rewinged-local -a https://localhost:8443 -t "Microsoft.Rest"
  1. 安装本地源中的信息
winget install [software] -s rewinged-local

本地脚本文件(可忽略)

复制以下,并且另存为后缀名为.ps1的文件。使用此文件 后面跟manifest的路径即可。

# Because we are adding a certificate to the local machine store, this has to be run in an elevated PowerShell session

$SelfSignedCertificateParameters = @{
    'DnsName'         = 'localhost'
    'NotAfter'        = (Get-Date).AddYears(1)
    'FriendlyName'    = 'rewinged HTTPS'
    'KeyAlgorithm'    = 'RSA'
    'KeyExportPolicy' = 'Exportable'
}
$cert = New-SelfSignedCertificate @SelfSignedCertificateParameters

$RSAPrivateKey    = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)
$PrivateKeyBytes  = $RSAPrivateKey.Key.Export([System.Security.Cryptography.CngKeyBlobFormat]::Pkcs8PrivateBlob)
$PrivateKeyBase64 = [System.Convert]::ToBase64String($PrivateKeyBytes, [System.Base64FormattingOptions]::InsertLineBreaks)

$CertificateBase64 = [System.Convert]::ToBase64String($cert.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks)

Set-Content -Path private.key -Encoding Ascii -Value @"
-----BEGIN RSA PRIVATE KEY-----`r`n${PrivateKeyBase64}`r`n-----END RSA PRIVATE KEY-----
"@

Set-Content -Path cert.pem -Encoding Ascii -Value @"
-----BEGIN CERTIFICATE-----`r`n${CertificateBase64}`r`n-----END CERTIFICATE-----
"@

$store = [System.Security.Cryptography.X509Certificates.X509Store]::new('Root', 'LocalMachine')
$store.Open('ReadWrite')
$store.Add($cert)
$store.Close()

Remove-Item $cert.PSPath

# start https server
Write-Host "manifestPath is $args[1]"

Start-Job { rewinged.exe  -https -listen localhost:8443 -manifestPath $args[1] }
Write-Host 'Ping command is running in the background...'
sleep 10
# add winget-source 
winget source add -n rewinged-local -a https://localhost:8443 -t "Microsoft.Rest"

其他可用的在线源

https://mirrors.ustc.edu.cn/winget-source

  • 查看源列表
winget source list
  • 添加源
winget source add ustcget  https://mirrors.ustc.edu.cn/winget-source
  • 删除源
winget source remove ustcget
  • 源重置
winget source restet --forece

注意

winget install 在搜索时会搜索所有的源,所以源过多会导致 搜索时间过长,并且需要参数-s指定源。所以可以先将winget源删除然后添加源,当前源列表中数量保证最多3个。

此次过程记录

尝试过的winget 源类型http、smb、ftp、windows文件共享路径、https(基于iis自建https,浏览器正常、curl 报错。放弃了)、官方的需要amzure数据库

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值