2012-09-25 75 views
1

如何检查GAC中的程序集是否存在于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 

但是,当没有项目被发现没有错误级别。 这里有什么方法?

回答

2

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

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