dotnet-exec 0.12.0 released
Intro
dotnet-exec
是一個 C# 程序的小工具,可以用來運行一些簡單的 C# 程序而無需創建項目文件,讓 C# 像 python/nodejs 一樣簡單,而且可以自定義項目的入口方法,支持但不限于 Main 方法。
Install/Update
dotnet-exec
是一個 dotnet tool,可以使用安裝 dotnet tool 的命令來安裝
安裝/更新最新穩定版本:
dotnet?tool?update?-g?dotnet-execute
安裝最新的 preview 版本:
dotnet?tool?update?-g?dotnet-execute?--prerelease
執行 dotnet-exec -h
或者 dotnet-exec --help
即可看到一些使用說明
Features
Config profile
在這個版本中我們加入了一個 config profile 的功能,我們可以將常用的選項配置保存到一個 profile 中,這樣我們就可以直接重用 profile 就可以了就不需要每次都用,我們可以使用 dotnet-exec profile --help
查看使用幫助
可以使用 ls
命令列出所有的 profiles
dotnet-exec?profile?ls
使用 get
命令獲取 profile 的詳細配置:
dotnet-exec?profile?get?web
使用 set
命令來配置 profile 對應的配置:
dotnet-exec?profile?set?web?-r?"nuget:WeihanLi.Web.Extensions"?-u?'WeihanLi.Web.Extensions'?--web?--wide?false
使用 rm
命令來刪除某一個 profile 的配置
dotnet-exec?profile?rm?web
在執行代碼的時候可以通過 --profile
指定要使用的 profile 配置,也可以額外補充 using 以及 reference 信息,也可以移除 profile 中的某一個 using 或者 reference
dotnet-exec?'WebApplication.Create().Chain(_=>_.MapRuntimeInfo()).Run();'?--profile?web?--using?'WeihanLi.Extensions'
Additional script for scripts
在之前版本中增加了對代碼的依賴支持,但是,script 的漏掉了,在這個版本中補充了上去
一個簡單的示例如下:
需要注意的是 script 的依賴也是script代碼有一些特殊,不能包含命名空間聲明的操作,否則會報錯
Gitee url transform
在之前的版本中我們已經添加了對于 github 和 gist 的支持,在這個版本中增加了對 gitee 的支持
在請求 https://gitee.com/weihanli/storage/blob/master/test/test.cs 的時候會自動轉換成 https://gitee.com/weihanli/storage/raw/master/test/test.cs
執行結果如下:
Reference && Using enhancements
在之前的版本中我們不支持 reference 的 remove,添加了 profile 功能之后有些 reference 可能會希望執行的時候移除掉,所以在新的版本中支持了 reference 的 remove,移除的時候和 using 類似,以 -
開頭即可,另外移除的優先級比較高,如果既有添加又有移除最終會被移除,示例如下:
移除 using
移除 reference
在新的版本中支持了從 project file 解析 project 引用,但只支持本地的 project file,遠程的 project file 不支持,因為要 build 項目,項目不在本地無法進行 build
另外改進了一下 framework reference,針對某個 framework 的引用會自動嘗試加載隱式命名空間引用
通過 framework reference 的形式來跑一個 web api,這等于是直接使用 --web
選項
dotnet-exec?'WebApplication.Create().Run();'?--reference?'framework:web'
我們給 asp.net core web 框架加了幾個別名,可以根據自己需要選擇,目前支持的有
web
/aspnet
/aspnetcore
再來看一下 WindowsDesktop 的框架引用示例:
More
.NET Conf China 2022 release~~
References
https://github.com/WeihanLi/dotnet-exec
https://www.nuget.org/packages/dotnet-execute/
https://hub.docker.com/r/weihanli/dotnet-exec
https://github.com/WeihanLi/dotnet-exec/compare/0.11.0...0.12.0