7

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

1
  • I've updated my answer with a Post Build Event that works a treat with .exe files and its dependent files. Commented Mar 30, 2011 at 16:08

3 Answers 3

8

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
Sign up to request clarification or add additional context in comments.

3 Comments

No, that doesn't work because it states that 'A project must build to a 'dll' extension in order to be referenced.'
@Kees - Ah, sorry, yes, the joys of a Website rather than a "Web Application".
No problem. I've been using a similar mechanism to move libraries to a test machine for some time now ;)
1

Output Type

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

Comments

0

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

1 Comment

You'd probably want to change the output directories of the Debug and Release builds to use a common directory in that case, which would make it harder to know whether you had a debug or release build, otherwise you'd be locked into using the one you'd browsed to first - it wouldn't notice that you'd done a release build for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.