Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 如何导入软件包(不是模块)?_Powershell - Fatal编程技术网

Powershell 如何导入软件包(不是模块)?

Powershell 如何导入软件包(不是模块)?,powershell,Powershell,我从安装了SharpDx包,但是有没有一种方法可以像导入模块一样导入它,这样我就不必指定程序集(dll)路径 目前,我找到的唯一方法是使用Add-Type引用程序集,但是除了此之外没有其他方法了吗 #Reference where you kept the dxSharp files $dxSharpPath = 'Path\To\DLLs' #Load the sharpDX Libraries Add-Type -Path "$dxSharpPath\sharpdx.dll" Add-Ty

我从安装了SharpDx包,但是有没有一种方法可以像导入模块一样导入它,这样我就不必指定程序集(dll)路径

目前,我找到的唯一方法是使用Add-Type引用程序集,但是除了此之外没有其他方法了吗

#Reference where you kept the dxSharp files
$dxSharpPath = 'Path\To\DLLs'

#Load the sharpDX Libraries
Add-Type -Path "$dxSharpPath\sharpdx.dll"
Add-Type -Path "$dxSharpPath\Sharpdx.Directinput.dll"

#Create new DirectInput object
$dInput = New-Object -TypeName SharpDX.DirectInput.DirectInput

我最终尝试创建directinput对象

您必须告诉PowerShell DLL所在的位置,这与您加载模块(.psm1文件(带或不带清单)时所做的相同,该模块没有安装到定义的PowerShell模块路径之一

除了添加类型,还可以使用反射:

$customDLL = 'UncToYourDLL'
[Reflection.Assembly]::LoadFile($customDll)
另请参见Lee Holmes关于此主题的文章:

更新

Import-Module SomeNewCustomOr3rdP.dll
导入模块:未加载指定的模块“SomeNewCustomOr3rdP.dll”,因为在任何模块目录中都找不到有效的模块文件

当然,这个错误非常具体。它不知道在哪里可以找到它,因为该名称与模块名称不匹配

所以,这个

Import-Module 'c:\users\mj\desktop\SomeNewCustomOr3rdP.dll'
或者在PSModulePath中创建一个与DLL同名的文件夹,将DLL复制到该命名文件夹中,并正常使用导入

C:\Users\<username>\Documents\WindowsPowerShell\Modules\SomeNewCustomOr3rdP\SomeNewCustomOr3rdP.dll'
。。。应该像预期的那样工作。总之,Add Type、Import Module和[Reflection.Assembly]::LoadFile($customDll)都完成了相同的任务

关于获取SharpDX作为模块的更新

Import-Module SomeNewCustomOr3rdP.dll
请注意,这是Install Module和InstallPackage cmdlet。对于目标资源,这两者都是相同的。如果它通过其中一个存在,那么获取/使用它们的方法是相同的

# Find all modules wiht share in the name
Find-Module -Name '*Sharp*' | 
Format-Table -AutoSize
<#
# Results

Version        Name                             Repository Description                                                                                              
-------        ----                             ---------- -----------                                                                                              
0.9.1.326      ACMESharp                        PSGallery  Client library for the ACME protocol, which is used to interoperate with the Let's Encrypt project's C...
0.9.3.334      ACMESharp.Providers.IIS          PSGallery  Microsoft IIS Provider extension library for ACMESharp Client.                                           
0.9.1.326      ACMESharp.Providers.AWS          PSGallery  AWS Provider extension library for ACMESharp Client.                                                     
0.9.1.326      ACMESharp.Providers.Windows      PSGallery  Microsoft Windows Providers extension library for ACMESharp Client.                                      
0.0.1          SNMPSharpNet                     PSGallery  PowerShell module implementing SNMP cmdlets from the SNMP Sharp .NET Library                             
0.9.1.326      ACMESharp.Providers.CloudFlare   PSGallery  CloudFlare Provider extension library for ACMESharp Client.                                              
1.0.1          CowsaySharp                      PSGallery  Generates ASCII pictures of a cow with a message                                                         
1.0.4          ACMESharpRoute53Automation       PSGallery  ACMESharpRoute53Automation is a PowerShell module which automates the ACMESharp process of obtaining S...
0.9.1.326      ACMESharp.Providers.DNSMadeEasy  PSGallery  DNS Made Easy Provider extension library for ACMESharp Client.                                           
1.0.6563.38109 ACMESharp.Providers.QCloud       PSGallery  A QCloud dns provider for handling Challenges.                                                           
0.1.0          PSCSharpInvoker                  PSGallery  Adds a cmdlet that can be used to invoke C# code without loading the types in the current PowerShell n...
1.0.0.0        IntelliTect.ResharperNugetSearch PSGallery  Provides functions for searching against Jet Brains' Resharper Nuget Search API.                         
1.3.5          CSharp-Watch                     PSGallery  Watches the current directory and sub-directories for changes to C-Sharp files. When a change is detec...
#>

# find all packages with sharp in the name
Find-Package -Name '*Sharp*' | 
Format-Table -AutoSize

# Get the detail on SharpDx specifically
Find-Package -Name 'SharpDX'
<#
# Results

Name                           Version          Source           Summary                                                                                            
----                           -------          ------           -------                                                                                            
SharpDX                        4.2.0            nuget.org        Core assembly for all SharpDX assemblies.  
#>
Find-Package -Name 'SharpDX' | 
Format-List

# Download and save a module or package
Find-Package -Name 'SharpDX' | 
Save-Package -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
Install-Package -Name 'SharpDX' -Force
#查找名称中共享的所有模块
查找模块-名称“*Sharp*”|
表格格式-自动调整大小

您必须告诉PowerShell DLL所在的位置,这与您在加载模块(.psm1文件(有或没有清单)时没有安装到定义的PowerShell模块路径之一时所做的相同

除了添加类型,还可以使用反射:

$customDLL = 'UncToYourDLL'
[Reflection.Assembly]::LoadFile($customDll)
另请参见Lee Holmes关于此主题的文章:

更新

Import-Module SomeNewCustomOr3rdP.dll
导入模块:未加载指定的模块“SomeNewCustomOr3rdP.dll”,因为在任何模块目录中都找不到有效的模块文件

当然,这个错误非常具体。它不知道在哪里可以找到它,因为该名称与模块名称不匹配

所以,这个

Import-Module 'c:\users\mj\desktop\SomeNewCustomOr3rdP.dll'
或者在PSModulePath中创建一个与DLL同名的文件夹,将DLL复制到该命名文件夹中,并正常使用导入

C:\Users\<username>\Documents\WindowsPowerShell\Modules\SomeNewCustomOr3rdP\SomeNewCustomOr3rdP.dll'
。。。应该像预期的那样工作。总之,Add Type、Import Module和[Reflection.Assembly]::LoadFile($customDll)都完成了相同的任务

关于获取SharpDX作为模块的更新

Import-Module SomeNewCustomOr3rdP.dll
请注意,这是Install Module和InstallPackage cmdlet。对于目标资源,这两者都是相同的。如果它通过其中一个存在,那么获取/使用它们的方法是相同的

# Find all modules wiht share in the name
Find-Module -Name '*Sharp*' | 
Format-Table -AutoSize
<#
# Results

Version        Name                             Repository Description                                                                                              
-------        ----                             ---------- -----------                                                                                              
0.9.1.326      ACMESharp                        PSGallery  Client library for the ACME protocol, which is used to interoperate with the Let's Encrypt project's C...
0.9.3.334      ACMESharp.Providers.IIS          PSGallery  Microsoft IIS Provider extension library for ACMESharp Client.                                           
0.9.1.326      ACMESharp.Providers.AWS          PSGallery  AWS Provider extension library for ACMESharp Client.                                                     
0.9.1.326      ACMESharp.Providers.Windows      PSGallery  Microsoft Windows Providers extension library for ACMESharp Client.                                      
0.0.1          SNMPSharpNet                     PSGallery  PowerShell module implementing SNMP cmdlets from the SNMP Sharp .NET Library                             
0.9.1.326      ACMESharp.Providers.CloudFlare   PSGallery  CloudFlare Provider extension library for ACMESharp Client.                                              
1.0.1          CowsaySharp                      PSGallery  Generates ASCII pictures of a cow with a message                                                         
1.0.4          ACMESharpRoute53Automation       PSGallery  ACMESharpRoute53Automation is a PowerShell module which automates the ACMESharp process of obtaining S...
0.9.1.326      ACMESharp.Providers.DNSMadeEasy  PSGallery  DNS Made Easy Provider extension library for ACMESharp Client.                                           
1.0.6563.38109 ACMESharp.Providers.QCloud       PSGallery  A QCloud dns provider for handling Challenges.                                                           
0.1.0          PSCSharpInvoker                  PSGallery  Adds a cmdlet that can be used to invoke C# code without loading the types in the current PowerShell n...
1.0.0.0        IntelliTect.ResharperNugetSearch PSGallery  Provides functions for searching against Jet Brains' Resharper Nuget Search API.                         
1.3.5          CSharp-Watch                     PSGallery  Watches the current directory and sub-directories for changes to C-Sharp files. When a change is detec...
#>

# find all packages with sharp in the name
Find-Package -Name '*Sharp*' | 
Format-Table -AutoSize

# Get the detail on SharpDx specifically
Find-Package -Name 'SharpDX'
<#
# Results

Name                           Version          Source           Summary                                                                                            
----                           -------          ------           -------                                                                                            
SharpDX                        4.2.0            nuget.org        Core assembly for all SharpDX assemblies.  
#>
Find-Package -Name 'SharpDX' | 
Format-List

# Download and save a module or package
Find-Package -Name 'SharpDX' | 
Save-Package -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules"
Install-Package -Name 'SharpDX' -Force
#查找名称中共享的所有模块
查找模块-名称“*Sharp*”|
表格格式-自动调整大小

据我所知,唯一能做到这一点的方法就是你所使用的方法。如果你想隐藏细节,我想你可以把它包装在一个模块中并使用它。[咧嘴笑]@Lee_Dailey ya…我希望有一个简单的导入模块,就像这样…看起来你需要自己构建它。我找不到任何迹象表明有人已经这么做了。祝你好运[咧嘴笑]据我所知,唯一能做到这一点的方法就是你使用的方法。如果你想隐藏细节,我想你可以把它包装在一个模块中并使用它。[咧嘴笑]@Lee_Dailey ya…我希望有一个简单的导入模块,就像这样…看起来你需要自己构建它。我找不到任何迹象表明有人已经这么做了。祝你好运[咧嘴笑]哦,我想一定有其他方法可以做到这一点,比如导入模块。哦,好的,谢谢!不用担心,您可以导入DLL,但仍然必须告诉它路径。因为DLL不是模块,因此无法从模块路径自动加载。请参阅与此评论相关的我的更新。请参阅扩展我的评论。如果我可以问的话,sqlserver是一个我可以使用导入模块轻松导入的模块。您知道SharpDx是否也可以作为模块而不是软件包提供吗?例如,如果我们想要构建SSAS表格多维数据集,我们可以加载部分程序集/dll,例如loadwithpartialname(Microsoft.Analysisservices.Tablear)。但是我们也可以使用sqlserver模块本身来完成这个程序集的所有功能,因此我们根本不需要加载表格程序集。SharpDx是否可以提供类似的功能?所有可用的模块和软件包都位于MS powershellgallery.com上。使用Find模块、Find-Package cmdlet查找它们。请看我的更新。哦,我想一定有其他方法可以做到这一点,比如导入模块。哦,好的,谢谢!不用担心,您可以导入DLL,但仍然必须告诉它路径。因为DLL不是模块,因此无法从模块路径自动加载。请参阅与此评论相关的我的更新。请参阅扩展我的评论。如果我可以问的话,sqlserver是一个我可以使用导入模块轻松导入的模块。您知道SharpDx是否也可以作为模块而不是软件包提供吗?例如,如果我们想要构建SSAS表格多维数据集,我们可以加载部分程序集/dll,例如loadwithpartialname(Microsoft.Analysisservices.Tablear)。但是我们也可以使用sqlserver模块本身来完成这个程序集的所有功能,因此我们根本不需要加载表格程序集。SharpDx是否可以提供类似的功能?所有可用的模块和软件包都位于MS powershellgallery.com上。使用Find模块、Find-Package cmdlet查找它们。请看我的更新。