0

I got a c# project in Visual Studio of a cloud system with services inside a docker. I am searching for a way to detect in the code:

  1. If the code running in a real deployment in a production environment or if it's running locally because the user clicked on the play button in VS (Is it also possible to refine the VS part and distinguish between running in debug mode or starting the program without debugging)?

  2. Read data according to the mode the code is running from step 1.

Pseudo code of what I mean:

string someData = null;
if(IsRunningFromPlayButtonInVS()) someData = GetVSData();
else if(IsRunningInRealDeployment()) someData = GetDeploymentData();

Is such a thing possible? Even if you know only the first section of detecting the mode I'm running that can also be useful.

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • Maybe you can try [`#if preprocessor directive`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if) to check if in debug mode. – 大陸北方網友 Dec 15 '20 at 02:22

1 Answers1

0

Assuming the program is deployed to a different directory than where it is built then you could test the application's directory to see whether it is the build directory or the deployment directory or elsewhere. The best way to get application folder path questions shows many ways of finding the directory.

You can also detect if youre running in a debug or release executable at runtime.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
  • From the answers of detecting a debug mode i didn't understand if its better to use #if or to check if a debugger is attached – CodeMonkey Dec 15 '20 at 07:30