C#命令行脚本 [英] C# command line scripts

查看:145
本文介绍了C#命令行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这是一个很容易找到答案的问题。



真的,真的试着继续使用PowerShell,我发现它语法至少可以说是奥术。我不怀疑它的力量,但我不是一个系统管理员,我不经常批量编写脚本。因此,每当我回到PowerShell时,即使是最简单的任务,Google的语法也需要很长时间。几乎总是,我发现自己在思考,我可能在C#中没有问题,有时我会在Visual Studio中创建一个完整的命令行.exe来做我想做的事情。所以...



是否有一种简单方便的方法来创建基于C#语法的脚本,然后从Windows命令提示符运行它们?



任何对人们有经验的建议或意见都将不胜感激。



亲切的愿望 - Patrick



我尝试了什么:



我看过CS-Script和ScriptCS以及还看了 dotnet-script ,但他们似乎没有很好地整合。通过这种方式,我的意思是我很难看到一个简单的工作流程,我会用它来创建,组织和运行脚本。如果我不经常使用它,我很难看到我会记得如何使用这些。

解决方案

这篇CP文章可能有所帮助:



在运行时编译C#代码 [ ^ ]



您实际上可以创建一个CSharpScript应用程序,它可以加载包含C#脚本代码的文本文件,并在运行时编译该脚本。您还可以为脚本运行器应用程序编写预编译的插件,并在命令行上指定DLL名称。



执行此操作几次之后,您可能会发现使用PowerShell更容易。 :)

I have what I thought would be a dead easy question to find an answer to.

Having really, really tried to get on with PowerShell, I find its syntax to be arcane to say the least. I don't doubt its power but I'm not a sysadmin and I don't do batch scripting very often. So every time I come back to PowerShell, it takes me ages to Google the syntax for even the simplest tasks. Almost always, I find myself thinking, I could probably do this no problem in C# and sometimes I do create a full command line .exe in Visual Studio to do what I want. So...

Is there an easy and convenient way to create scripts based on C# syntax and then run them from a Windows command prompt?

Any advice or comments on anything that people have experience of would be appreciated.

Kind wishes - Patrick

What I have tried:

I've looked at CS-Script and ScriptCS and also looked here dotnet-script, but they seem not to integrate well. By that, I mean that I struggle to see an easy workflow I would use for creating, organising and running scripts. And I struggle to see that I'd remember how to use any of these if I didn't use it often.

解决方案

This CP article might help:

Compiling C# Code at Runtime[^]

You could essentially create a CSharpScript app that loads a text file that contains C# "script" code and compile that script at runtime. You could also write pre-compiled plugins for your script runner app, and specify the DLL name on the commandline.

After doing that a couple of times, you might find that it's just easier to use powershell. :)


这篇关于C#命令行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆