C#通过我的应用程序调用资源管理器中的.cs文件[已解决] [英] C# invoke a .cs file that is in explorer through my app [solved]

查看:192
本文介绍了C#通过我的应用程序调用资源管理器中的.cs文件[已解决]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行我的资源管理器中的cs文件(带参数)(而不是通过我的IDE)。在cs文件中会有一个名为main的方法,我想通过我的控制台应用程序运行带有参数的方法。



编辑:



如果您在这里同样的事情,: - ]



编译器构造 - 是否可以动态编译和执行C#代码片段? - 堆栈溢出 [ ^ ]

使用CodeDOM | Microsoft Docs [ ^ ]

从CodeDOM图生成和编译源代码Microsoft Docs [ ^ ] //包含我需要的内容



我有什么尝试过:



搜索找不到一个好的答案,这个答案对我有用。我经常遇到一个涉及通过我的IDE运行cs文件的主题,我正在尝试通过我的控制台应用程序运行我的资源管理器中的运行cs文件。

I'm trying to run a cs file(with arguments) that is in my explorer(not through my IDE). There will be a single method named "main" in the cs file , I want to run that with arguments through my console app.



If your here for the same thing, :-]

compiler construction - Is it possible to dynamically compile and execute C# code fragments? - Stack Overflow[^]
Using the CodeDOM | Microsoft Docs[^]
Generating and Compiling Source Code from a CodeDOM Graph | Microsoft Docs[^] // contained what I need

What I have tried:

did searching can't find a good answer, a answer that is working for me. I usually run into a topic involving 'running a cs file through my IDE', I'm trying to a run cs file that is in my explorer through my console app.

推荐答案

要做到这一点,你需要编译它 - 这没关系,因为每个.NET安装都包含C#编译器,CSC.EXE:在运行时编译C#代码 [ ^ ]

然后您可以使用Process.Start运行它(如果它干净地编译): Process.Start方法(System.Diagnostics) [ ^ ]
To do that, you need to compile it - that's OK because every .NET installation includes the C# compiler, CSC.EXE: Compiling C# Code at Runtime[^]
You can then run it using Process.Start (if it compiles cleanly): Process.Start Method (System.Diagnostics)[^]


你不能执行cs文件,cs文件是j你是一个文本文件。 IDE将该文本转换为可以运行的已编译代码。
You can't execute a cs file, a cs file is just a text file. The IDE converts that text into compiled code that can be run.


您不能直接调用它。



你能做什么选择,编译,然后在调用程序中即时执行
You cannot invoke it directly.

What you can do is select, compile, and then execute on-the-fly within the calling program


这篇关于C#通过我的应用程序调用资源管理器中的.cs文件[已解决]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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