Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have C# project that uses several libraries as a reference. I put those reference libraries in a subfolder (e.g. folder named References) and I set 'Copy Local' property of those references to 'True' then the application works fine.
However, I want to keep the output folder tidy by keeping those reference files in the subfolder.

What I have tried:

I did that by setting the 'Copy Local' property of those references to 'False' but then the references will not be accessible during runtime. So I need suggestion on how to resolve this problem.
Posted
Updated 13-Jul-22 22:17pm

The system looks in the default locations for libraries: the directory where the executable is stored and the global assembly cache. For other locally developed libraries see Assembly.Load Method (System.Reflection) | Microsoft Docs[^].
 
Share this answer
 
I found the solution. The problem is references placed in References folder are copied to Output folder during project build. The objective is to put the references in References folder instead of the output folder. So we need to do the following three changes.
1) To configure the reference file so that they will not be copied to the Output folder during build. To do this set the CopyLocal property of the reference files to False.

2) To configure the reference files to be copied to References folder. To do that add the following entry in the project file. For example, suppose we have reference called myLib.dll
<contentwithtargetpath include="References\myLib.dll">
<copytooutputdirectory>PreserveNewest
<targetpath>References\myLib.dll


3) To make the runtime to look the references in the References folder we have to add <probing privatepath="References"> in the app.exe.config file.

<runtime>
<assemblybinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatepath="References">

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900