Powershell极速教程-如何在三分钟内编写项目编译脚本

分析及思路

来看一下项目目录结构

image

炒鸡正常的三板斧src+docs+tests。咦,怎么会多出一个build的文件夹呢,这就是我们今天要研究的目录。今天我会带着大家在五分钟之内编写一个极简的编译脚本。

build内及其简单image

思路很明显了:获取当前脚本所在目录=>获取上一级目录=>回到上一级(.sln所在目录)=>执行dotnet publish –c release

第一分钟:了解基本的变量

1.$psscriptroot:当前脚本文件所在目录,从Powershell3.0开始,有一个新的自动变量叫$PSScriptRoot,这个变量以前只存在模块里,它能指向当前文件夹中的脚本的位置(准确的说在你运行脚本的时候它才有用)

2.变量定义:$代表var,$workspace={$workspace} 定义一个变量

第二分钟:路径变换的基本操作

1.split-path –parent {$path}

2.join-path {$path1} {$path2}

3.cd {$path}进入某目录

第三分钟:编写脚本

1.获取当前脚本所在目录,为方便查看,有些变量我们可以向控制台输出一下:

echo $psscriptroot

2.获取上一级目录,我们可以定义它为我们的工作目录:

$workspace=split-path –parent $psscriptroot

3.回到上一级(.sln所在目录)

cd $workspace

4.执行dotnet publish –c release

dotnet publish –c release

最终脚本如下:

echo $psscriptroot

 

$workspace=split-path -parent $psscriptroot

 

echo $workspace

 

cd $workspace

 

echo "releasing project..."

 

dotnet publish -c release


image

最后

powershell 作为一种脚本语言,他可能比多数脚本语言都要强大。作为windows的日常使用者,了解并使用它,一定会让我们日常的工作事半功倍!

最后贴出 自动打包类库并发布到nuget.org的例子给大家参考一下:

image

转载于:https://www.cnblogs.com/gainorloss/p/10563371.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
中文名: PowerShell脚本编写手册 原名: Windows Powershell Scripting Guide 作者: Ed Wilson 资源格式: PDF 版本: 影印版 出版社: Microsoft Press书号: 073562279发行时间: 2008年 地区: 美国 语言: 英文 内容简介: Get practical guidance for using Windows PowerShell to manage Windows Vista and Windows Server 2008. Written by Ed Wilson, a leading scripting expert and trainer at Microsoft, this reference offers a task-based approach to help you find the information you need for day-to-day tasks. With more than 200 scripts, it offers rich examples that administrators can customize for their own environment and needs. The scripts range in complexity from one-line commands, to full-blown scripts with managed output and command-line arguments examples that are applicable to all skill levels. Includes a companion CD with fully searchable eBook, sample scripts, and other resources for managing your Windows-based environment.Key Book Benefits Delivers more than 200 scripts administrators can customize and use to get up and running quickly Provides multiple ways of accomplishing tasks: from one-line commands to full-blown scripts with managed output and command-line arguments Features a task-oriented approach, and organized to help you quickly find the information you need for your day-to-day activities Includes a companion CD with a fully searchable eBook, sample scripts, and other resources for on-the-job results 目录: 1. The Shell in Windows Powershell. 2. Scripting Windows Powsershell 3. Managing Logs 4. Managing Services 5. Managing Shares 6. Managing Printing 7. Desktop Maintenance 8. Networking 9. Configuration Desktop Settings 10. Managing Post-Deployment Issues 11. Managing User Data 12. Troubleshooting Windows 13. Managing Domain Users 14. Configuring the Cluster Service 15. Managing Internet Information Services 16. Working with the Certificate Store 17. Managing the Terminal Services Service 18. Configuring Network Services 19. Working with Windows Server 2008 Server Core

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值