Matt Arnold
Matt Arnold

Reputation: 686

Determining the Configuration of a Calling Assembly for a BuildName Property

Suppose I have a static class with the following property in it:

        /// <summary>
        /// Gets the name of the current build of this assembly or <see langword="null"/> if this is a Release build.
        /// </summary>
        public static string BuildName { get; } = 
#if DEBUG
            "Debug"
#elif TEST
            "Test"
#else
            default(string)
#endif
            ;

This worked when I had the project that contained this code within the solution being built as the project would build in Debug, Test or Release along with the solution.

Now I've moved this project out of the solution so that it can also be used in other products in other repositories. This has unfortunately meant that it's become a static DLL reference that is always a Release build. Now when I use it, BuildName always comes back as null regardless of the configuration of the calling assembly.

How can I define this property so that it returns "Debug" when the calling assembly is in Debug, "Test" when it's in my custom configuration of Test and null when it's in Release?

I've looked into the [Conditional("DEBUG")] attribute but this appears to only be for if you want members to be defined if the pre-compilation symbol passed in is defined in the calling assembly. I always want BuildName defined, I just want its value to change based upon the calling assembly's configuration.

Upvotes: 0

Views: 19

Answers (0)

Related Questions