[英]How can I use a console application with my website in Visual Studio?
Please read the following in the Visual Studio 2012 context: 请在Visual Studio 2012上下文中阅读以下内容:
I have two projects--one is a website (File --> New Website) and another is a console application (File --> New Project --> Windows --> Console Application). 我有两个项目-一个是网站(文件->新网站),另一个是控制台应用程序(文件->新项目-> Windows->控制台应用程序)。 I am the author of the former.
我是前者的作者。
The standalone app fakes the input by hardcoding it, runs through some code, and creates an output. 独立应用程序通过对输入进行硬编码来伪造输入,通过一些代码运行并创建输出。 It uses dlls from a local installation of software that I have installed on my machine to generate this output.
它使用我在计算机上安装的本地软件安装中的dll生成此输出。
I read on MSDN that I cannot add a console app to a website solution in a useful manner. 我在MSDN上读到我无法以有用的方式将控制台应用程序添加到网站解决方案中。 So, if I compile the console app to output a dll instead of an exe, can I reference that dll in my website?
因此,如果我编译控制台应用程序以输出dll而不是exe,可以在我的网站中引用该dll吗? How can I do this exactly?
我该怎么做呢? I would need to pass the input value from the website to the dll, and return meaningful results from the dll.
我需要将输入值从网站传递到dll,并从dll返回有意义的结果。 Is this possible?
这可能吗?
Yes, you describe a feasible way to solve this. 是的,您描述了解决此问题的可行方法。 You need to create a class library project, add source code from console application to it, except the the class that has
static Main
method and modify (add to) that source code such that there is a class that you will be able instantiate from the code in your web application after you add the class library assembly to the web application as a reference. 您需要创建一个类库项目,将来自控制台应用程序的源代码添加到该类库项目中,但具有
static Main
方法的类除外,并修改(添加到)该源代码,以便可以从中实例化一个类。将类库程序集添加到Web应用程序中作为参考后,在Web应用程序中添加代码。 This class will have a method with appropriate parameters, that you will call. 此类将具有一个带有适当参数的方法,您将调用该方法。 All this assuming that the task that console application code performs is fast and will not create noticeable delay in the web application response.
所有这些假设控制台应用程序代码执行的任务都是快速的,并且不会在Web应用程序响应中造成明显的延迟。 If the task takes a long time, you will either have to run it in a background thread or move it outside the web application - the latter is significantly more involved.
如果该任务花费很长时间,则您要么必须在后台线程中运行它,要么将其移到Web应用程序之外-后者的参与程度明显更高。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.