Question .NET Standard Projects - No DEBUG Constant

Neal

Forum Admin
Staff member
Joined
Apr 15, 2011
Messages
246
Location
VA
Programming Experience
10+
Why in a .NET Standard 2.0 Class Library in Debug in the BUILD section of the project properties is the DEBUG constant not checked?
 
Good question. I never noticed that before... And TRACE is enabled for both Debug and Release. So strange.
 
And even more interesting, the right thing seems to happen even without the checkbox being checked...

This is my .NET Standard 2.1 library contents:
TestCoreLibrary: Foo.cs:
using System;

namespace TestCoreLibrary
{
    public class Foo
    {
        public void DoIt()
        {
#if DEBUG
            Console.WriteLine("DEBUG");
#else
            Console.WriteLine("Release");
#endif
        }
    }
}

And this is my .NET Core Console app:
ConsoleApp: Program.cs:
using System;
using TestCoreLibrary;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
#if DEBUG
            Console.WriteLine("Main: DEBUG");
#else
            Console.WriteLine("Main: Release");
#endif
            new Foo().DoIt();
        }
    }
}
 
Also looks to have been reported last October:

And the documentation says this:
Other predefined symbols include the DEBUG and TRACE constants. You can override the values set for the project using #define. The DEBUG symbol, for example, is automatically set depending on your build configuration properties ("Debug" or "Release" mode).
 
Another weird thing is in .NET Core 3.1 projects (or at least my asp.net core Web API project) there is no Class template. If you right click a folder and choose to add a class it's completely empty, no template contents. If you choose Add New Item then Class isn't even an option to pick from! Very weird!
 
Why in a .NET Standard 2.0 Class Library in Debug in the BUILD section of the project properties is the DEBUG constant not checked?
I see that too for C# project, for VB.Net it is enabled by default.
 
Back
Top Bottom