[Cake] 2. dotnet 全局工具 cake

在上篇博客[Cake] 1. CI中的Cake中介绍了如何在CI中利用Cake来保持与CI/CD环境的解耦。

当时dotnet 2.1还未正式发布,dotnet 还没有工具的支持,使得安装cake非常麻烦。不过随着 dotnet tool 的加入,这一问题得到了很好的解决。目前安装cake(0.30.0版本之后)只需要一行命令即可:

1 dotnet tool install -g cake.tool

然后就可以使用cake了。用 dotnet cake 或者 dotnet-cake 都可以,推荐使用前者。

 1 $ dotnet cake --help
2
3 Usage: Cake.exe [script] [--verbosity=value]
4 [--showdescription] [--dryrun] [..]
5
6 Example: Cake.exe
7 Example: Cake.exe build.cake --verbosity=quiet
8 Example: Cake.exe build.cake --showdescription
9
10 Options:
11 --verbosity=value Specifies the amount of information to be displayed.
12 (Quiet, Minimal, Normal, Verbose, Diagnostic)
13 --debug Performs a debug.
14 --showdescription Shows description about tasks.
15 --showtree Shows the task dependency tree.
16 --dryrun Performs a dry run.
17 --exclusive Execute a single task without any dependencies.
18 --bootstrap Download/install modules defined by #module directives
19 --version Displays version information.
20 --info Displays additional information about Cake execution.
21 --help Displays usage information.

上一篇博客[Cake] 1. CI中的Cake中出现的cake的引导脚本 build.ps1 和 build.sh ,绝大部分代码都是在下载安装cake用的,既然有了上面的 dotnet tool 命令可以安装cake,那么当然也就可以简化一下了。

引导脚本中包含安装和执行命令的代码。nuget相关的环境变量是项目需要的,cake脚本可以读取这些信息来使用。

2.1 cake.ps1

 1 [string]$SCRIPT       = '0-build/build.cake'
2 [string]$CAKE_VERSION = '0.33.0'
3
4 # nuget server config
5 $ENV:NUGET_REPOSITORY_API_URL = "http://nuget-server.test/nuget"
6 $ENV:NUGET_REPOSITORY_API_KEY = "123456"
7
8 # Install cake.tool
9 dotnet tool install --global cake.tool --version $CAKE_VERSION
10
11 # Start Cake
12 [string]$CAKE_ARGS = "-verbosity=diagnostic"
13
14 Write-Host "dotnet cake $SCRIPT $CAKE_ARGS $ARGS" -ForegroundColor GREEN
15
16 dotnet cake $SCRIPT $CAKE_ARGS $ARGS

查看一下cake脚本都有哪些task:

 1 $ .\cake.ps1 --showtree
2 Tool 'cake.tool' is already installed.
3 dotnet cake 0-build/build.cake -verbosity=diagnostic --showtree
4
5 ....
6
7 default
8 └─test
9 └─build
10 ├─clean
11 └─restore
12
13 push
14 └─pack
15 └─test
16 └─build
17 ├─clean
18 └─restore

2.2 cake.sh

 1 #!/bin/sh
2
3 SCRIPT='0-build/build.cake'
4 CAKE_VERSION='0.33.0'
5
6 # nuget server config
7 export NUGET_REPOSITORY_API_URL='http://nuget-server.test/nuget'
8 export NUGET_REPOSITORY_API_KEY='123456'
9
10 # Install cake.tool
11 dotnet tool install --global cake.tool --version $CAKE_VERSION
12 export PATH="$PATH:$HOME/.dotnet/tools"
13
14 # Start Cake
15 CAKE_ARGS="$SCRIPT -verbosity=diagnostic"
16
17 echo "\033[32mdotnet cake $CAKE_ARGS $@"
18
19 dotnet cake $CAKE_ARGS "$@"

CI/CD的yaml配置文件不用做调整,只需执行对 cake.sh 或者 cake.ps1 的调用即可。这也是cake带来的避免在CI/CD中编程的好处,所有的逻辑都位于cake脚本中。

dotnet tool https://docs.microsoft.com/zh-cn/dotnet/core/tools/dotnet-tool-install

cake 示例项目 https://github.com/linianhui/cake.example

原文地址:https://www.cnblogs.com/linianhui/p/cake-with-dotnet-tool.html

 
 

.NET社区新闻,深度好文,欢迎访问公众号文章汇总 http://www.csharpkit.com 
640?wx_fmt=jpeg


C# Vlc.DotNet是一个用于在C#应用程序中集成VLC媒体播放器的类库。它提供了一组类和方法,使开发人员能够在他们的应用程序中播放视频和音频文件。这个类库包括四个项目:Vlc.DotNet.Core.Interops、Vlc.DotNet.Core、Vlc.DotNet.Forms和Vlc.DotNet.Wpf,后两者依赖于前两者。\[1\] 要使用C# Vlc.DotNet,你需要先安装.NET Core,并使用"dotnet new console"命令生成一个项目文件和基本应用程序。然后,使用"dotnet run"命令编译和运行你的应用程序。"new"命令会创建所有支持代码、obj和bin文件夹等。当你执行"dotnet run"时,实际上是"dotnet build"和"dotnet exec whatever.dll"的组合。\[2\] 如果你想查看dotnet脚本,你可以使用"dotnet tool install -g dotnet-script"命令安装dotnet-script工具。然后,你可以使用"dotnet script"命令来执行脚本文件。\[3\] #### 引用[.reference_title] - *1* [Vlc.DotNet C#音视频播放器使用说明及简单实例](https://blog.csdn.net/u011127019/article/details/52734195)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [c# vlc.dotnet_使用“ dotnet-script”全局工具的C#和.NET Core脚本](https://blog.csdn.net/cunfuteng7334/article/details/109051158)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值