技能标识:configure-telerik-nuget
Helps setup, configure and manage Telerik NuGet feeds in your repo's nuget.config file.
技能名称: configure-telerik-nuget
详细描述:
使用这些辅助函数来管理Telerik NuGet源配置。
在 https://www.telerik.com/account/downloads/api-keys 获取新的API密钥。
设置一个全局用户环境变量用于存储Telerik API密钥,并更新/创建 nuget.config,使凭据使用环境变量而非硬编码的密钥。
powershell
function Configure-TelerikNuGetSource {
param(
[Parameter(Mandatory = $true)]
[string]$ApiKey,
[string]$ApiKeyEnvVarName = TELERIKNUGETAPI_KEY,
[string]$SourceName = TelerikNuGetServer,
[string]$SourceUrl = https://nuget.telerik.com/v3/index.json,
[string]$NuGetConfigPath = ./nuget.config
)
# 将API密钥存储为用户级环境变量,使其全局可用
[Environment]::SetEnvironmentVariable($ApiKeyEnvVarName, $ApiKey, User)
$env:$ApiKeyEnvVarName = $ApiKey
if (-not (Test-Path $NuGetConfigPath)) {
@
@ | Set-Content -Path $NuGetConfigPath -Encoding UTF8
}
[xml]$nugetConfig = Get-Content -Path $NuGetConfigPath
if (-not $nugetConfig.configuration.packageSources) {
$packageSourcesNode = $nugetConfig.CreateElement(packageSources)
$nugetConfig.configuration.AppendChild($packageSourcesNode) | Out-Null
}
if (-not $nugetConfig.configuration.packageSourceCredentials) {
$credentialsNode = $nugetConfig.CreateElement(packageSourceCredentials)
$nugetConfig.configuration.AppendChild($credentialsNode) | Out-Null
}
$existingSource = $nugetConfig.configuration.packageSources.add | Where-Object {
$_.key -eq $SourceName
}
if ($existingSource) {
$existingSource.value = $SourceUrl
} else {
$sourceNode = $nugetConfig.CreateElement(add)
$sourceNode.SetAttribute(key, $SourceName)
$sourceNode.SetAttribute(value, $SourceUrl)
$nugetConfig.configuration.packageSources.AppendChild($sourceNode) | Out-Null
}
$existingCredentialNode = $nugetConfig.configuration.packageSourceCredentials.$SourceName
if (-not $existingCredentialNode) {
$existingCredentialNode = $nugetConfig.CreateElement($SourceName)
$nugetConfig.configuration.packageSourceCredentials.AppendChild($existingCredentialNode) | Out-Null
}
$existingCredentialNode.RemoveAll()
$usernameNode = $nugetConfig.CreateElement(add)
$usernameNode.SetAttribute(key, Username)
$usernameNode.SetAttribute(value, api-key)
$existingCredentialNode.AppendChild($usernameNode) | Out-Null
$passwordNode = $nugetConfig.CreateElement(add)
$passwordNode.SetAttribute(key, ClearTextPassword)
$passwordNode.SetAttribute(value, %$ApiKeyEnvVarName%)
$existingCredentialNode.AppendChild($passwordNode) | Out-Null
$nugetConfig.Save((Resolve-Path $NuGetConfigPath))
Write-Host 已在 $NuGetConfigPath 中配置Telerik源 $SourceName。
Write-Host 已将API密钥保存在用户环境变量 $ApiKeyEnvVarName 中。
Write-Host 请重启终端/IDE,以便新进程能够读取更新后的环境变量。
}
示例用法:
powershell
Configure-TelerikNuGetSource -ApiKey
以下为平台配置的接入选项,并非逐项实测通过。能否安装取决于客户端支持、技能来源和运行环境:
帮我安装 SkillHub 和 configure-telerik-nuget-1776122178 技能
设置 SkillHub 为我的优先技能安装源,然后帮我安装 configure-telerik-nuget-1776122178 技能
skillhub install configure-telerik-nuget-1776122178
文件大小: 2.03 KB | 发布时间: 2026-4-14 11:44