检查批处理文件中GAC中是否存在程序集

时间:2012-09-25 14:57:18

标签: batch-file gac gacutil

我们如何在Windows批处理文件中检查GAC中是否存在程序集?

我在尝试:

C:\>gacutil /l ExistentAssembly
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:
  ExistentAssembly, Version=4.0.0.0, Culture=neutral, PublicKeyToke
n=023235e0weaaa8f0, processorArchitecture=x86

Number of items = 1

当我们列出一个不存在的程序集时:

C:\>gacutil /l NonExistentAssembly
Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

The Global Assembly Cache contains the following assemblies:

Number of items = 0

但是没有找到任何项目时没有错误级别。 这是什么方法?

1 个答案:

答案 0 :(得分:2)

最简单的方法是解析输出,然后检查findstr的错误级别:

gacutil /l assemblyname | findstr /c:"Number of items = 0"
if "%ERRORLEVEL%" equ "1" (
    echo Assembly not found.
) else (
    echo Assembly found
)