Determine whether App is running is Visual Studio

  • Thread starter Thread starter cody
  • Start date Start date
C

cody

Is there a way to do:

#if APP_IS_RUN_IN_VS
path = ".\..\..\..\myfile.rpt";
#else
path = "myfile.rpt";
#endif

I don't want to put the files into debug/bin dir since they woulbe be
deleted on rebuilt then.
 
If we assume that you always use the Debug configuration to run the project
from the IDE,
you can use the following condition:

#if DEBUG
path = ".\..\..\..\myfile.rpt";
#else
path = "myfile.rpt";
#endif
 
If we assume that you always use the Debug configuration to run the
project
from the IDE,
you can use the following condition:

#if DEBUG
path = ".\..\..\..\myfile.rpt";
#else
path = "myfile.rpt";
#endif


But I cannot assume this. Additionally, Debug is still set if the app is not
run in VS. Is there another way?
Maybe I can instruct VS to automatically copy these files into the bin/obj
dirs so there is no need to change the path, but how?
 
You can use this:

Public Shared Function IsInIDE() As Boolean



If System.Diagnostics.Debugger.IsAttached Then

'The application is currently running from within the IDE.

Return True

Else

'The application is currently running as a compiled application.

Return False

End If

End Function


--

HTH

Éric Moreau, MCSD
Conseiller Principal / Senior Consultant
Concept S2i inc.(www.s2i.com)
 
You can use this:
Public Shared Function IsInIDE() As Boolean



If System.Diagnostics.Debugger.IsAttached Then

'The application is currently running from within the IDE.

Return True

Else

'The application is currently running as a compiled application.

Return False

End If

End Function


Thank you, but what if I start the app in VS without debug?
What would you do if you have a file that your application needs to open and
you don't want it to copy in the bin/obj directory every time manually?
There must be a way!
 
BTW - are you that sure that the whole contents of the Debug folder is
erased every time the project is built? I remember I copied necessary data
files to bin\Debug rather frequently and they remained intact regardless of
many subsequent builds...
 
BTW - are you that sure that the whole contents of the Debug folder is
erased every time the project is built? I remember I copied necessary data
files to bin\Debug rather frequently and they remained intact regardless of
many subsequent builds...


VS clears that folder if you do a complete rebuild. regular builds don't do
this.
 
Just out of interest, why not just place your files in a directory elsewhere
on the hd and just reference it from there? Or even place them in your
project directory (up from debug) and reference it using "..\filename"?

Kieran
 
Just out of interest, why not just place your files in a directory
elsewhere
on the hd and just reference it from there? Or even place them in your
project directory (up from debug) and reference it using "..\filename"?


Sure I could do this and all would be fine if I run my program from Visual
studio.
But sometimes I need to deploy my app and I do not want to have a path in
the
following form "c:\cody\projects\myapp" or "..\..\myfile.rpt", since my
customer
will neither have Visual Studio installed nor does he have a directory named
"c:\cody\projects".
 
There are ways to bypass this problem.
You could use Application.StartupPath and make a sub directory for the
file.
You can put the file under the local user in Documents and Settings using
Application.LocalUserAppDataPath.
You can use a registry entry or a config file specifying the location of
the file.


I wanted the files to be in the same directory where the executable file is.
 
There are ways to bypass this problem.
You could use Application.StartupPath and make a sub directory for the
file.
You can put the file under the local user in Documents and Settings using
Application.LocalUserAppDataPath.
You can use a registry entry or a config file specifying the location of
the file.

Happy coding!
Morten Wennevik [C# MVP]
 
Application.StartupPath then

this gets me:

D:\cody\projects\myapp\MainWindow\bin\Debug

But I don't want to put the files into the "bin\Debug" since VS sometimes
erases it.
I thought on including the files as resource. I embedded the files into my
project and set the type on "embedded resource". So now the big question is
how to load them.
 
cody said:
[...]
But I don't want to put the files into the "bin\Debug" since VS sometimes
erases it. [...]

I just tried creating a new text file in 'bin\Debug' then rebuilding the
solution multiple times, and the file wasn't deleted. I'm using VS.NET
2003...
 
But I don't want to put the files into the "bin\Debug" since VS
sometimes
erases it. [...]

I just tried creating a new text file in 'bin\Debug' then rebuilding the
solution multiple times, and the file wasn't deleted. I'm using VS.NET
2003...

I also tried it now and it didn't disappear either. I could swear VS would
clear the bin/obj folder on complete rebuilds.
Maybe it was in another version, maybe it was C++. :(
Thanks, this should have solved my problem for now :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top