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

发布于 2024-09-17 06:50:08 字数 1662 浏览 10 评论 0原文

我正在编写一些使用 的 PowerShell 脚本MSDeploy API。 加载程序集

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")

我可以使用The location is in the 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?

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

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Deployment")

The location is in the 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海里的那抹蓝 2024-09-24 06:50:08

PowerShell 只允许通过其部分/简单名称加载特定的预定义程序集集。您将需要通过其完全限定名称加载它,例如:

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

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')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文