Question

How do we check if an assembly is present in GAC in a windows batch file?

I am trying:

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

When we list a non-existent assembly:

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

But there is no errorlevel when no item is found. What is the approach here?

Était-ce utile?

La solution

The easiest way is to parse the output and then check the errorlevel of findstr:

gacutil /l assemblyname | findstr /c:"Number of items = 0"
if "%ERRORLEVEL%" equ "1" (
    echo Assembly not found.
) else (
    echo Assembly found
)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top