Embedding Powershell v2.0 in .NET app on Windows 8 RTM

后端 未结 5 857
情歌与酒
情歌与酒 2020-12-05 07:33

Im getting the following error when trying to run hosted powershell scripts before upgrading from Windows 7 I never got this error.

The following erro

相关标签:
5条回答
  • 2020-12-05 07:51

    above answer did not work for me, i fixed the problem by removing the %APPDATA%..\Local\Microsoft\VisualStudio\ folder.

    Upon restarting VS this folder is recreated and the package manager console works again. A little crude but it does the job.

    0 讨论(0)
  • 2020-12-05 08:04

    Install the appropriate version of PowerShell for your OS:

    • Windows XP SP2 / Vista / 2003 / 2008 - PowerShell v1.0
    • Windows XP SP3 / Vista SP1 / 7 / 2003 SP2 / 2008 R2 - PowerShell v2.0
    • Windows 7 SP1 / 8 / 2008 SP1 / 2008 R2 SP1 / 2012 - PowerShell v3.0
    • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v4.0
    • Windows 7 SP1 / 8.1 / 2008 R2 SP1 / 2012 / 2012 R2 - PowerShell v5.0 (as part of Windows Management Framework (WMF) 5.0)
    0 讨论(0)
  • 2020-12-05 08:10

    The solution is to do the following, rather than only adding a block for only System.Management.Automation as suggested by the posts I read, you need to add one for all referenced PS assemblies.

      <runtime>
          <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
                <publisherPolicy apply="no" />
              </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
            </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
            </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
            </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
            </dependentAssembly>
            <dependentAssembly>
              <assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
              <publisherPolicy apply="no" />
            </dependentAssembly>
            </assemblyBinding>
        </runtime>
    
    0 讨论(0)
  • 2020-12-05 08:12

    After trying the solution in the accepted answer and getting tired of Visual Studio resetting the file, I reinstalled VS 2015 from scratch and haven't had the problem since. If you find the issue persists, the nuclear option is definitely worth a try.

    0 讨论(0)
  • 2020-12-05 08:13

    I had the same problem in VS 2015 Update 3.

    I must remove the folder:

    %APPDATA%\Local\Microsoft\VisualStudio\
    

    and then add into:

    c:\Users\%username%\AppData\Local\Microsoft\VisualStudio\14.‌​0\devenv.exe.config
    

    in section:

    <runtime> 
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    

    the following lines:

    <dependentAssembly>
      <assemblyIdentity name="System.Management.Automation" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Utility" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.ConsoleHost" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Management" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Security" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    
    <dependentAssembly>
      <assemblyIdentity name="Microsoft.PowerShell.Commands.Diagnostics" publicKeyToken="31bf3856ad364e35" />
      <publisherPolicy apply="no" />
    </dependentAssembly>
    

    I lost two days searching for solutions... thanks MS :-/

    0 讨论(0)
提交回复
热议问题