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?
In IIS Manager, in the Connections pane, right-click your IIS website, point to Deploy, and then click Import Application. In the Import Application Package Wizard, on the Select the Package page, browse to the location of your web deployment package, and then click Next.
If Windows Firewall is enabled on your web server, you'll need to create a new inbound rule to allow TCP traffic on port 8172 (all outbound traffic is permitted by default in Windows Firewall). If you use a third-party firewall, you'll need to create rules to allow traffic.
You can use the Web Deployment Tool to synchronize a Web site from a source to a destination on IIS 6.0, or IIS 7 or above. You can do this by "pushing" data to a remote destination or by "pulling" data from a remote source.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With