powershell – 如何使用Add-Type加载Microsoft.Web.Deployment?

前端之家收集整理的这篇文章主要介绍了powershell – 如何使用Add-Type加载Microsoft.Web.Deployment?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在编写一些使用 MSDeploy API的PowerShell脚本。我可以加载组件
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")

位置在GAC

PS > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment") | fl Location

Location : C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Deployment\7.1.0.0__31bf3856ad364e35\Microsoft.Web.Deployment.dll

但是,我无法使用Add-Type加载程序集。我收到一个错误,指出程序集无法找到,并且缺少一个或多个程序集。

PS > Add-Type -AssemblyName Microsoft.Web.Deployment
Add-Type : Cannot add type. The assembly 'Microsoft.Web.Deployment' could not be found.
At line:1 char:9
+ Add-Type <<<<  -AssemblyName Microsoft.Web.Deployment
    + CategoryInfo          : ObjectNotFound: (Microsoft.Web.Deployment:String) [Add-Type],Exception
    + FullyQualifiedErrorId : ASSEMBLY_NOT_FOUND,Microsoft.PowerShell.Commands.AddTypeCommand

Add-Type : Cannot add type. One or more required assemblies are missing.
At line:1 char:9
+ Add-Type <<<<  -AssemblyName Microsoft.Web.Deployment
    + CategoryInfo          : InvalidData: (:) [Add-Type],InvalidOperationException
    + FullyQualifiedErrorId : ASSEMBLY_LOAD_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand

如何使用Add-Type来加载Microsoft.Web.Deployment?

PowerShell仅允许某些预定义的程序集由其部分/简单名称加载。您将需要通过其完全限定名称加载它,例如:
Add-Type -AssemblyName ('Microsoft.Web.Deployment,Version=7.1.0.0,' +
                        'Culture=neutral,PublicKeyToken=31bf3856ad364e35')

猜你在找的Windows相关文章