Note that there are some explanatory texts on larger screens.

plurals
  1. POVisual Studio 2010 DTE: How to make added DLL reference absolute and not copied
    text
    copied!<h2>Summary:</h2> <p><strong>We need to duplicate the behaviour of the Add Reference dialog, using DTE, when you add a specific DLL (it adds a Hint path entry to the reference in the CSProj file).</strong></p> <p>**Note: There is another related, but not duplicated, post from me here: <a href="https://stackoverflow.com/questions/6690655/visual-studio-2010-add-in-how-to-get-a-references-hint-path-property">https://stackoverflow.com/questions/6690655/visual-studio-2010-add-in-how-to-get-a-references-hint-path-property</a> Please also read that one for more information about this issue. I have now added a decent bounty to get an answer to this and will happily spread up-votes over any decent answers :)*</p> <h2>The story so far:</h2> <p>I am converting a project reference to a direct DLL reference programmatically using DTE. </p> <p>Assuming I have a simple solution with a <code>Project2</code> (the <em>parent</em> project) which references a <code>Project1</code> (the <em>child</em> project), I make the change like this:</p> <pre><code>project1Reference = FindProjectReference(project2.References, project1); project1Reference.Remove(); Reference dllReference = project2.References.Add(project1DllPath); </code></pre> <p>where project1DllPath refers to the <code>"c:\somewhere\Project1\Bin\Debug\Project1.dll"</code> file.</p> <p>The problem I cannot yet solve is that the new reference <strong>is not</strong> to <code>"c:\somewhere\Project1\Bin\Debug\Project1.dll"</code> but instead points to <code>"c:\somewhere\Project2\Bin\Debug\Project1.dll"</code> (and the file is copied there).</p> <p>If I add the DLL directly/manually using the Add Reference menu, it does not do this copying.</p> <p><strong>How do I add a DLL reference to an existing project's DLL without it taking a copy and referencing that instead?</strong> </p> <p>I have tried adding <code>dllReference.CopyLocal = false;</code> after the Add but aside from setting the flag it made no difference. There appear to be no options to modify the path after creation.</p> <p>Update: I have also tried programmatically removing any Build dependency on Project1 from Project2, but that had no effect.</p> <p>Below is the difference between the csproj files:</p> <h2>As a project:</h2> <pre><code> &lt;ItemGroup&gt; &lt;ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj"&gt; &lt;Project&gt;{86B3E118-2CD1-49E7-A180-C1346EC223B9}&lt;/Project&gt; &lt;Name&gt;ClassLibrary1&lt;/Name&gt; &lt;/ProjectReference&gt; &lt;/ItemGroup&gt; </code></pre> <h2>As a DLL reference (path was lost completely):</h2> <pre><code> &lt;ItemGroup&gt; &lt;Reference Include="ClassLibrary1, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"&gt; &lt;Private&gt;False&lt;/Private&gt; &lt;/Reference&gt; ... &lt;/ItemGroup&gt; </code></pre> <h2>As a manually referenced DLL:</h2> <pre><code> &lt;ItemGroup&gt; &lt;Reference Include="ClassLibrary1, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"&gt; &lt;HintPath&gt;..\ClassLibrary1\bin\Debug\ClassLibrary1.dll&lt;/HintPath&gt; &lt;/Reference&gt; ... &lt;/ItemGroup&gt; </code></pre> <p>It looks like being able to specify the hint path for the DLL reference is the key. <strong>How do you set a hint path on a DLL reference (assuming you only have a handle to the Reference property)?</strong></p> <h2>More information (20 July 2011):</h2> <p>The suggestion from <a href="https://stackoverflow.com/users/328577/muse-vsextensions">Muse VSExtensions</a> below does not impact the DLLs in question, as a copy has already been made from the DLL's project BIN to the parent project's BIN folder. The parent project does not bother to make use of the reference path as it already has the child DLL in its output folder.</p> <p>Also the <code>Reference Paths</code> of a project are saved to the <em>project</em>.csproj.user file and not to the <em>project</em>.csproj file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload