有人知道如何将自定义包源添加到 Visual Studio Code 吗?
例如我想添加 https://www.myget.org/F/aspnet-contrib/api/v3/index.json 作为包源并通过 project.json 驱动这些包。
在项目中添加一个
nuget.config
为项目解决。添加到根是可以的。配置可能如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="MyGet" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
</packageSources>
</configuration>
另一个对我有用并且作为我的 CI/CD 管道的一部分实际需要的选项是使用
dotnet nuget add source <repo-url> --name <repo-name>
只需在调用
dotnet restore
或dotnet build
之前调用它
参考: https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source
注意 - 如果您的自定义包源受密码保护,那么凭据也应该是配置文件的一部分。
<packageSourceCredentials>
<MyGet> <!--package src name-->
<add key="Username" value="something" />
<add key="ClearTextPassword" value="thepassword" />
</MyGet>
</packageSourceCredentials>
对于任何想知道为什么凭据必须以明文形式存在的人来说(这首先违背了拥有凭据的全部目的,因为此配置文件也将进入源代码管理)。
您可以添加一个 NuGet.config 文件并在其中指定包源。一些参考文档:https://learn.microsoft.com/en-us/nuget/schema/nuget-config-file