Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace DLL refs with Project refs for project dependencies in Visual Studio C# solution

Is it possible to programmatically replace DLL refs with Project refs for project dependencies in Visual Studio C#/VB.NET solution?

BACKGROUND:

I'm working with some legacy code where dependencies for each project are mostly referenced as compiled DLLs instead of including project reference from corresponding project in solution or even worse - referenced straight from GAC!

Right now I have to manually remove each DLL reference and replace it with project reference from VS UI for each solution out of dozens projects.

Editing the project/solution XML .csproj/.sln files is not straightforward due to GUIDs:

<!--typical DLL reference-->

<ItemGroup>
    <Reference Include="MyDLL, Version=2.0.1.0, Culture=neutral, PublicKeyToken=1b6d1e0267e1acba, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>...\MyDLL.dll</HintPath>
    </Reference>
</ItemGroup>

<!--typical Project reference-->

<ItemGroup>
    <ProjectReference Include="..\MyDLL\MyDLL.csproj">
      <Project>{3cc27830-3d6b-4071-85e5-5a4006f11142}</Project>
      <Name>MyDLL</Name>
    </ProjectReference>
</ItemGroup>
like image 451
denfromufa Avatar asked Mar 10 '16 17:03

denfromufa


1 Answers

Use this plug-in .. It might help on your problem

https://visualstudiogallery.msdn.microsoft.com/056617a4-da39-4d7b-8ecf-933009d9b721

It has description below

Switches references from file to projects (and vice versa) references when adding projects. References are reverted when the project is removed.

usage:

You are developing project A which has a file reference to assembly "b.dll". At some point you need to make changes to "b.dll" . So you add project "B" to the solution. The ReferenceSwitcher will detect that project B produces an assembly called "b.dll" and ask if you want to switch all references from "b.dll" to project B.

Then at some point later, you no longer need project B in your solution, so you remove project B. The reference switcher will detected that references to B used to point to "b.dll" and ask you if you would like to update them.

More info here: http://markkemper1.blogspot.com/2011/09/project-to-file-reference-switcher-for.html

Edit: there are lots of plug-in available to solve your purpose check them out

https://visualstudiogallery.msdn.microsoft.com/197d94f6-6276-471d-853d-a5a322ccb08c

OR search them all

https://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=reference&pageIndex=2

like image 132
Moumit Avatar answered Oct 22 '22 14:10

Moumit