Can I embed other files in a DLL?

20,539

Solution 1

Sure, you can embed a resource in your DLL. Then at runtime you just do:

Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("com.stackoverflow.plugin.example.Foo.pdf");

This would give you a stream to the Foo.pdf file embedded in your DLL. Pay attention to the fact that the resource name has to be scoped by the namespace of the type from which you're invoking the method.

Solution 2

Sure, just make them "Embedded Resource" in VS.NET (assuming you're using it). You can then read them via resource APIs or simply with Assembly.GetManifestResourceStream().

Solution 3

Yes, you can do that.

Add a resource file to your project. Open the resource file in Visual Studio and click Insert Resource. You can select different types of resources, including external files.

Visual Studio will generate code for you so that you can retrieve the files as byte arrays at run time from their names through the Resources identifier.

Share:
20,539
Eric Anastas
Author by

Eric Anastas

Updated on July 09, 2022

Comments

  • Eric Anastas
    Eric Anastas almost 2 years

    I'm writing a plug-in for another application through an API. The plug-ins are distributed a DLLs. Is it possible to embed other files in the DLL file like pdfs, images, chm help files etc... I want to be able to provide documentation with my plug-in but I'd still like to retain the ability to distribute the plug-in as a single file the user can just drag and drop onto the application to install.