c# vlc.dotnet
You likely know that open source .NET Core is cross platform and it's super easy to do "Hello World" and start writing some code.
您可能知道开源.NET Core是跨平台的,并且做“ Hello World”并开始编写一些代码非常容易。
You just install .NET Core, then "dotnet new console" which will generate a project file and basic app, then "dotnet run" will compile and run your app? The 'new' command will create all the supporting code, obj, and bin folders, etc. When you do "dotnet run" it actually is a combination of "dotnet build" and "dotnet exec whatever.dll."
您只安装.NET Core,然后安装“ dotnet新控制台”,它将生成一个项目文件和基本应用程序,然后安装“ dotnet run”将编译并运行您的应用程序? “ new”命令将创建所有支持的代码,obj和bin文件夹等。当您执行“ dotnet run”时,它实际上是“ dotnet build”和“ dotnet exec what.dll”的组合。
What could be easier?
有什么会更容易?
What about .NET Core as scripting?
.NET Core作为脚本怎么办?
Check out dotnet script:
查看dotnet脚本:
C:\Users\scott\Desktop\scriptie> dotnet tool install -g dotnet-script
You can invoke the tool using the following command: dotnet-script
C:\Users\scott\Desktop\scriptie>copy con helloworld.csx
Console.WriteLine("Hello world!");
^Z
1 file(s) copied.
C:\Users\scott\Desktop\scriptie>dotnet script helloworld.csx
Hello world!
NOTE: I was a little tricky there in step two. I did a "copy con filename" to copy from the console to the destination file, then used Ctrl-Z to finish the copy. Feel free to just use notepad or vim. That's not dotnet-script-specific, that's Hanselman-specific.
注意:在第二步中,我有点棘手。 我做了一个“复制CON文件名”从CON唯一复制到目标文件,然后用按Ctrl-Z来完成复制。 随意使用记事本或vim。 这不是特定于dotnet脚本,而是特定于Hanselman。
Pretty cool eh? If you were doing this in Linux or OSX you'll need to include a "shebang" as the first line of the script. This is a standard thing for scripting files like bash, python, etc.
很酷吧? 如果您是在Linux或OSX上执行此操作,则需要在脚本的第一行包含“ shebang ”。 这是脚本文件(例如bash,python等)的标准配置。
#!/usr/bin/env dotnet-script
Console.WriteLine("Hello world");
This lets the operating system know what scripting engine handles this file.
这使操作系统知道什么脚本引擎处理该文件。
If you you want to refer to a NuGet package within a script (*.csx) file, you'll use the Roslyn #r syntax:
如果要在脚本(* .csx)文件中引用NuGet包,则将使用Roslyn #r语法:
#r "nuget: AutoMapper, 6.1.0"
Console.WriteLine("whatever);
Even better! Once you have "dotnet-script" installed as a global tool as above:
更好! 如上所述,将“ dotnet-script”安装为全局工具后:
dotnet tool install -g dotnet-script
You can use it as a REPL! Finally, the C# REPL (Read Evaluate Print Loop) I've been asking for for only a decade! ;)
您可以将其用作REPL! 最后,我一直只要求十年的C#REPL(读取评估打印循环)! ;)
C:\Users\scott\Desktop\scriptie>dotnet script
> 2+2
4
> var x = "scott hanselman";
> x.ToUpper()
"SCOTT HANSELMAN"
This is super useful for a learning tool if you're teaching C# in a lab/workshop situation. Of course you could also learn using http://try.dot.net in the browser as well.
如果您在实验室/车间环境中教授C#,这对于学习工具超级有用。 当然,您也可以在浏览器中使用http://try.dot.net进行学习。
In the past you may have used ScriptCS for C# scripting. There's a number of cool C#/F# scripting options. This is certainly not a new thing:
过去,您可能使用ScriptCS进行C#脚本编写。 有许多很酷的C#/ F#脚本选项。 这当然不是什么新鲜事:
Roslyn Scripting APIs (Roslyn is underneath most scripting environments)
Roslyn脚本API (Roslyn在大多数脚本环境下)
In this case, I was very impressed with the easy of dotnet-script as a global tool and it's simplicity. Go check out https://github.com/filipw/dotnet-script and try it out today!
在这种情况下,dotnet-script作为全局工具的简便性和简单性给我留下了深刻的印象。 去看看https://github.com/filipw/dotnet-script并立即尝试!
翻译自: https://www.hanselman.com/blog/c-and-net-core-scripting-with-the-dotnetscript-global-tool
c# vlc.dotnet