without C#: How to include dependent DLLs?

visual studio package dll into exe (5)

I know it's an old question, but I believe my answer might help someone.

I was able to successfully compile and run examples using c# gdal by doing the following:

  1. Downloading GDAL sdk from http://www.gisinternals.com/ (64 bit in my case)
  2. Executing the SDKShell.bat script to set the system environment paths, etc.
  3. Creating a project in Visual Studio. And referencing all .net dlls (the ones that names end with _csharp.dll), located in \bin\gdal\csharp\ inside downloaded SDK
  4. Setting platform target in Visual Studio project settings to x64 to get rid og bad image format exceptions. The last step wouldn't be necessary if I'd choosse 32bit version of SDK to work with.

I did not install fwtools at all. It seems like the last build of fw_tools is relatively old, and sdk is still maintained.

I am using a 3rd party API which is defined in 2 DLLs. I have included those DLLs in my project and set references to them. So far so good.

However, these DLLs have at least one dependent DLL which cannot be found at runtime. I copied the missing DLL into the project and set the 'Copy to output' flag but without success.

What should I be doing here to tell the project where it should find the dependent DLL?

Clarification I tried adding a reference to the missing DLL but as it wasn't recognised as a .Net component. In desperation, I added it directly to the output folder but without success.

Finally, I installed the API on the PC and it all worked. The installation sets the PATH variable and the DLL is found in the installation folder. But how to tell the project to look in one of its internal folders?

It sounds like you need to better understand the third-party library and how it uses its own dependencies. If the installation of the API solves the problem, but copying the files manually does not, then you're missing something. There's either a missing file, or some environment variable or registry entry that's required. Two things that will really help you in this is the depends tool (which is part of the C++ installation) and procmon, which will tell you all the registry keys and files that get used at runtime.

If you're lucky, it's just a file that you're missing. If that's all it is, you can use the "Build Events" section of the project to copy the needed files to the right location on a successful build. If not, you're going to have to solve this some other way - either by requiring the API be installed, or rolling your own installation project.

How are you deploying? Just flat files? If so, it should work as long as the file ends up in the project output directory. Does it?

If you are using another deployment, you will need to tell that engine to include it. This is different for each of msi/ClickOnce/etc.

Exception while using GDAL in C#

As an update to this there is now GDAL maintained by the SharpMap team as a nuget package here which is updated regularly. You'll need to install both the "GDAL.Native" and "GDAL" package for your project to use the GDAL library. Once installed via nuget, they'll automatically create a "GdalConfiguration.cs" that you call into to initialize the GDAL paths before starting. The only thing to note is the packages are setup to automatically copy their appropriate GDAL libraries to your output build directory. If you need to deploy the application you'll have to do a bit of extra effort.

You can either slowly add the downstream dependencies as references to your project. This is cumbersome, and somewhat fragile

Or your could use a tool like "Depends.exe" from microsoft to inspect your top level assemblies and get a reference list to the dependencies.