简体   繁体   English

问题 .NET web 应用程序使用 Powershell SDK

[英]Problem with .NET web application using Powershell SDK

I don't know what else to test hence my question here.我不知道还有什么要测试因此我的问题在这里。

The goal is to continue using my Visual Studio project set to <Project Sdk="Microsoft.NET.Sdk.Web"> and being able to obtain a Powershell session via the Powershell.SDK nuget package.目标是继续使用我的 Visual Studio 项目设置为<Project Sdk="Microsoft.NET.Sdk.Web">并能够通过 Powershell.SDK 8831999658843188 8831999658843188 获得 Powershell session

I noticed that running "powerShell.Invoke()" with a Visual studio project set to <Project Sdk="Microsoft.NET.Sdk"> will give me a session as expected.我注意到在将 Visual Studio 项目设置为<Project Sdk="Microsoft.NET.Sdk">的情况下运行"powerShell.Invoke()"会给我一个预期的 session。 However using Sdk.Web always returns an error => "An error occured that Powershell could not handle".但是,使用Sdk.Web总是会返回错误 =>“发生 Powershell 无法处理的错误”。

I even added a project reference to a console application in order to get the session working but the result is the same as explained above.为了使 session 正常工作,我什至添加了对控制台应用程序的项目引用,但结果与上面解释的相同。

Am I doing something wrong or is there any workaround?我做错了什么或者有什么解决方法吗?

Could I change my .net web application to a console app and still host it on IIS?我可以将我的 .net web 应用程序更改为控制台应用程序并仍将其托管在 IIS 上吗?

Thank you.谢谢你。

Was able to fix this by adding能够通过添加来解决这个问题

<EnableUnsafeBinaryFormatterSerialization>true</EnableUnsafeBinaryFormatterSerialization>

and

<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" />

to csproj file as stated here: Issue到 csproj 文件,如下所述: Issue

Also I had to set the RuntimeIdentifier to win7-x64 in my publish profile:此外,我还必须在我的发布配置文件中将 RuntimeIdentifier 设置为 win7-x64:

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM