dotnet-exec 0.6.0 released
Intro
dotnet-exec
是一個 C# 程序的小工具,可以用來運行一些簡單的 C# 程序而無需創建項目文件,而且可以自定義項目的入口方法,支持但不限于 Main 方法
Install/Update
dotnet-exec
是一個 dotnet tool,可以使用安裝 dotnet tool 的命令來安裝
安裝/更新最新穩定版本:
dotnet?tool?update?-g?dotnet-execute
安裝最新的 preview 版本:
dotnet?tool?update?-g?dotnet-execute?--prerelease
Script
在 0.6.0 版本中引入了 script 支持,從而簡化一些簡單的代碼使用,比如說這個簡單的例子
dotnet-exec?"script:1+1"
在 0.5.0 版本中用戶可以自定義 reference,現在你也可以針對 script 使用 -r
/--reference
選項來自定義引用的本地的 dll 或者 nuget 包
比如說下面這個引用 nuget 包的示例
dotnet-exec?"script:typeof(CsvHelper).Assembly.Location"?-r?"nuget:WeihanLi.Npoi"?-u?"WeihanLi.Npoi"
這里引用了 WeihanLi.Npoi
這個 nuget 包,沒有指定版本的時候默認使用最新的穩定版本,目前是 2.3.0 所以我們看到的輸出結果會是 2.3.0
我們也可以指定具體的 NuGet 包版本,比如:
dotnet-exec?"script:typeof(CsvHelper).Assembly.Location"?-r?"nuget:WeihanLi.Npoi,2.1.0"?-u?"WeihanLi.Npoi"
我們也可以直接引用本地的 dll,比如我們引用上面 nuget 包中的本地 dll
dotnet-exec?"script:typeof(CsvHelper).FullName"?-r?"C:\Users\Weiha\.nuget\packages\weihanli.npoi\2.3.0\lib/net6.0/WeihanLi.Npoi.dll"?-u?"WeihanLi.Npoi"
新的 docker 鏡像已經發布,也可以通過 docker 使用?weihanli/dotnet-exec:0.6.0?鏡像來體驗
References
https://github.com/WeihanLi/dotnet-exec
https://www.nuget.org/packages/dotnet-execute/
https://hub.docker.com/r/weihanli/dotnet-exec