在 NuGet 中包含控制台应用程序的最佳实践 [英] Best practice to include console app in NuGet

查看:52
本文介绍了在 NuGet 中包含控制台应用程序的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个开源库,它主要由一个面向 .NET Standard 2.0 的类库项目组成.最重要的是,我还实现了一个控制台应用程序,它是该库的 CLI.控制台项目(由于历史原因)仅针对 .NET Framework 4.6.2.

现在我想知道什么是使这个控制台应用程序可供社区使用的最佳实践.在最广泛的层面上,我认为有两种可能性:

  1. 将控制台应用作为单独的 NuGet 提供.
  2. 在与类库相同的 NuGet 中提供控制台应用程序,因为它只是一个小插件,并不能证明自己的包是合理的.

过去,我一直在使用第二种方法,但考虑到类库可用于多目标场景,我不确定了.也许将控制台应用程序分离到它自己的 NuGet 中会更清晰,以便明确它对完整 .NET 框架的依赖.

不管怎样,我想知道控制台 exe 在 NuGet 的文件结构中属于哪个位置.从历史上看,我一直将它放在 tools et462 下,但对 这个页面让我不安全:

<块引用>

可从包管理器控制台访问的 Powershell 脚本和程序

我不一定想象有人使用来自 Package Manager Consoler 的 CLI.相反,它会在某个 shell 中用作独立的 exe.

解决方案

一般来说,NuGet 仅用于提供类库(注意如果您的库..."一词).

使用 Chocolatey 代替将命令行和 GUI 应用程序部署到 Windows.它有一个 CLI,可用于轻松安装和更新应用程序.它不是 NuGet,而是使用类似的方法来打包和部署应用程序.

还有针对其他平台的包管理器:

  1. apt-get(适用于 Debian/Ubuntu/Mint)
  2. Brew(适用于 MacOS)
  3. RPM(用于 Fedora/Red Hat)

<块引用>

注意: 正如 Martin Ullrich 在评论中指出的那样,现在有一个 使用 NuGet 部署构建工具 CLI 的方式,主要用于持续集成部署场景.

I'm developing an open-source library which mainly consists of one class-library project targeting .NET Standard 2.0. On top of that, I've also implemented a console app which is the CLI to this library. The console project (for historic reasons) only targets .NET Framework 4.6.2.

Now I wonder what would be the best practice in order to make this console app available to the community. On the broadest level, I see two possibilities:

  1. Ship the console app as a separate NuGet.
  2. Ship the console app in the same NuGet as the class library because it's just a minor add-on and does not justify an own package.

Historically, I've been using the second approach but considering that the class library can be used in a multi-targeting scenario, I'm not sure anymore. Maybe it's cleaner to separate the console app in a NuGet of its own so that it's dependency on the full .NET framework is clear.

Either way I wonder where the console exe belongs to in the file structure of the NuGet. Historically, I've been putting it under tools et462 but a comment about the tools folder on this page made me insecure:

Powershell scripts and programs accessible from the Package Manager Console

I'm not necessarily imagining someone using the CLI from the Package Manager Consoler. Rather it would be used as stand-alone exe somewhere is some shell.

解决方案

In general, NuGet is meant only for delivering class libraries (note the wording "if your library...").

Use Chocolatey instead for deploying command-line and GUI apps to Windows. It has a CLI that can be used to easily install and update applications. It is not NuGet, but uses a similar method to package and deploy the app.

There are also package managers to target other platforms:

  1. apt-get (for Debian/Ubuntu/Mint)
  2. Brew (for MacOS)
  3. RPM (for Fedora/Red Hat)

NOTE: As Martin Ullrich pointed out in the comments, there is now a way to deploy build tool CLIs with NuGet, which is primarily meant for continuous integration deployment scenarios.

这篇关于在 NuGet 中包含控制台应用程序的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆