发布带有可执行文件的 nuget 包,nuget.org

Publish nuget package with executable inside, nuget.org

我是个好人,想为nuget.org

做贡献

我有一个任务无法使用 .NET 解决(将 .pdf 转换为 .html,但这不是要点,它可能是其他任何东西)但是很容易处理使用 Python。所以我写了一个 .py 脚本,把它变成单文件可执行文件,在 .NET 中写了一些包装,然后它就可以工作了。

包装器基本上只是卸载硬盘上某处的可执行文件,通过命令行参数调用它并获得响应。

Now how do I go about publishing this nuget with executable inside?

这是常见的做法。 NuGet 包允许各种工件,如源文件、图像、XML 文件、MSBuild 构建脚本、工具可执行文件、PowerShell 脚本以及任何类型的二进制文件,包括库和可执行文件。

Is this even allowed?

NuGet 是一个包管理器。至于包本身,微软的description并不清楚有用的代码内容是什么。

An essential tool for any modern development platform is a mechanism through which developers can create, share, and consume useful code. Often such code is bundled into "packages" that contain compiled code (as DLLs) along with other content needed in the projects that consume these packages.

许多主流 NuGet 包都包含可执行文件,例如 CefSharp.Common that contains a whole Chromium browser or even Microsoft's own CPPRestSDK,其中包含用于 OpenSSL、Boost 或 Brotli 的多个可执行文件,以及用于复制文件等的 PowerShell 脚本。顺便说一句,它是在 MSDN 上构建本机 NuGet 包的主要示例。

Is the idea so bad that I scrap the whole thing?

没有。即使从一开始就没有打算打包可执行文件,它已经成为一种常见的做法。使用 NuGet 的每个人都应该意识到他们正在使用库和其他可能有害的工件。您如何确定您使用的 DLL 也是安全的?

Do I somehow explicitly warn users that the library contains an executable which would get copied to their hard-drive?

如果你看上面的包,除了是原生包外,没有任何关于内容的通知。您必须检查包或获得相应的项目站点才能自己找到答案。此外,包含不需要的工件的包可能会被一系列其他包依赖项所掩盖。

您当然可以通过 NuSpec 文件中的 description 标签提供对您的包的全面描述。此描述将显示在 nuget.org 以及大多数客户端中。

Provide a link (where?) to the code of the .py script?

您可以通过 projectUrl 标签向您的项目站点提供 link,您可以在其中详细介绍并提供您的来源。另一种选择是将其作为内容文件包括在内以供参考,但有人查看它的机会很小,并且不能证明您的可执行文件是从该脚本构建的。

And a validation of sorts (how?) that this code is what actually inside the executable?

这一切都归结为一个问题,您如何信任包裹? 你不能

软件包可能会带来安全风险,因为它们可能会执行任意代码或将恶意代码带入您的应用程序。您可以作为消费者自己检查所有文件,也可以依赖您信任的来源或作者。提供信任的一种方法是 signing packages 以防止内容被篡改并确保包的完整性。同样,这不会验证 如何 您的可执行文件是如何构建的。