【问题标题】:Problem with .NET web application using Powershell SDK使用 Powershell SDK 的 .NET Web 应用程序出现问题
【发布时间】:2022-10-05 14:13:02
【问题描述】:

我不知道还有什么要测试的,因此我的问题在这里。

目标是继续使用我设置为<Project Sdk="Microsoft.NET.Sdk.Web"> 的 Visual Studio 项目,并能够通过 Powershell.SDK nuget 包获得 Powershell 会话。

我注意到运行"powerShell.Invoke()" 并将Visual Studio 项目设置为<Project Sdk="Microsoft.NET.Sdk"> 会给我一个预期的会话。但是使用SDK.Web总是返回错误 =>“发生 Powershell 无法处理的错误”。

我什至添加了对控制台应用程序的项目引用,以使会话正常工作,但结果与上面解释的相同。

我做错了什么还是有任何解决方法?

我可以将我的 .net Web 应用程序更改为控制台应用程序并仍将其托管在 IIS 上吗?

谢谢你。

【问题讨论】:

    标签: c# .net powershell


    【解决方案1】:

    能够通过添加来解决这个问题

    <EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>
    

    <PackageReference Include="Microsoft.Management.Infrastructure" Version="1.0.0" />
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.4" />
    <PackageReference Include="System.Management.Automation" Version="6.0.4" />
    

    到此处所述的 csproj 文件:Issue

    我还必须在我的发布配置文件中将 RuntimeIdentifier 设置为 win7-x64:

    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    

    【讨论】:

      猜你喜欢
      • 2017-06-10
      • 2011-04-22
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-22
      • 2021-12-07
      • 1970-01-01
      相关资源
      最近更新 更多