建网站的费用,网站建设的特点,深圳网站制作公司招聘,郑州网站优化的微博_腾讯微博dotnet-exec 0.11.0 releasedIntrodotnet-exec 是一个 C# 程序的小工具#xff0c;可以用来运行一些简单的 C# 程序而无需创建项目文件#xff0c;让 C# 像 python/nodejs 一样简单#xff0c;而且可以自定义项目的入口方法#xff0c;支持但不限于 Main 方法。Install/Upd…dotnet-exec 0.11.0 releasedIntrodotnet-exec 是一个 C# 程序的小工具可以用来运行一些简单的 C# 程序而无需创建项目文件让 C# 像 python/nodejs 一样简单而且可以自定义项目的入口方法支持但不限于 Main 方法。Install/Updatedotnet-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 即可看到一些使用说明FeaturesStatic using using alias在之前版本中对于 script我们是不支持 static using 和 using alias 的只支持 code 中使用在 0.10.0 版本中我们支持了在 script 中使用 static using 和 using 的别名了举个栗子dotnet-exec MyConsole.WriteLine(PI) --using MyConsoleSystem.Console --using static System.Math实现原理其实也比较简单script 默认的 import 选项只能引入普通的命名空间于是我们曲线救国把 using 作为代码先执行了一下之后再执行我们的 script 代码在同一个上下文中会记住之前的 using 信息具体实现代码可以参考https://github.com/WeihanLi/dotnet-exec/blob/2b2d2d4d47da5561001fb9f172bea65a8daa0932/src/dotnet-exec/CSharpScriptingExecutor.cs#L50-L52Execute without SDK在之前的版本中我们进行编译的时候始终会选择去使用引用程序集进行编译在没有 SDK 的环境里会尝试从 nuget 上下载引用程序集进行编译在 0.10.0 版本中我们默认会使用 runtime 的程序集进行编译这样即使没有网络没有 SDK只有 runtime 依然是可以工作的当然你仍然可以使用 --ref-compile 选项来指定始终使用引用程序集来编译Execute without web在之前的版本中我们的 docker 镜像使用的是 aspnet 的镜像考虑很多场景可能用不到 web 框架所以从 0.11.0 版本开始默认不会再引用 web 框架引用当然你也可以使用 -w/--web 来显式添加 web 框架引用对于 docker 镜像新的 latest tag 的镜像的基础镜像换成了 runtime另外单独提供了一个 web tag 的镜像基础镜像是 aspnet这样我们的镜像就能小很多了但是即使你使用的是 latest 指定了使用 web 框架引用那你仍然可以运行只是本地没有 aspnet runtime 的时候会尝试从 nuget 下载而 web 则内置了 runtime 不需要再去下载来个例子首先我们可以来看一下最新的 docker 镜像中只有一个 .NET Core runtime 的信息没有 aspnet 的 runtime 了我们用这个镜像来跑一个 web api 项目docker run --rm --pullalways weihanli/dotnet-exec:latest dotnet-exec WebApplication.Create().Run(); --web从上面的截图可以看到我们的 webapi 已经跑起来了我们可以进一步使用暴露一个端口请求一下我们的 API 试一下让我们稍加改造docker run --rm --pullalways -p 5000:80 weihanli/dotnet-exec:latest dotnet-exec WebApplication.Create().Chain(_ _.MapRuntimeInfo()).Run(); --web --reference nuget:WeihanLi.Web.Extensions --using WeihanLi.Web.Extensions这里引用了一个我自己封装的一个扩展会注册一个 runtime-info 的 endpoint我这里使用的是 Github 的 CodeSpaces会自动暴露一个 endpoint 来访问我们的服务我们可以访问我们的 runtime-info endpoint 会看到一个类似下面的 response我们也可以使用 curl 或者可以使用 dotnet-httpie 来访问这个 endpointdotnet-http :5000/runtime-infoProjectReference在 0.11.0 版本中我们增加项目引用的支持实现原理是尝试 build 项目引用 build 之后的 dll使用方式如下dotnet-exec ApplicationHelper.GetLibraryInfo(typeof(CsvHelper)) --reference project:C:\projects\sources\WeihanLi.Npoi\src\WeihanLi.Npoi\WeihanLi.Npoi.csproj --using WeihanLi.Npoi和引用 nuget 的效果基本一致ApplicationHelper.GetLibraryInfo 是从 assembly 信息中获取信息封装的一个方法可以参考https://github.com/WeihanLi/WeihanLi.Common/blob/d2db73a0e02cef009dc61190a41263ad6cb2b6bc/src/WeihanLi.Common/Helpers/ApplicationHelper.cs#L28More原来引用本地的 dll 需要指定一个绝对路径full path)在 0.11.0 版本中我们支持了相对路径使用起来也是更加的简单新增加的项目引用也是支持相对路径的上面的更新包含了 0.10.0 版本和 0.11.0 版本具体更新可以参考 Github代码变更可以参考https://github.com/WeihanLi/dotnet-exec/compare/0.9.0...0.11.0Referenceshttps://github.com/WeihanLi/dotnet-exechttps://www.nuget.org/packages/dotnet-execute/https://hub.docker.com/r/weihanli/dotnet-exechttps://github.com/WeihanLi/dotnet-exec/compare/0.9.0...0.11.0https://github.com/WeihanLi/WeihanLi.Common/blob/d2db73a0e02cef009dc61190a41263ad6cb2b6bc/src/WeihanLi.Common/Helpers/ApplicationHelper.cs#L28