简体   繁体   English

如何在Visual Studio中的网站上使用控制台应用程序?

[英]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.

相关问题 如何将Visual Studio代码上的本地网站推送到在Azure上部署的Webapp - How can I push my local website on visual studio code to a webapp I deployed on Azure 有没有办法可以在 visual studio code IDE 和 Live 服务器之外运行我的 tailwind CSS 网站? - Is there a way I can run my tailwind CSS website outside the visual studio code IDE and Live server? 如何在我的网站的SQL查询中使用会话变量? - How can i use session variables for a SQL Query for my website? 如何在我的网站上使用Apple符号? - How can I use Apple symbols on my website? 我可以使用 OneDrive 作为我网站的后端吗 - Can I use OneDrive as backend for my website 如果他们没有我的用户,如何让我的用户自动下载我用于我的网站的字体? - How can I make my users automatically download the font I use for my website if they don't have it? 如何在 Visual Studio 中加载图像? - How I can load an image in Visual Studio? 如何在网站上放置 spring 应用程序? - How can I put a spring application on website? 如何在我的应用程序中使用数据库 sqlite? - How can i use the database sqlite in my application? 如何在我的天气应用程序中使用天气图标 - How Can I Use Weather Icons on My Weather Application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM