[英]Download private nuget packages from private nuget server
我的 .NET 6 项目的.csproj
有这个:
<ItemGroup>
<!-- public -->
<PackageReference Include="Autofac" Version="1.0.0" />
<PackageReference Include="FluentValidation" Version="1.0.0" />
<PackageReference Include="Serilog" Version="1.0.0" />
<!-- private -->
<PackageReference Include="Company.Package1" Version="1.0.0" />
<PackageReference Include="Company.Package2" Version="1.0.0" />
</ItemGroup>
“公共”包是从 nuget 服务器下载的,“私有”包是从我们的私有 nuget 服务器下载的。
但我不希望我们的私有包的详细信息泄露给 nuget。
我该如何执行?
这是一个新的 nuget 功能,称为“包源映射” 。
在解决方案根目录的nuget.config
中,我有这个:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
<add key="private" value="https://www.example.com/v3/index.json" />
</packageSources>
<packageSourceMapping>
<!-- public -->
<packageSource key="nuget">
<package pattern="*" />
</packageSource>
<!-- private -->
<packageSource key="private">
<package pattern="Company.*" />
</packageSource>
</packageSourceMapping>
</configuration>
运行dotnet nuget locals --clear all
以清除缓存,否则新策略将不适用于已在缓存中的包。 然后运行dotnet restore
。
此功能的另一个用例是确保从特定的包存储库下载一个包,以防它存在于多个存储库中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.