I'm a huge fan of .NET Core global tools. I've done a podcast on Global Tools. Just like Node and other platform have globally tools that can be easily and quickly installed and then used in build scripts, CI/CD (Continuous Integration/Continuous Deployment) systems, or just general command line utilities, .NET Global Tools are easily made (by you!) and distributed via NuGet.
我非常喜欢.NET Core全局工具。 我在Global Tools上做了一个播客。 就像Node和其他平台具有可以轻松快速地安装然后在构建脚本,CI / CD(连续集成/连续部署)系统中使用的全局工具一样,或者仅在通用命令行实用程序中使用。.NETGlobal Tools易于制作(由您!)并通过NuGet分发。
Some cool examples (and there are hundreds) are the "Try .NET" Workshop runner and creator that can you can use to make interactive documentation, or coverlet for code coverage. There's a great and growing list of .NET Core Global Tools on GitHub.
一些很酷的例子(有成百上千个)是“ Try .NET” Workshop运行者和创建者,您可以用来制作交互式文档,或用于覆盖代码的coverlet 。 GitHub上有大量且不断增长的.NET Core全局工具列表。
If you've got the .NET SDK installed you can try out a global tool just like this.
如果您安装了.NET SDK ,则可以尝试使用像这样的全局工具。
dotnet tool install -g dotnetsay
dotnet tool install -g dotnetsay
Then run this example with "dotnetsay," it's fun.
然后使用“ dotnetsay”运行此示例,这很有趣。
stepping back a moment, you may be familiar with PowerShell. It's a scripting language and a command line shell like Bash or DOS or the Windows Command Prompt. You may think of PowerShell as a tool for maintaining and managing Windows Servers.
退一步,您可能对PowerShell很熟悉。 它是一种脚本语言和命令行外壳,例如Bash或DOS或Windows命令提示符。 您可能会将PowerShell视为维护和管理Windows Server的工具。
However in recent years, PowerShell has gone cross platform and runs most anywhere. It's lightweight and has .NET Core at its, ahem, core. You can use PowerShell for scripting systems on any platform and if you're a .NET developer the team has made installing and immediately using PowerShell in scripts a one liner - which is genius. It's PowerShell as a .NET Global Tool.
但是,近年来,PowerShell已经跨平台运行,并且可以在大多数地方运行。 它是轻量级的,并具有.NET Core。 您可以将PowerShell用于任何平台上的脚本系统,如果您是.NET开发人员,则该团队已使安装和立即在脚本中使用PowerShell成为一个胆小鬼-天才。 作为.NET全局工具的PowerShell 。
Here's an example output from my system running Ubuntu. I just "dotnet tool install --global PowerShell."
这是运行Ubuntu的系统输出的示例。 我只是“ dotnet工具安装--global PowerShell”。
$ dotnet --version
2.1.502
$ dotnet tool install --global PowerShell
You can invoke the tool using the following command: pwsh
Tool 'powershell' (version '6.2.2') was successfully installed.
$ pwsh
PowerShell 6.1.1
https://aka.ms/pscore6-docs
Type 'help' to get help.
PS /mnt/c/Users/Scott/Desktop>
exit
Here I've checked that I have .NET 2.x or above, then I install PowerShell. I can run scripts or I can drop into the interactive shell. Note the PS prompt and my current directory above.
在这里,我检查了.NET 2.x或更高版本,然后安装了PowerShell。 我可以运行脚本,也可以进入交互式外壳。 注意上面的PS提示符和我当前的目录。
In fact, PowerShell is so useful as a scripting language when combined with .NET Core that PowerShell has been included as a global tool within the .NET Core 3.0 Preview Docker images since Preview 4. This means you can use PowerShell lines/scripts inside Docker images.
实际上,PowerShell作为与.NET Core结合使用的脚本语言非常有用,以至于从Preview 4开始,PowerShell已作为.NET Core 3.0 Preview Docker映像中的全局工具包含PowerShell。这意味着您可以在Docker内部使用PowerShell行/脚本。图片。
FROM mcr.microsoft.com/dotnet/core/sdk:3.0
RUN pwsh -c Get-Date
RUN pwsh -c "Get-Module -ListAvailable | Select-Object -Property Name, Path"
Being able to easily install PowerShell as a global tool means you can count on it in your scripts, CI/CDs systems, or docker containers. It's also nice to be able to be able to use existing PowerShell scripts cross platform.
能够轻松地将PowerShell作为全局工具安装意味着您可以在脚本,CI / CD系统或Docker容器中依靠它。 能够跨平台使用现有的PowerShell脚本也很不错。
I'm impressed with this idea - installing PowerShell itself as a .NET Global Tool. Very clever and useful.
这个想法让我印象深刻-将PowerShell本身安装为.NET Global工具。 非常聪明和有用。
翻译自: https://www.hanselman.com/blog/installing-powershell-with-one-line-as-a-net-core-global-tool