从PowerShell脚本运行C#.cs文件 [英] Run a C# .cs file from a PowerShell Script

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

问题描述

我有一个 PowerShell V2 脚本,该脚本可移动一些文件并安装某些服务。但是,我想在PowerShell脚本的一半左右调用并运行.cs文件。我已经找到了许多关于从 C#调用 PowerShell 的文章,但没有相反的方法。我只希望C#文件运行一次,然后继续运行PowerShell脚本。

I have a PowerShell V2 script that moves some files around and installs some services. However I would like to call and run a .cs file about halfway through the PowerShell Script. I have found plenty of articles on calling PowerShell from C# but none the opposite way around. I would just like the C# file to run once then continue running the PowerShell script.

如果有人可以将我引向一篇说明如何实现此目标的文章的指导,或者您了解自己并且可以帮助您,将不胜感激。

If anyone could point me in the direction of an article explaining how to accomplish this or if you know yourself and could help it would be greatly appreciated.

推荐答案

您正在寻找错误的内容。将C#放入程序集,然后从PowerShell调用其公共类,函数和方法,就像从Powershell调用.NET Framework一样。

You're looking for the wrong thing. Put your C# into an assembly, and call its public classes, functions and methods from PowerShell, just like you would call the .NET Framework from Powershell.

要从PowerShell编译和运行C#源代码,请参见
周末脚本编写者:在PowerShell中运行C#代码

If you really want to compile and run C# source from PowerShell, see Weekend Scripter: Run C# Code from Within PowerShell.

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

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