简体   繁体   中英

Run as Windows Service, Console App, or Wpf App in a single VS2010 project

I currently have 3 projects which produces 2 executables

    1. Class library to do work
    1. Windows Service project that uses library #1
    1. WPF App that uses the library #1

The class library is used to perform some client-server interaction.

What I want is to only have 2 projects, the class library, and another that produces an executable that can be run as a Console, WPF, or a Windows Service. Is it possible (or advisable) to do it this way? What should the project output type be?

The main reason is that we have automated scripts to run that expect some fixed file paths. I want to avoid having to duplicate the scripts for the WPF executable and the Service/console executable.

I'm not sure about being able to do WPF, but TopShelf will allow you to run an executable as a console application or as a service.

http://topshelf-project.com/

There are two ways to use TopShelf - exe as a service or using shelving .

To run as a console application you just run yourprogram.exe. To install as a service it's simply yourprogram.exe install.

I know this question is a bit old, but...

You can start a new project as a WPF project, then right-click it in the solution explorer and change "Start As" to console application. Your WPF app will still run exactly the same, but a console window will appear where you can use things like Console.WriteLine() calls.

You could then accept a command-line parameter that tells your application to suppress the rest of the UI, leaving only the console part. I don't think this will allow it to run as a service, though.

You have to go for Windows Communication Foundation aka WCF, Click link to learn basics

http://msdn.microsoft.com/en-us/netframework/dd939784

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM