2

我需要检查项目中的所有引用是否存在以避免可能的错误,但我无法在任何地方找到如何在 VB.NET 中执行此操作。我可以像这样在 VBA 中做到这一点:

Dim vbProj As VBProject
Dim chkRef As Reference

Set vbProj = ThisWorkbook.VBProject

For Each chkRef In vbProj.References
   If chkRef.IsBroken Then
      Debug.Print chkRef.Name " reference doesn't exist!"
   End If
Next

更具体地说,该项目引用了另一个程序(BarTender),我需要能够打开文件并使用 VB 打印它们。

我已将它安装在我的计算机上,但如果其他人在没有安装 Bartender 的情况下运行我的项目,则在声明对象变量时会抛出未知数据类型的异常。

如何在 VB.NET 中完成此操作?

4

1 回答 1

2

Try enabling Option Strict On it will prevent late binding which should prevent your code from compiling unless all of the references are present.

From above link:

Restricts implicit data type conversions to only widening conversions, disallows late binding, and disallows implicit typing that results in an Object type.

Also if you click on all files in your solution explorer you will see a References Section if you look in there. Any references with an exclamation point next to them are missing.

于 2013-10-19T21:50:57.967 回答