c# – Visual Studio or Eclipse code review rule


I would like to know if there is any add-in for visual studio that ensures that while I'm in the development environment, I make some changes, but when I generate the project build, this commented part is revised warning me that in production it won't work


string servidor = "umaString";

string servidor = "outraString";

Sometimes it's necessary to make these comments and force certain actions only in the development environment, but when I generate a build, I sometimes forget to revert this change and I have rework

Thank you very much in advance


You can use the #if DEBUG operator for this, as demonstrated in the Microsoft documentation:


It is not necessary to define the DEBUG variable, because Visual Studio itself does this, when you compile an executable as DEBUG, it already defines this variable internally, otherwise it is not defined. You can also define other variables for any number of cases you need.

// exemplo definindo a variável MYTEST, que também pode ser usada para verificações adicionais
#define MYTEST
using System;
public class MyClass 
    static void Main() 
#if (DEBUG && !MYTEST)
        Console.WriteLine("DEBUG is defined");
#elif (!DEBUG && MYTEST)
        Console.WriteLine("MYTEST is defined");
#elif (DEBUG && MYTEST)
        Console.WriteLine("DEBUG and MYTEST are defined");
        Console.WriteLine("DEBUG and MYTEST are not defined");
Scroll to Top