Check if an executable or DLL is build in Release or Debug mode

Recently I ran into problem when I tried to pass std::string and std:wstring types between DLLs. Simply hardcoded const std::string passed from one DLL to another gets completely wrong transmitted. It looks like something with encoding is wrong but it turns out somehow I had compiled those two DLLs with deferent configurations. One was Debug another was Release build. Since I had over 50 executables and libraries, static and dynamic, interlinking with each other I had to find out quickly which ones were build wrong configuration.

.NET offers very nice helper class FileVersionInfo with FileVersionInfo.IsDebug property.

The FileVersionInfo properties are based on version resource information built into the file. Version resources are often built into binary files such as .exe or .dll files; text files do not have version resource information. Version resources are typically specified in a Win32 resource file, or in assembly attributes. The IsDebug property reflects the VS_FF_DEBUG flag value in the file's VS_FIXEDFILEINFO block, which is built from the VERSIONINFO resource in a Win32 resource file.

I’ve wrote very simple C# console application that accepts directory path as input parameter. It iterates trough all .exe, .dll and .lib files and writes out to .txt file if it was build with Debug or Release configuration.

Here very short and simple code listing:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConfigChecker
    class Program
        static void Main(string[] args)
            string inputPath = string.Empty;
            if (args.Length == 1 && Directory.Exists(args[0])) 
                inputPath = args[0];    
                Console.WriteLine("Input path does not exist. Check input arguments.");

            string[] searchExtensions = { ".dll", ".exe", ".lib" };
            var files = Directory
                        .GetFiles(inputPath, "*.*", SearchOption.TopDirectoryOnly)
                        .Where(file=> searchExtensions.Any(ext => file.ToLower().Contains(ext)))

            uint releaseCount = 0;
            uint debugCount = 0;
            StreamWriter sw = new StreamWriter("output.txt", false);
            foreach (var file in files)
                FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(file);


                if (fileVersionInfo.IsDebug)
            sw.WriteLine("Debug: " + debugCount.ToString());
            sw.WriteLine("Release: " + releaseCount.ToString());

            Console.WriteLine("Output successfully written to: " + new FileInfo("output.txt").FullName);

Here is output when we call it with “C:\Windows\System32” parameter for example:

C:\Windows\System32\XAudio2_7.dll		Release
C:\Windows\System32\XAudioD2_7.dll		Debug
C:\Windows\System32\xcopy.exe		Release
C:\Windows\System32\xinput1_1.dll		Release
C:\Windows\System32\xinput1_2.dll		Release
C:\Windows\System32\xinput1_3.dll		Release
C:\Windows\System32\XInput9_1_0.dll		Release
C:\Windows\System32\xlive.dll		Release

About me

Bizic Bojan is Co-Founder of Amida IT-Services GmbH and Software Architect with focus on .NET, C++, Python and Cloud Native solutions. 



The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.