我正在制作一个 dotnet 工具,它将在我们的生产服务器中用作命令行应用程序。所以我按照 tutorial 的建议从本地源源安装它。
dotnet tool install --tool-path /bin --add-source path/to/nupkg coolcompany.cooltool
上面的教程也有这个警告:
你给你的包起了一个唯一的名字,以确保它只能在 ./nupkg 目录中找到,而不是在 Nuget.org 网站上。
似乎在名称冲突的情况下,
dotnet tool install
从 nuget.org 中选择包而不是本地包。
现在,
coolcompany.cooltool
在 nuget.org 上实际上并不存在。但是后来有人可能会添加它,无论是无意还是无意,我们都会在生产中运行意想不到的代码,甚至都不知道。
有没有办法强制将本地资源用于特定包?如果不是,这不是安全问题吗?还是我在这里遗漏了一些明显的东西?
虽然我还没有尝试过,但我 expect 使用带有
--configfile
的 dotnet tool install
标志会起作用。然后,您将指定一个配置文件,only 包括您的本地源:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- Don't use any default sources -->
<clear />
<!-- Just use the local one -->
<add key="LocalRepo" value="path/to/nupkg" />
</packageSources>
</configuration>
使用包源映射
将此添加到
nuget.config
<packageSources>
<add key="MySourceName" value="path/to/nupkgfolder" />
</packageSources>
<packageSourceMapping>
<!-- key value for <packageSource> should match key values from <packageSources> element -->
<packageSource key="nuget.org">
<package pattern="*" />
</packageSource>
<packageSource key="MySourceName">
<package pattern="coolcompany.cooltool" />
</packageSource>
</packageSourceMapping>
现在,如果包名称匹配
coolcompany.cooltool
,它将始终从 MySourceName
nuget 提要中获取,但仍然允许从 nuget.org 中获取所有其他包。