当前位置:网站首页>dotnet-exec 0.4.0 released
dotnet-exec 0.4.0 released
2022-06-25 04:01:00 【dotNET跨平台】
dotnet-exec 0.4.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 --prereleaseUpdates
Features
Custom Usings
在 0.4.0 版本中支持用户自定义 using 默认会包含默认的 using 引用,你也可以自定义要增加的 using
比如说下面这个示例,使用了一个 static using
dotnet-exec 'code:WriteLine(1+1);' --using "static System.Console"输出结果如下:

如果不加这个引用的话就会报错

我们也可以移除默认的 using 引用,只需要以 “-”开头就可以了,比如下面这样

前面可以正常编译并执行的程序就变得编译不通过了
Preview enhancement
在新版本中增加了一个 --preview 的选项来简化 --lang-version=Preview 的配置,除了 LangVersion 配置之外,还会增加一个程序集 attribute [assembly:System.Runtime.Versioning.RequiresPreviewFeatures] 来启用一些还在预览中的一些特性,从 .NET 6 开始支持正式版发布中带一些预览特性的功能,使用的话需要配置这个 attribute,所以针对 preview 增加了这个 Attribute

Startup type
新的版本中增加了一个 --startup-type 的选项,默认如果有多个入口会找到第一个,startup-type 可以帮助找到更加准确的入口
Reference handling refactor
之前是直接把编译好的 dll 加载到了默认的 AssemblyLoadContext,这在一般情况下没什么问题
但是在出现程序集版本冲突的时候就会报错,新的版本中会使用单独的 AssemblyLoadContext,并且修复了之前单独使用 AssemblyLoadContext 时执行代码的问题,就是因为前面介绍的 Reference Assembly,在编译时使用引用程序集,在执行时换成了包含实现的实现程序集去执行代码,这样我们在需要测试两种版本下不同的行为就会变得简单

Executor refactor
0.4.0 的版本中增加了 --executor-type,类似于上一个版本中的 --compiler-type,但是目前只提供了一种实现,主要为了便于更好的进行扩展
Docker support
如果你不是 dotnet 开发者,不想安装 dotnet sdk,你也可以使用 docker 来尝试它
docker run --rm weihanli/dotnet-exec:0.4.0 dotnet-exec "code:(1+1).Dump()"
Bug fix
修复 Linux 上 dotnet path 的问题
在 Linux 环境上默认的
dotnet路径并不是 dotnet 可执行文件,而是一个 symbol link 文件,需要找到对应真正的文件路径,由于代码的 BUG 导致没有转换成真正的文件路径,在 0.4.0 版本中已经修复
More
目前 dotnet-exec 依赖于 SDK 环境,后面要改进一下,只需要 Runtime 环境就可以,这样 docker 镜像可以小很多,另外打算支持可以自定义引用,比如引用自己的 dll 或者指定的 Nuget 包
References
https://github.com/WeihanLi/dotnet-exec
https://www.nuget.org/packages/dotnet-execute/
https://hub.docker.com/repository/docker/weihanli/dotnet-exec
边栏推荐
- 【esp32学习之路6——flash加密】
- Coordinate system left multiply right multiply
- Mongodb cluster
- JS arrow function
- 2021.4.15 note the difference between let, const and VaR in ES6
- Anaconda installation +tensorflow installation +keras installation +numpy installation (including image and version information compatibility issues)
- PHP extracts and analyzes table contents, and collects bidding information
- OOP 向量加减(友元+拷贝构造)
- PHP encapsulates curl to send get and post request methods, and uses
- How to apply for software
猜你喜欢

Code scanning payment flow chart of Alipay payment function developed by PHP

第九章 APP项目测试(2) 测试工具

Anaconda安装+TensorFlow安装+Keras安装+numpy安装(包含镜像和版本信息兼容问题)

php开发支付宝支付功能之扫码支付流程图

领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!

「 每日一练,快乐水题 」1108. IP 地址无效化

Concat() in JS

CTF_ Web: advanced problem WP (5-8) of attack and defense world expert zone

Value transfer between parent and child components of wechat applet

关于TCP连接三次握手的详细总结
随机推荐
Concat() in JS
GBASE 8s存储过程语法结构
Php7.2 add JPEG extension
PHP encapsulates curl to send get and post request methods, and uses
三角形类(构造与析构)
【esp32学习之路6——flash加密】
GBASE 8S内存管理
GBASE 8s 索引B+树
CTF_ Web: Advanced questions of attack and defense world expert zone WP (19-21)
GBASE 8s 索引R树
计算学生成绩等级(虚函数和多态)
Easyrecovery15 very easy to use computer data recovery software
Join() in JSZ
Wechat likes to pay attention to the solution of invalid automatic reply
OOP 向量加减(友元+拷贝构造)
CTF_ Web: Changan cup-2021 old but a little new & asuka
Gbase 8s index b+ tree
小白学习MySQL - 统计的'投机取巧'
A detailed summary of TCP connection triple handshake
CTF_ Web: basic 12 questions WP of attack and defense world novice zone