使用 dotnet-script 将 C# 作为脚本工具使用

有时候只想使用 C# 验证或计算一些简单的事情,如何快速实现?

linqpad 是个不错的方案,LINQPad - The .NET Programmer's Playground,这里介绍 dotnet-script

dotnet-script 为何物?

Run C# scripts from the .NET CLI, define NuGet packages inline and edit/debug them in VS Code - all of that with full language services support from OmniSharp.

filipw/dotnet-script: Run C# scripts from the .NET CLI.

准备工作

VS Code,安装插件 C#Code Runner

如何使用

安装

dotnet tool install -g dotnet-script

创建 .csx 文件

#!dotnet-script
// #!dotnet-script  // windows
// #!/usr/bin/env dotnet-script  // linux

Console.WriteLine("hello dotnet");

然后就可以运行了,就这么简单。

更多参考

.NET Core脚本工具dotnet-script - LamondLu - 博客园
Azure Functions C# 脚本开发人员参考 | Microsoft Docs

其它

VScode 中 code runner 插件乱码问题

进入 File - > Preference -> setting, 然后在输入框搜索 settings.json 文件,选择编辑,然后在右边user setting 中增加即可

 "code-runner.runInTerminal": true,

VScode 中 code runner 插件乱码问题_kzcming的博客-CSDN博客_code runner乱码

在线 .net runner

https://try.dot.net

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/jasongrass/p/15071481.html