Visual Studio DLL 引用替换工具

10/23/2017 工具

用于批量替换C#解决方案中的DLL引用(At VisualStudio)。这是一篇使用指南。 介绍可以看这里 (opens new window)

# 目的

进行源码调试。 通常,我们使用DLL引用(或 Nuget 引用),但这样很不方便调试,尤其对于内部项目之间,明明两边的代码都有,为啥不能联合调试呢。

# 原理

将所有引用目标DLL的工程文件(.csproj文件)中的引用替换为 ProjectReference。 引用目标DLL对于的工程文件(.csproj)。

# 使用步骤

入口:

  1. 点击 "SELECT .CSPROJ FILE" 按钮。
  2. 选择目标工程的 csproj 文件。
  3. 点击 "REPLACE REFERENCE" 按钮完成替换。

这时VS会提示你重新加载解决方案,重新加载之,之后此解决方案中所有的引用就是新指定的引用了。

  • 撤销是怎么做的?
    因为替换的操作,其实就是对csproj文件的操作,撤销,就是把csproj恢复原样咯。
    这里使用的是git命令checkout。 所以,在替换之前,会检测是否有 csproj 文件和 sln 文件的修改,如果有,会提示不能替换,除非取消勾选下方的 Use git checkout command when Undo

  • 取消勾选了 Use git checkout command when Undo 会怎么样? 1、将不能使用撤销按钮进行撤销操作。
    要撤销怎么办? - 敲命名 git checkout *.csprojgit checkout *.sln
    注意,自己不能有对 csproj 文件的修改哦。

2、可以替换多个DLL引用。
取消勾选之后,不会对 csproj 文件的修改进行检查,所以可以任意替换。

  • 替换之后,关闭了 VS , 怎么撤销?
    参考上面第1条。

# 相关知识:

There is a search order for assemblies when building. The search order is as follows:

  • Files from the current project – indicated by ${CandidateAssemblyFiles}.
  • $(ReferencePath) property that comes from .user/targets file.
  • %(HintPath) metadata indicated by reference item.
  • Target framework directory.
  • Directories found in registry that uses AssemblyFoldersEx Registration.
  • Registered assembly folders, indicated by ${AssemblyFolders}.
  • $(OutputPath) or $(OutDir)
  • GAC

# 相关链接:

更新时间: Sunday, March 14, 2021 23:11