How to Place DLLs in Subdirs

E

Ecke

Hi,

i have writte 3 projects, 1 application (.exe) and 2 DLLs.
In the application i use the references to add the 2 DLLs to work with
their namespaces and functionallity.

But the application always copys the DLLs in its own diretory.
I want to have my own structure

e.g.:
C:.
¦---Application Directory
¦ +---Settings
¦ +---Dll Directory


And the application should look into the dll dir to find the DLLs, but
it only looks in its own directory and in the Windows system path...

Any idea how to make my application running in my preferenced directory
structur


greetz
Ecke


(Sorry for bad english :))
 
N

nemtsev

It's behavior by design to copy all dependend components to the currend
folder, due to security and robust reasons.
There are several ways to avoid it

1) put your dlls into GAC
2) use <codebase> of config file to specify location
 
E

Ecke

I am not very experienced in VS2005.

I have two C++/CLR Projects where i create 2 namespaces (1 per dll).
First is the PCheck.dll with the Declaration:

#pragma once
using namespace System;

namespace CHECK{

// Class declarations...

}


And second is the PTry.dll with the Declaration:

#pragma once
using namespace System;

namespace TRY{

// Class declarations...

}


Then (in my Application) i used the Reference Link to Browse for the
DLL Files.
Then the VS2005 copys automatically the dlls in the temp dir of my
Application Project.


In my application code i wrote:

using namespace CHECK;
using namespace TRY;

// Rest of Form Code...



And now i compile my project. Everything works fine as long as the dlls
and the exe are in the same directory (the Debug dir), but when i copy
the dlls in a subdirectory (which is called dll), nothing works,
because the exe can't find the dll files, of course.

But what must i do to tell my application to search for the dlls in the
dll subdirectory.
Can you give me please a step by step explanation.


greetz and thanks
Ecke
 
C

Chris Dunaway

In your App.Config file in the Configuration Section add something like
this:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="DllPathSubDirHere"/>
</assemblyBinding>
</runtime>

The privatePath must be a sub-directory under the main application
directory. It cannot be elsewhere on the machine.
 
E

Ecke

Sorry, but which config file?

I searched everything...

Or did you mean the *.vcproj File ?
 
N

nemtsev

For your UI app create new documet and choose App.config type from
newDocument window of VS
Afterward add codebelow into this config file. In Codebase node locate
your own dll path.

When app UI starts (after compile u will get Appname.config file nearby
your exe file), it will use this config file to load all dependent
components that are not in localdirectory/GAC reading <Codebase> node

<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top