是否可以在 Visual Studio C#/VB.NET 解决方案中以编程方式将 DLL 引用替换为项目依赖项的项目引用?
背景:
我正在处理一些遗留代码,其中每个项目的依赖项大多被引用为已编译的 DLL,而不是在解决方案中包含相应项目的项目引用,甚至更糟 - 直接从 GAC 引用!
现在,对于数十个项目中的每个解决方案,我必须手动删除每个 DLL 引用并将其替换为来自 VS UI 的项目引用。
由于 GUID,编辑项目/解决方案 XML .csproj/.sln 文件并不简单:
<!--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>
最佳答案
使用这个插件..它可能对你的问题有帮助
https://visualstudiogallery.msdn.microsoft.com/056617a4-da39-4d7b-8ecf-933009d9b721
下面有说明
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
编辑: 有很多插件可以解决您的问题,请查看它们
https://visualstudiogallery.msdn.microsoft.com/197d94f6-6276-471d-853d-a5a322ccb08c
或者全部搜索
关于c# - 在 Visual Studio C# 解决方案中将 DLL 引用替换为项目依赖项的项目引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35923320/