I'm trying to reference a managed DLL in my .NET project, without copying it into my output directory. So, when my program runs, it runs the DLL from the location it's installed - wherever that is. The problem lies in the fact that this managed DLL calls unmanaged DLLs. When I try and reference the managed DLL, it throws a FileNotFound Exception - Could not load file or assembly 'CharacterGen' or one of its dependencies. The system cannot find file specified
. When I set my output to be within the same directory as the DLL I'm referencing, everything works fine. The usual solution would be to also reference the DLLs which are called from within the other assembly. However, I can't reference unmanaged assemblies from my managed program.
Is there a way to reference a managed DLL which calls unmanaged DLLs?
If you asking how to get visual studio to copy the unmanaged DLL to your output directory you can do this:
If your solution has a bunch of unmanaged C++ dlls that you're building and one or two managed C# assemblies, and they all need to be in the same folder, I've found that setting all of the projects to use the same output directory to be the easiest to manage solution. -- This way, if projects get renamed later, etc., they all still end up in the right location, and if you add a new project later, you don't have to figure out what dlls need to be added in, you just need to set the
OutputPath
to the exact same thing as your other projects.To achieve this I set the
OutputPath
property (for all Configurations and Platforms, for every project) to$(SolutionDir)\bin\$(Configuration)
.Generally, I don't include
$(Platform)
in the path, because for the unmanaged projects it's namedWin32
and for the managed it's namedx86
-- but if you really need platform segregation you can do some conditional logic in the .csproj files to create a new property that has the desired value.