如何使用Add-Type加载Microsoft.Web.Deployment? [英] How do I use Add-Type to load Microsoft.Web.Deployment?

查看:86
本文介绍了如何使用Add-Type加载Microsoft.Web.Deployment?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些使用 MSDeploy API.我可以使用

I am writing some PowerShell scripts that use the MSDeploy API. I can load the assembly using

[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

但是,我无法使用添加类型.我收到一条错误消息,提示找不到该程序集,并且缺少一个或多个程序集.

However, I am not able to load the assembly using Add-Type. I get an error saying the assembly cannot be found and that one or more assemblies are missing.

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?

How can I use Add-Type to load Microsoft.Web.Deployment?

推荐答案

PowerShell仅允许按部分/简单名称来加载某些预定义的程序集.您将需要通过其完全限定的名称来加载它,例如:

PowerShell only allows a certain pre-defined set of assemblies to be loaded by their partial/simple name. You're going to need to load it via its fully qualified name, for example:

Add-Type -AssemblyName ('Microsoft.Web.Deployment, Version=7.1.0.0, ' +
                        'Culture=neutral, PublicKeyToken=31bf3856ad364e35')

这篇关于如何使用Add-Type加载Microsoft.Web.Deployment?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆