Kees C. Bakker Kees C. Bakker - 1 month ago 5
ASP.NET (C#) Question

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

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:
enter image description here

Answer

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