相关疑难解决方法(0)

在Windows 8 RTM上的.NET应用程序中嵌入Powershell v2.0

我在尝试从Windows 7升级之前运行托管的PowerShell脚本时遇到以下错误我从未遇到此错误.

在加载扩展类型数据文件时出现以下错误:Microsoft.PowerShell.Core,C:\ WINDOWS\Syswow64资料\ WindowsPowerShell\V1.0\types.ps1xml(2977):在输入 "System.Security.AccessControl.ObjectSecurity" 错误:异常:getter方法应该是public,non void,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2984):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是public,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2991):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是公共的,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\ Windows\SysWOW64\WindowsPowerShell\v1.0\types.ps1xml(2998):类型"System.Security.AccessControl.ObjectSecurity"出错:异常:getter方法应该是public,非void ,static,并且有一个PSObject类型的参数.Microsoft.PowerShell.Core,C:\的Windows\Syswow64资料\ WindowsPowerShell\V1.0\types.ps1xml(3005):异常:在类型 "System.Security.AccessControl.ObjectSecurity" 错误该吸气剂的方法应该是公共的,非空隙,static,并且有一个PSObject类型的参数.

我在App.config中应用了以下内容:

<dependentAssembly>
  <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
  <publisherPolicy apply="no" />
</dependentAssembly>
Run Code Online (Sandbox Code Playgroud)

问题可能是什么?

.net powershell

23
推荐指数
2
解决办法
6418
查看次数

PowerShell的'-Version'参数和CLR版本

我已经安装了PowerShell v3的发布版本,但是在使用-Version参数时遇到了一些麻烦.我有很多需要.NET 4.0的模块,我使用PowerShell v2时没有使用以下powershell.exe.config文件:

<?xml version="1.0"?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0.30319"/>
        <supportedRuntime version="v2.0.50727"/>
    </startup>
    <runtime>
        <loadFromRemoteSources enabled="true"/>
    </runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)

这将允许我使用.NET 4.0 CLR运行PowerShell v2.一切都没有问题.

我现在已经安装了PowerShell v3的发布版本$PSVersionTable,只要我使用命令'powershell -version 2'并检查变量,它就会显示它已经加载了PowerShell v3(使用.NET 4.0).如果我删除powershell.exe.config上面的文件并运行相同的命令,则表明已加载PowerShell v2但使用的是.NET 2.0.

所以我的问题是:有没有办法加载PowerShell v2并让它像我以前在安装PowerShell v3之前那样使用.NET 4.0 CLR?或者PowerShell v3不允许这样做?

另外,我应该提一下为什么我要这样做 - 主要是在我们切换到V3时可能会出现任何不兼容问题.我计划用V3测试一切,但是能够退回到V2可以让我们免于很多麻烦.

powershell powershell-2.0 powershell-3.0

2
推荐指数
1
解决办法
1520
查看次数

标签 统计

powershell ×2

.net ×1

powershell-2.0 ×1

powershell-3.0 ×1