【发布时间】:2018-10-21 21:32:11
【问题描述】:
问题
我正在尝试创建一个使用 SimpleInjector 的 PowerShell Core 二进制 cmdlet 库,但在使用 Visual Studio 调试它时无法弄清楚为什么它会导致 FileNotFoundException。
详情
我在 Visual Studio 中创建了一个超级简单的 PowerShell cmdlet 库,面向 .NET Standard 2.0 并使用 PowerShellStandard.Library 包 (v5.1.0-RC1)。 You can view/clone it here。它包含以下 cmdlet:
using System.Management.Automation;
using Newtonsoft.Json.Linq;
using SimpleInjector;
[Cmdlet(VerbsDiagnostic.Test, "SimpleInjectorDependency")]
public class TestSimpleInjectorDependencyCmdlet : PSCmdlet
{
protected override void ProcessRecord()
{
var container = new Container();
WriteObject("Success!");
}
}
结果是FileNotFoundException:
这似乎特定于 SimpleInjector,因为使用例如 json.net 执行相同的操作没有问题:
using System.Management.Automation;
using Newtonsoft.Json.Linq;
using SimpleInjector;
[Cmdlet(VerbsDiagnostic.Test, "JsonDotNetDependency")]
public class TestJsonDotNetDependencyCmdlet : PSCmdlet
{
protected override void ProcessRecord()
{
var j = new JObject();
WriteObject("Success!");
}
}
我真的不明白这里发生了什么。我什至不确定这是否真的特定于 SimpleInjector,或者是否还有其他因素在起作用。如果有人能赐教,我将不胜感激!
【问题讨论】:
-
这通常是构建或 NuGet 问题,但老实说,我不确定我是否会使用 DI 容器来构建我的 PowerShell 命令行开关。它们通常足够小,可以使用 Pure DI。
-
无论这种方法是否是一个好主意,我仍然想了解正在发生的事情。称其为纯粹的好奇心。
标签: c# powershell .net-standard simple-injector powershell-core