在上篇博客[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 directives19     --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_VERSION10 11 # Start Cake12 [string]$CAKE_ARGS = "-verbosity=diagnostic"13 14 Write-Host "dotnet cake $SCRIPT $CAKE_ARGS $ARGS" -ForegroundColor GREEN15 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    └─build10       ├─clean11       └─restore12 13 push14 └─pack15    └─test16       └─build17          ├─clean18          └─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.tool11 dotnet tool install --global cake.tool --version $CAKE_VERSION12 export PATH="$PATH:$HOME/.dotnet/tools"13 14 # Start Cake15 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 

[Cake] 2. dotnet 全局工具 cake相关推荐

  1. .net core下的dotnet全局工具

    .net core 2.1后支持了一个全新的部署和扩展命令,可以自己注册全局命令行. dotnet install tool -g dotnetsay dotnetsay 也可以自己构建自己的命令行, ...

  2. [Cake] 1. CI中的Cake

    在上一篇C#Make自动化构建-简介中,简单的介绍了下Cake的脚本如何编写以及通过Powershell或者Bash在本地运行Cake脚本.本篇在此基础上,介绍下如何在CI环境中使用Cake. 1. ...

  3. jdk安装失败_jenkins全局工具jdk、maven安装

    jdk自动安装需要oracle网站的账号才能使用,但还是安装失败,原因:就是网速太卡.有时版本那里会显示空白,那是因为使用国内镜像时jenkins_home/updates/hudson.tools. ...

  4. Vue——定义全局工具类

    解决方案 一:简单的写法 每次使用都需要import test.js: 具体使用 二:定义全局工具类(实例属性) 官方文档:https://cn.vuejs.org/v2/cookbook/addin ...

  5. 关于dotNet加密工具

    我一直用的是Xenocode Postbuild 2006 Profession(呵呵,比较老了,只是随便处理下,防不了高手),可是,最近Windows更新些不知什么内容,弄得我三台电脑上都无法正常运 ...

  6. SonarQube系列二、分析dotnet core/C#代码

    来源:https://www.cnblogs.com/7tiny/p/11342902.html [前言] 本系列主要讲述sonarqube的安装部署以及如何集成jenkins自动化分析.netcor ...

  7. C# 中使用面向切面编程(AOP)中实践代码整洁

    1. 前言 最近在看<架构整洁之道>一书,书中反复提到了面向对象编程的 SOLID 原则(在作者的前一本书<代码整洁之道>也是被大力阐释),而面向切面编程(Aop)作为面向对象 ...

  8. C# 中使用面向切面编程(AOP)中实践代码整洁(转)

    出处:https://www.cnblogs.com/chenug/p/9848852.html 1. 前言 最近在看<架构整洁之道>一书,书中反复提到了面向对象编程的 SOLID 原则( ...

  9. Cake Frosting:更具可维护性的C#DevOps

    目录 什么是Frosting? 入门 适应Frosting 别名 目录/文件 插件和工具 概括 Frosting中的代码更加冗长,别名和目录不那么方便.但是,您将得到的强类型的.可维护的代码可能是值得 ...

最新文章

  1. 什么是物联网网关?物联网网关具备什么功能?_转
  2. 基于Cobbler实现多版本系统批量部署
  3. mysql通过局域网访问数据库_MySQL数据库之局域网内访问同一个mysql数据库
  4. 【Siddhi】Siddhi 如何表示布尔 Syntax error in SiddhiQL, mismatched input ‘boolean
  5. 属性匹配工具_Route-policy的匹配工具If-match的使用简介
  6. 图论(二):图的割点(cut vertex)与连通度(connectivity)
  7. 基于WEB的网上购物系统的设计与实现(附:源码 论文 sql文件)
  8. face_landmarks
  9. 新特汽车在重庆“复活”:打造新品牌“电动屋”,已获网约车牌照
  10. Linux下的永中 Office 2004(转)
  11. 计算机小喇叭找不到,windows电脑右下角的小喇叭不见了_电脑声音的小喇叭不见了...
  12. matlab画图不显示中文_如何解决 Matlab 画图时中文显示乱码的问题?
  13. 综合函数矩量法原理及实现思路
  14. sim卡与imei号和手机号码之间的关系
  15. 浅谈支付宝第三方支付
  16. 福昕阅读器自定义快捷键
  17. BUU刷题记录——5
  18. 刷爆朋友圈的虚幻引擎5,会给我们带来哪些影响?
  19. 芒果iOS开发之百度魔图面试题
  20. Conflux 树图区块链 “数字藏品 合约标准和编写规范

热门文章

  1. 用户帐户控制设置_创建快捷方式以避免用户帐户控制弹出式快捷方式
  2. 自从装了windows神器,再也不用羡慕mac了
  3. 使用Visual Studio 创建可视Web Part部件
  4. nobelking 3 js 数字和数字相加 字符串连接 数字和字符串连接1
  5. 递归与非递归法实现链表相加 CC150 V5 2.5题 java版
  6. 怎么实现动态设置静态文件存储目录?
  7. 更方便地模拟 Http 响应
  8. 当 dotnet-monitor 遇上 Prometheus, 是种什么样的体验?
  9. 值得永久收藏的 C# 设计模式套路(一)
  10. 如何编写干净流畅的Web API测试