Search code examples
c#dllexemanifest

How do I check if dll or exe file has an application manifest in C#


I am writing some tests for a build system and I ran into a problem I couldn't really solve in C#.

I need to check multiple exe and dll files if they have a application manifest.

I have seen some people solve this problem by just seeing if the User executes some program with elevated privileges like here and some solving it with C++ like here for example. However this doesn't work in my case since I am not executing these exe and dll files.

Isn't there some easy way to check if there is an application manifest attached to an exe or dll file?

TIA.


Solution

  • I think I have found a solution for the problem.

    Keep in mind that this is probably not the best solution and I am sure that if you were to do more research on the topic you would find a better solution.

    However I had to come up with one in a shorter amount of time, so here is the solution I came up with.

    string exeFileData = File.ReadAllText(@"path\file.exe");
    string dllFileData = File.ReadAllText(@"path\file.dll");
    
    if (exeFileData.Contains("manifestVersion"))
    {
        Console.WriteLine("Exe contains a manifest");
    }
    
    if (dllFileData.Contains("manifestVersion"))
    {
        Console.WriteLine("Dll contains a manifest");
    }
    

    It is probably the simplest solution that you could come up with.

    Just read all the text from a exe or dll file, since the application manifest is clear text and in xml format contained in the exe or dll file, so we just have to check if some string that exists in the added manifest, in my example the manifestVersion attribute, is contained in the exe or dll file.

    Like I said this is surely not the best solution but I found it working for me.