title: Adding a native DLL path to managed console application
body: <p>I have VS2010 solution with 3 projects:</p>
  
  <ol>
  <li>A native (C++) DLL</li>
  <li>A managed (C#) DLL that uses the native DLL</li>
  <li>A managed (C#) console app that uses the managed DLL</li>
  </ol>
  
  <p>I can set the managed DLL as a Reference to the console app, but I cannot set the native DLL as such a Reference.</p>
  
  <p>To run the console app from within VS2010 without a crash, I must copy the native DLL to the .exe folder.</p>
  
  <p>I have 2 questions:</p>
  
  <ol>
  <li>How can I add the native DLL to the DLL search path, so that I don't have to do a manual copy?</li>
  <li>How can I do this so that each configuration (Debug/Release) takes the correct DLL version?</li>
  </ol>
  
  <p><strong>More Detailed Solution</strong> - due to <a href="https://stackoverflow.com/a/14224133/135862">Tilak's answer</a>:<br>
  Here are more newbie friendly details based <a href="https://stackoverflow.com/a/14224133/135862">Tilak's reply</a> below:  </p>
  
  <ol>
  <li>Add the native DLL as a file (Add existing file...) to the managed console project.</li>
  <li>In the project properties pane, set "Build Action" to "Content" and "Copy to Output Directory" to "Copy if newer" or "Copy always".</li>
  <li>Close the solution or VS2010.</li>
  <li>Open the managed project <code>.csproj</code> file in a text editor and find the <code>&lt;ItemGroup&gt;</code> which includes the native DLL name (this was created when we added the file in step 1). We'll make several small changes there:    
  
  <ol>
  <li>For the Debug build, instead of <code>&lt;ItemGroup&gt;</code> use <code>&lt;ItemGroup Condition="'$(DefineConstants)' == 'DEBUG;TRACE' "&gt;</code> and enter the path to the <em>Debug</em> DLL.</li>
  <li>Duplicate the entry for the Release build, and instead of <code>&lt;ItemGroup&gt;</code> use <code>&lt;ItemGroup Condition="'$(DefineConstants)' != 'DEBUG;TRACE' "&gt;</code> and enter the path to the <em>Release</em> DLL.</li>
  </ol></li>
  <li>Save the file and reopen VS2010. The dependency should now be in place.</li>
  </ol>