简体   繁体   English

在Visual Studio C#解决方案中将DLL引用替换为Project refs以获取项目依赖性

[英]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? 是否可以在Visual Studio C#/ VB.NET解决方案中以编程方式将DLL引用替换为项目依赖项的项目引用?

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! 我正在使用一些遗留代码,其中每个项目的依赖项主要被引用为已编译的DLL,而不是包含来自解决方案中相应项目的项目引用,甚至更糟 - 直接来自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. 现在,我必须手动删除每个DLL引用,并将其替换为VS UI中的项目引用,用于几十个项目中的每个解决方案。

Editing the project/solution XML .csproj/.sln files is not straightforward due to GUIDs: 由于GUID,编辑项目/解决方案XML .cs​​proj / .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>

Use this plug-in .. It might help on your problem 使用此插件..它可能有助于解决您的问题

https://visualstudiogallery.msdn.microsoft.com/056617a4-da39-4d7b-8ecf-933009d9b721 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". 您正在开发项目A,其中包含程序集“b.dll”的文件引用。 At some point you need to make changes to "b.dll" . 在某些时候,您需要更改“b.dll”。 So you add project "B" to the solution. 因此,您将项目“B”添加到解决方案中。 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. ReferenceSwitcher将检测到项目B生成一个名为“b.dll”的程序集,并询问您是否要将所有引用从“b.dll”切换到项目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. 然后在某个时候,您的解决方案中不再需要项目B,因此您删除了项目B.参考切换器将检测到B的引用用于指向“b.dll”并询问您是否要更新它们。

More info here: http://markkemper1.blogspot.com/2011/09/project-to-file-reference-switcher-for.html 更多信息: 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 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 https://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=SearchText&f%5B0%5D.Value=reference&pageIndex=2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM