{"id":379,"date":"2014-12-02T09:23:45","date_gmt":"2014-12-02T08:23:45","guid":{"rendered":"http:\/\/dev.flauschig.ch\/wordpress\/?p=379"},"modified":"2014-12-02T09:57:49","modified_gmt":"2014-12-02T08:57:49","slug":"putting-assemblies-dependencies-in-a-subfolder-in-a-c-project","status":"publish","type":"post","link":"http:\/\/dev.flauschig.ch\/wordpress\/?p=379","title":{"rendered":"Putting assemblies \/ dependencies in a subfolder in a c#-project"},"content":{"rendered":"<p>An application folder can look quite crowded if you have some assemblies or 3rd party references in use.<\/p>\n<table style=\"border-color: #ffffff;\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td style=\"border-color: #ffffff; vertical-align: top;\">Like in this image:<\/td>\n<td style=\"border-color: #ffffff; vertical-align: top;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-383 size-medium\" style=\"border: 1px solid black;\" src=\"http:\/\/dev.flauschig.ch\/wordpress\/wp-content\/uploads\/2014\/12\/proj_folder_before-151x300.png\" alt=\"proj_folder_before\" width=\"151\" height=\"300\" srcset=\"http:\/\/dev.flauschig.ch\/wordpress\/wp-content\/uploads\/2014\/12\/proj_folder_before-151x300.png 151w, http:\/\/dev.flauschig.ch\/wordpress\/wp-content\/uploads\/2014\/12\/proj_folder_before.png 261w\" sizes=\"(max-width: 151px) 100vw, 151px\" \/><\/td>\n<td style=\"border-color: #ffffff; vertical-align: top;\">Wouldn&#8217;t it be much nicer to have it look like:<img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-382 size-full\" style=\"border: 1px solid black;\" src=\"http:\/\/dev.flauschig.ch\/wordpress\/wp-content\/uploads\/2014\/12\/proj_folder_after.png\" alt=\"proj_folder_after\" width=\"262\" height=\"164\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>When it comes to having dll-files somewhere else than in the &#8220;app-folder, things can get quite cumbersome.<\/p>\n<p>Here&#8217;s how to achieve this:<\/p>\n<p><strong>Moving files into subfolder<\/strong><\/p>\n<p>There are multiple ways to achieve this.<\/p>\n<p>One way is to add a solution folder with the desired name of the subfolder and add the assemblies \/ dependencies as files (best way is to add them as links) there with build <code>action=none<\/code> and <code>copylocal=true<\/code>. If you add assemblies there used as references as well, set the <code>copylocal<\/code> for the references to <code>false<\/code>.<\/p>\n<p>Another way is to leave the dll&#8217;s where they are (just adding dependent dlls as files\/links into the project&#8217;s root directory) and create a post-build event or (my preferred way) add an <code>AfterBuild<\/code> task to the project to move all *.dll files into the subfolder.<\/p>\n<p>For the post-build event just edit the project&#8217;s properties and add the commands into the post-build in the Build Events.<\/p>\n<p>For the preferred way, just edit the csproj file (unload the project, then right-click and edit, open in any text-editor or use the visual studio addon <a href=\"https:\/\/visualstudiogallery.msdn.microsoft.com\/b346d9de-8722-4b0e-b50e-9ae9add9fca8\" target=\"_blank\">EditProj<\/a>) and add the following code at the bottom:<\/p>\n<pre class=\"lang:default decode:true \">&lt;Target Name=\"AfterBuild\"&gt;\r\n\t&lt;ItemGroup&gt;\r\n\t\t&lt;FilesToMove Include=\"$(OutDir)*.dll\" \/&gt;\r\n\t&lt;\/ItemGroup&gt;\r\n\t&lt;Move SourceFiles=\"@(FilesToMove)\" DestinationFolder=\"$(OutDir)Libs\" \/&gt;\r\n&lt;\/Target&gt;<\/pre>\n<p>This example code uses the folder &#8220;Libs&#8221; for the dlls. Feel free to adjust it to your needs.<\/p>\n<p><strong>Telling the application\u00a0to search other directories for libraries<\/strong><\/p>\n<p>This is actually quite simple. The current way of doing this is to edit the app.config and adding the following code into the configuration:<\/p>\n<pre class=\"lang:default decode:true \">&lt;runtime&gt;\r\n\t&lt;assemblyBinding xmlns=\"urn:schemas-microsoft-com:asm.v1\"&gt;\r\n\t\t&lt;probing privatePath=\"Libs\" \/&gt;\r\n\t&lt;\/assemblyBinding&gt;\r\n&lt;\/runtime&gt;<\/pre>\n<p>That&#8217;s it. With those two things you can have a &#8220;clean&#8221; application folder where all the assemblies or 3rd-party dependencies (like sqlite or sqlce dlls) are nicely stored in a subfolder<\/p>\n","protected":false},"excerpt":{"rendered":"<p>An application folder can look quite crowded if you have some assemblies or 3rd party references in use. Like in this image: Wouldn&#8217;t it be much nicer to have it look like: When it comes to having dll-files somewhere else than in the &#8220;app-folder, things can get quite cumbersome. Here&#8217;s how to achieve this: Moving &hellip; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[4,3],"tags":[],"class_list":{"0":"entry","1":"post","2":"publish","3":"author-roemer","4":"post-379","6":"format-standard","7":"category-csharp","8":"category-programming"},"acf":[],"views":3651,"_links":{"self":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/379"}],"collection":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=379"}],"version-history":[{"count":0,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/379\/revisions"}],"wp:attachment":[{"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=379"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/dev.flauschig.ch\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}