c#PowerShell远程处理无法在具有的服务器2012 R2上运行.净6



我有一个c#应用程序,它使用powershell远程处理来连接到远程服务器。我最近从迁移了它。净4.6至。Net 6.0。在我的开发系统上一切都很好,但在Server 2012 R2上却不太好用。

代码基本上是这样做的:

// using System.Management.Automation.Runspaces;
const string shellUri = "http://schemas.microsoft.com/powershell/Microsoft.PowerShell"
WSManConnectionInfo connectionInfo = new (true, remoteAddress, remotePort, "/wsman", shellUri, remoteCredentials);
// this throws the exception:
var runspace = RunspaceFactory.CreateRunspace(connectionInfo);

如果我将应用程序部署到Server2019服务器上,它运行良好,因此它是Server2012R2特有的。不幸的是,这是我一直坚持的操作系统,所以升级不是一个选择。

调用堆栈详细信息:.NET版本:6.0.10描述:由于出现未处理的异常,进程已终止。异常信息:系统。经营自动化Remoting。PSRemotingTransportException:此参数集需要WSMan,但找不到支持的WSMan客户端库。WSMan未安装或不可用于此系统。--->系统DllNotFoundException:无法加载DLL"WsmSvc.DLL"或其依赖项之一:找不到指定的模块。(0x8007007E(在系统中。经营自动化Remoting。客户WSManNativeApi。WSManInitialize(Int32标志,IntPtr和wsManAPIHandle(在系统中。经营自动化Remoting。客户WSManClientSessionTransportManager。WSManAPI数据公用。。ctor((---内部异常堆栈跟踪结束---在系统中。经营自动化Remoting。客户WSManClientSessionTransportManager。WSManAPI数据公用。。ctor((在系统中。经营自动化Remoting。客户WSManClientSessionTransportManager。。ctor(Guid runspacePoolInstanceId,WSManConnectionInfo connectionInfo,PSRemotingCryptoHelper cryptoHelper,String sessionName(在系统中。经营自动化运行空间。WSManConnectionInfo。CreateClientSessionTransportManager(Guid instanceId、String sessionName、PSRemotingCryptoHelper cryptoHelper(在系统中。经营自动化Remoting。客户端远程会话DSHandlerImpl。。ctor(ClientRemoteSession会话、PSRemotingCryptoHelper cryptoHelper、RunspaceConnectionInfo connectionInfo、URIDirectionReported uriRedirectionHandler(在系统中。经营自动化Remoting。ClientRemoteSessionImpl。。ctor(RemoteRunspacePoolInternal rsPool,URIDirectionReported uriRedirectionHandler(在系统中。经营自动化内部的ClientRunspacePoolDataStructureHandler。CreateClientRemoteSession(RemoteRunspacePoolInternal rsPoolInternal(在系统中。经营自动化内部的客户端运行空间池数据结构处理程序。。ctor(RemoteRunspacePoolInternal clientRunspacePool,TypeTable TypeTable(在系统中。经营自动化运行空间。内部的RemoteRunspacePoolInternal。CreateDSHandler(TypeTable TypeTable(在系统中。经营自动化运行空间。内部的RemoteRunspacePoolInternal。。ctor(Int32 minRunspace,Int32 maxRunspace,TypeTable TypeTable,PSHost主机,PSPrimitiveDictionary applicationArguments,RunspaceConnectionInfo connectionInfo,字符串名称(在系统中。经营自动化运行空间。运行空间池。。ctor(Int32 minRunspace,Int32 maxRunspace,TypeTable TypeTable,PSHost主机,PSPrimitiveDictionary applicationArguments,RunspaceConnectionInfo connectionInfo,字符串名称(在系统中。经营自动化远程运行空间。。ctor(TypeTable TypeTable,RunspaceConnectionInfo connectionInfo,PSHost主机,PSPrimitiveDictionary applicationArguments,字符串名称,Int32 id(在系统中。经营自动化运行空间。RunspaceFactory。CreateRunspace(RunspaceConnectionInfo connectionInfo,PSHost主机,TypeTable TypeTable,PSPrimitiveDictionary applicationArguments,字符串名称(在系统中。经营自动化运行空间。RunspaceFactory。CreateRunspace(RunspaceConnectionInfo connectionInfo,PSHost主机,TypeTable TypeTable(在系统中。经营自动化运行空间。RunspaceFactory。CreateRunspace(PSHost主机,RunspaceConnectionInfo connectionInfo(在系统中。经营自动化运行空间。RunspaceFactory。CreateRunspace(RunspaceConnectionInfo connectionInfo(…(此处为用户代码(

我解决了自己的问题。

出于习惯,我重新使用了现有的部署脚本,该脚本运行如下:

dotnet publish -c --self-contained=true $file --runtime win10-x64 --configuration Release

看到问题了吗?通过运行以下程序修复了它:

dotnet publish -c --self-contained=true $file --runtime win81-x64 --configuration Release

哪里的脸手掌表情。。。

最新更新