2

我们如何检查 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

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

4

1 回答 1

2

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

gacutil /l assemblyname | findstr /c:"Number of items = 0"
if "%ERRORLEVEL%" equ "1" (
    echo Assembly not found.
) else (
    echo Assembly found
)
于 2012-09-25T18:58:17.463 回答