[英]PowerShell DSC load assembly
I have written a class based DSC resource. 我已经写了一个基于类的DSC资源。 In this resource I need an assembly(Microsoft.SqlServer.Smo.dll).
在此资源中,我需要一个程序集(Microsoft.SqlServer.Smo.dll)。 I have tried to load the assembly with the manifest file: like that:
RequiredAssemblies = @("Microsoft.SqlServer.Smo.dll")
我试图用清单文件加载程序集:像这样:
RequiredAssemblies = @("Microsoft.SqlServer.Smo.dll")
Now I have the problem that when I want to write my DSC Configuration definion, I can't load my dsc resource because of the erromessage: Unable to find type [Microsoft.SqlServer.Smo.Login] 现在,我遇到一个问题,当我想编写DSC配置定义时,由于出现错误而无法加载dsc资源:无法找到类型[Microsoft.SqlServer.Smo.Login]
Picture of the errormessage: 错误消息的图片:
How can I load an assembly into my dsc session? 如何将程序集加载到dsc会话中?
Make sure that assembly is in the same folder as your module, and then call it like this (no dll): RequiredAssemblies = @("Microsoft.SqlServer.Smo")
确保程序集与模块位于同一文件夹中,然后按以下方式调用它(无dll):
RequiredAssemblies = @("Microsoft.SqlServer.Smo")
If that doesn't work, you can use reflection and load it into your AppDomain when the module is imported. 如果这不起作用,则可以在导入模块时使用反射并将其加载到AppDomain中。
$assembly = Join-Path $PSScriptRoot -ChildPath 'Microsoft.SqlServer.Smo.dll'
$result = [System.Reflection.Assembly]::LoadFile($assembly)
if($result -eq $null)
{
throw New-Object System.Exception("Failed to Microsoft.SqlServer.Smo assembly")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.