Visual Studio or Eclipse Code Review Rule

Asked

Viewed 90 times

5

I wonder if there is any add-in for visual studio that ensures that while I am in development environment make some changes but when I generate the build of the project, this commented part is reviewed warning me that in production will not work

Example:

// DESENVOLVIMENTO
string servidor = "umaString";

// PRODUÇÃO
string servidor = "outraString";

Sometimes it is necessary to make these comments and force certain actions only in development environment but when Gero build sometimes I forget to reverse this change and I have rework

Thanks in advance

  • William, you don’t need to tag visual-studio when your problem is unrelated to the IDE. See this question http://answall.com/q/101691/18246

  • 2

    And, answering your question, you can have this effect using preprocessing, with #if DEBUG.

  • kkk true jbueno. Congratulations to you Thank you

1 answer

6


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

https://msdn.microsoft.com/pt-br/library/4y6tbswk.aspx

It is not necessary to define the DEBUG variable, because Visual Studio itself already does this, when you compile an executable as DEBUG, it already defines this variable internally, otherwise it is not defined. You can also set other variables for numerous 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");
#else
        Console.WriteLine("DEBUG and MYTEST are not defined");
#endif
    }
}
  • 2

    If you set DEBUG, it won’t always be true?

  • I already adjusted the answer, it will depend on how you generate the version, if you generate as Release the DEBUG variable is not defined, if you generate as Debug, it will always be defined.

  • 2

    You see, you’re setting DEBUG. In that case, even if I run as Release the code will be executed because there is an explicit instruction to define DEBUG (#define DEBUG). Can you understand?

  • yes, I’ll edit the answer again to see if it’s clearer.

  • 2

    Oops, I hadn’t seen the edition. It’s straight =) +1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.