【发布时间】:2014-12-04 10:36:24
【问题描述】:
我们的一些应用程序依赖于用于日志记录和配置的通用 dll。这个通用 dll 被添加到我们服务器上的 GAC 中,并且不包含在我们部署的 bin 文件夹中。
我想编写一个简单的控制台应用程序来检查 common.dll 是否已添加到服务器上的 GAC。 我没有运气使用 fusion 或 assembly.load 以编程方式检查这个:Check GAC for an assembly
我的想法是在本地包含对 dll 的引用,确保关闭本地复制,然后在调用 dll 中的方法时尝试在服务器上捕获 FileNotFoundException。
类似的东西
static void Main()
{
try
{
Common.Logger.LogInfo("Testing logger."); //call to the dll
Console.WriteLine("loaded successfully");
Console.ReadLine();
}
catch (System.IO.FileNotFoundException e)
{
Console.WriteLine("Common dll missing!" + e.Message);
Console.ReadLine();
}
}
但由于 dll 不存在,应用程序将崩溃并在调用 main 方法之前抛出 FileNotFoundException。我假设在运行 .exe 时有一些初始检查是否存在所有 dll - 有没有办法禁用它?
【问题讨论】: