Change Dll Folder In Visual Studio 2008 C# - visual-studio

I have 2 projects in my solution. The first one is a console application, and the second is a dll, used (referenced) by the console. When I build my solution (release) I get one EXE file and one DLL file, because copy local is true (if I set it to false, it doesn't run).
How can I store that DLL file in a subdirectory? If my output folder is C:\123\, and there's the EXE file, I want all my DLLs to be in C:\123\Dll\.

You should be able to use the probing element to specify which paths your application should use when attempting to resolve dll dependencies.
Example:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="123;123\dill"/>
</assemblyBinding>
</runtime>
</configuration>
Also you can use the Post-build event command line to copy your dll's to a particular directory.

Related

Organizing Dependencies

I'm trying to organize my unmanaged .dll dependencies in my Visual Studio solution but unless the DLLs are strewn about the top level of my solution they do not get built into the application's directory and then the application fails to run. I have done a lot of Googling on the subject and there seems to be a solution in the form of an app.config setting:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatepath="lib" />
</assemblybinding>
</runtime>
</configuration>
I have a folder in my solution called "lib" and Copy Local is set to true for all files in the folder but the application is still unable to run. How can I keep my Visual Studio solution organized without breaking my application?
The only way I have found to solve this issue is through windows .bat files.
If there is a way to encode extra search paths into an unmanaged executable, I would like to know!
Here is an example of what I do:
SET PATH=$~dp0plugins\MY_PLUGIN\Debug;%PATH%
vcvars32.bat
devenv build\MY_PROJECT.sln
The first line adds the path of where I want visual studio to find my dll's in.
The second line ensures that the 'right' visual studio will open up. IE: if I have my environment set for VS2010, I dont want VS2012 to open up by default.
The last line invokes the IDE to open up my sln file.
The visual studio that opens up now has a path to the Debug folder of one of my plugins. When I debug my application, the correct dll will be found, loaded, and debugged with no issue - I verify this under the Debug->Windows->Modules panel.
This only works for the Debug configuration. If I want to run the release configuration, I change the .bat file to say 'Release', close Visual Studio and re-run the .bat file.
I apply this same pattern to running my executable. Set up the environment of where I want my dll's to come from and then execute my executable:
SET PATH=$~dp0plugins\Debug;%PATH%
... Repeat for other dll locations
"%~dp0Debug\MY_EXECUTABLE.exe" %*
SS64 is an invaluable resource to figure out what you can do in .bat files

DLL not found by Windows Service EXE

I have a .net 4.0 DLL (class library) which is used to execute some operations for a windows service I've created. The executable of the service references this DLL by adding a project reference to the project of the executable. I have also tried a binary reference but the result is the same: InstallUtil fails to install the Windows Service from the EXE since it's unable to locate the DLL.
The system I'm working on is not using GAC registration for locating DLLs. Rather, at post-build the DLL gets copied to a child directory of the one in which the service EXE is located named "lib", and that exe has a matching .config file in which "lib" is referenced using:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
We have multiple .exes and .dlls working like that. The project properties and .config file definitions for all these DLLs and matching EXEs are identical for all we could see.
However, whereas for all others InstallUtil has no problem locating the DLL, here it fails. When I move the DLL to the same location as the EXE, however, all works fine.
The .config file we're discussing is successfully referred for other purposes.
If you have any specific questions please share and I'll answer.
We're clueless.

Relative paths to DLL's for the built app

I wonder if it's possible to make something like this...
I have a project in VS2012 that uses two referenced VS projects (DLLs are being created during compilation) and some other DLLs (external libraries etc.). Now I want to clean up my compilation and place DLLs in two folders: e.g. Internals and Externals.
How to make it possible? The problem is that my compiled .exe app file wants the DLLs to be placed in the main folder (near to it) - so if it needs to load the library from DLL it crashes...
I tried to find something in the web, but ppl only ask about copying DLLs from the reference folders into the output folder. But that's not what I want to do:/
Ok, I have found a solution. I need to add a new item app.config and specify privatePaths:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="InternalsFolder;ExternalsFolder" />
</assemblyBinding>
</runtime>
</configuration>

Post Build event that puts all extra .dlls in bin directory using probing

I have WPF assembly with a bunch of other dlls in my project
I want to move everything except the main assembly and the app.config from the build directory to a subdirectory called bin
this is easy when I add the probing tag to my app.config and do it manually (a cut and paste job)
<configuration>
<connectionStrings>
<add name="ConnectionString" connectionString="..." />
</connectionStrings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="bin"/>
</assemblyBinding>
</runtime>
</configuration>
What i want to do now is automatically move everything that's not the assembly into the bin directory at the end of my build.
so from this
App.exe
App.config
Domain.dll
Application.dll
Framework.dll
to this
App.exe
App.config
bin\Domain.dll
bin\Application.dll
bin\Framework.dll
I'm guessing I could use a bat files with a bunch of move commands in it but i was hoping that there was something a bit more reusable and intelligent than that out there.
For anyone interested what I ended up doing was this
a Post Build Event that looks like this
move $(TargetDir)$(TargetName).* .\..
and I set the build directory to be the actual sub directory so it looked like
[Path to Project]\bin\Release\bin
So instead of working out what to move down a directory (which could be a whole bunch of things) I just took the bits I know I want up a directory.
Big smiley face for me Hooray!

Visual Studio: DLL locations for release

I have a project that I am working on that references a "Common Library (DLL)". In the DevEnv it works fine, however if I build and try to organize my files it doesn't work. Basically if I have things setup like so:
C:\Program Files\MyApp\MyApp.exe
C:\Program Files\MyApp\Common\WPF Commons.dll
C:\Program Files\MyApp\Modules\SomeModule.dll
etc
MyApp.exe doesn't work. It tries to look only in the current directory for the DLL files. So how do I set it up in Visual Studio so that when I build the application knows to look for the DLLs in those other folders?
Oh, and I realize that it does work in Dev because all the DLLs are put in the same folder. I don't want to do that for release though :-/
What you need to do is add a private probing path into the application configuration file. This tells the CLR which directories to look in for extra assemblies.
http://msdn.microsoft.com/en-us/library/823z9h8w.aspx
Sample app.config
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Common;Modules"/>
</assemblyBinding>
</runtime>
</configuration>

Resources