2012-09-25 144 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 
) 
相關問題