Loading

windows右键菜单自动打包发布nuget,没有CI/CD一样方便!

构建现代的 .Net 应用离不开 Nuget 的支持,而快速打包 Nuget 成了提高生产率的有效方法。没有CI/CD?来试试使用windows右键菜单吧

先看右键效果图

有时候我们可能没有CI/CD的条件来自动发布nuget包,这个时候文件夹右键菜单就显得十分高效了
如图所示,直接在文件夹右键可以看到又nuget publish的菜单按钮

如何实现

具体的操作是修改 windows 的注册表,具体可以参考 windows 下如何修改右键菜单 一文

这里我写了2个注册表脚本分享一下

bata版发布:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Nuget]
@="Nuget Publish-beta"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Nuget\command]
@="powershell.exe -noexit -command Set-Location -literalPath '%V' ;powershell.exe  -c \"echo $pwd;del *.nupkg ;$ver = -join ((Get-Date -format 'yyyy.MMdd.HH.mm'),'-beta');$outputpwd=$pwd;foreach($item in (ls $pwd -R | ?{$_.psiscontainer -eq $true} | Where-Object {Test-Path (join-path $_.fullname *)  -include '*.csproj'})){dotnet pack $item.fullname --configuration Release --output  $outputpwd /p:Version=$ver;}$nupkg= dir *.nupkg; dotnet nuget push $nupkg -k chx666 -s http://192.168.1.24:8080;del $nupkg\""

正式版发布:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Nuget]
@="Nuget Publish-beta"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\Nuget\command]
@="powershell.exe -noexit -command Set-Location -literalPath '%V' ;powershell.exe  -c \"echo $pwd;del *.nupkg ;$ver = (Get-Date -format 'yyyy.MMdd.HH.mm');$outputpwd=$pwd;foreach($item in (ls $pwd -R | ?{$_.psiscontainer -eq $true} | Where-Object {Test-Path (join-path $_.fullname *)  -include '*.csproj'})){dotnet pack $item.fullname --configuration Release --output  $outputpwd /p:Version=$ver;}$nupkg= dir *.nupkg; dotnet nuget push $nupkg -k chx666 -s http://192.168.1.24:8080;del $nupkg\""

搞定

将文本另存为 xxx.reg(注意,文件编码需要UTF-16 LE, 不然右键菜单点击会报错),双击即可导入到系统,然后重启 windows 资源管理器的进程(就是我的电脑的进程)。
然后右键就可以体验啦,搞定收工。

最后

欢迎大家体验评论,使用后欢迎各位给出更好的脚本方案评论

posted @ 2021-10-21 11:44  饭勺oO  阅读(377)  评论(2编辑  收藏  举报