冲突查找器
一个用于查找引用 DLL 版本冲突的工具。
引言
冲突查找器应用程序旨在帮助开发团队查找外部 DLL 的冲突引用。
背景
在我们的系统开发过程中,我们遇到了一个关于引用不同版本的外部 DLL 的问题。当外部 DLL 对另一个具有错误版本的 DLL 进行第二阶段引用时,问题会变得更糟。
为了解决这个问题,我开发了一个应用程序,帮助开发团队在集成期间(而不是运行时)查找冲突。
使用代码
有三个项目
- 控制台应用程序:如果存在任何冲突,则返回值为 1,否则返回 0。冲突的 DLL 将打印到控制台。
- Windows 应用程序:此应用程序通过显示正在特定文件夹中使用的 DLL 之间的所有关系,帮助开发人员分析外部引用。
- 类库:下面的代码……
Find
:此方法使用一个输入参数,类型为string
,表示要分析的文件夹的路径,并返回true
/false
,具体取决于是否存在冲突。
CollisionOutPut
:get
属性,返回一个包含所有找到的冲突的字符串。Data
:返回已分析数据的dataset。
如何从控制台应用程序执行
FindCollisions c = new FindCollisions();
bool reply = c.Find(args[0]); /// rgss[0] = your directory
Console.Write(c.CollisionsOutPut);
if (reply == false)
return 1;
else
return 0;
如何查找当前 DLL 的所有引用
ReferenceCollisionDataSet.DllTableRow dllRow =
_ds.DllTable.NewDllTableRow();
// file = the curent dll/exe path
Assembly asm = Assembly.LoadFile(file);
AssemblyName asmName = asm.GetName();
// the name of the dll/exe
dllRow.Name = asmName.Name;
// the version of the dll
dllRow.Version = asmName.Version.ToString();
_ds.DllTable.Rows.Add(dllRow);
//run on all the references of the curent Assembly
foreach (AssemblyName refName in asm.GetReferencedAssemblies())
{
try {
//check if this reference is not a system reference
if (IsNotSystemRef(refName))
{
ReferenceCollisionDataSet.ReferenceTableRow refRow =
_ds.ReferenceTable.NewReferenceTableRow();
refRow.Dll_Name = asmName.Name;
refRow.Reference_Name = refName.Name;
refRow.Version = refName.Version.ToString();
_ds.ReferenceTable.Rows.Add(refRow);
}
catch { }
}