A common (and particularly sane) way to solve your problem is to have a solution containing two projects. The first project should be a library (statically or dynamically linked, it doesn't matter) that contains most of your code. The second project should be an executable that references the library you've created in your first project.
Do it this way and a single build of your solution will produce both the executable and the library.