开发者

How can I determine if I am running an application from the Visual Studio IDE?

开发者 https://www.devze.com 2023-02-28 15:31 出处:网络
I have written a Winforms application that will function in two ways: If no command line arguments are supplied, the main form of the application will show, and the user开发者_开发问答 can interact

I have written a Winforms application that will function in two ways:

  1. If no command line arguments are supplied, the main form of the application will show, and the user开发者_开发问答 can interact with the application.

  2. If a command line argument is supplied, the main form is not shown, and the application perfoms the operation defined by the command line argument and then shuts down.

I would also like to display the command line argument to the user in a MessageBox, if the application is run from the Visual Studio IDE and the command line arugment has been specified in the Properties\Debug page.


You could always use System.Diagnostics.Debugger.IsAttached


If you need to determine the "parent process" of a given process, here is a link on SO: How to get parent process in .NET in managed way

That being said, what I would do instead is split your program in two: one class library (a DLL, that will contain all the real meat of what your program does) and one EXE that references this class library. This way you can create a 3rd project as a VS Addin that will also reference this class library, but will implicitely be aware that it's running from VS.

0

精彩评论

暂无评论...
验证码 换一张
取 消