How to include another project Console Application exe in an Asp.Net website?

有些话、适合烂在心里 提交于 2019-12-01 03:51:24

问题


I've got two projects: a .Net 4.0 Console Application and an Asp.Net 4.0 Website (they are in the same solution). Now I'd like to include the console application (its .exe) in the web application, because I need to run it on the server when the user clicks on a certain button.

Now I would like to include it in a way that the console application will be updated whenever I recompile the solution, so it stays up to date.

So... how can I include my .exe in my web app?

Ps. Referencing doesn't work:


回答1:


Have you tried just adding it as a "Project Reference" to the Website project? Right click on the website project, select "Add Reference..." and switch to the "Projects" tab.

A quick test here showed that by doing that the output of the console app project (the .exe) was copied to the /bin folder of the website when I built the solution.

You should then be able to use your standard deployment mechanisms to ensure that this is copied to the server at the same time as the other libraries.


Apologies, you're right, this doesn't work with a WebSite project, only with a Web Applciation.

In this case, you'll have to use a "Post Build" event on your console app to copy it to the website's folder.

Right click on the console app project in the Solution Explorer and select "Properties" or when you have a file from the project open use the "Project" menu.

Then on the "Build Events" tab, update the "Post-build event command line" to something like:

xcopy "$(TargetDir)$(TargetFileName)" "c:\users\[UserName]\Documents\Visual Studio 2010\Websites\[ProjectName]\bin\" /D /S /I /Y

If you want to include the PDB and config files as well then something like the following would be better:

xcopy "$(TargetDir)$(TargetName).*" "c:\users\[UserName]\Documents\Visual Studio 2010\Websites\[ProjectName]\bin\" /D /S /I /Y



回答2:


On the project you are trying to reference, make sure you change the output type to class Library. This should fix it.




回答3:


The exe option is available if you, use the browse tab instead.



来源:https://stackoverflow.com/questions/5488160/how-to-include-another-project-console-application-exe-in-an-asp-net-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!