C++/CLI 程序集中定义的 Powershell 和枚举
我有一个用 C++/CLI 编写的程序集,其中包含一堆定义如下的枚举,一个接一个地位于单个头文件中。
namespace Fix
{
public enum class Side
{
SideBuy = '1',
SideSell = '2'
};
}
我可以在其他 C# 项目中引用这些类型,并且在 IronPython 中,我可以反映程序集并毫无问题地查看它们。我也已经在 Powershell 中使用它们好几个月了,没有出现任何问题 - 直到现在。我这样引用它们:
[Fix.Side]::SideBuy
我刚刚从 Visual Studio 2008 迁移到 Visual Studio 2010,现在我这样定义的一些枚举对于 Powershell 来说是不可见的。我没有看到声明有任何差异,并且可以毫无问题地反映类型。
这是一个 .NET 4.0 程序集,我已将 Powershell 配置为与 4.0 运行时一起运行。我通过以下注册表更改做到了这一点。
reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
有人遇到过这样的问题吗?
I have an assembly written in C++/CLI that contains a heap of enum defined like the following, one after the other in a single header file.
namespace Fix
{
public enum class Side
{
SideBuy = '1',
SideSell = '2'
};
}
I can reference these types in other C# projects, and in IronPython, I can reflect the assembly and see them all with no trouble at all. I've also been using them in Powershell for many months with no issues - until now. I reference them like this:
[Fix.Side]::SideBuy
I have just moved from Visual Studio 2008 to Visual Studio 2010 and now some of the enums I have defined like this are invisible to Powershell. I don't see any difference in the declarations and I can reflect the types with no problem.
This is a .NET 4.0 assembly and I have configured Powershell to run with the 4.0 runtime. I did that with the following registry changes.
reg add hklm\software\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
Has anyone had issues like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这对我有用。我的步骤:
我使用单个源文件(stdafx.* 除外)构建 C++/CLI .NET 4.0 程序集:
然后创建并调用此测试脚本:
它有效:枚举值按预期打印。
如何配置我的 PowerShell 以与 .NET 4.0 一起使用?我不使用任何注册表技巧。我在 PS 主目录中创建了 XML 文件“powershell.exe.config”(或者在实现 PowerShell 主机的应用程序的主目录中(例如 MyApp.exe.config),我也尝试过这样的场景)。
x64 机器:该文件还需要复制到 C:\Windows\SysWOW64\WindowsPowerShell\
v1.0如果这仍然没有帮助,您能否提供您收到的确切错误消息?
It works for me. My steps:
I build a C++/CLI .NET 4.0 assembly with a single source file (except stdafx.*):
Then I create and invoke this test script:
It works: the enum value is printed as expected.
How do I configure my PowerShell to work with .NET 4.0? I do not use any registry tricks. I create the XML file “powershell.exe.config” in the PS home directory (or in a home directory of an application that implements a PowerShell host (e.g. MyApp.exe.config), I tried such a scenario, too).
x64 machine: the file also needs to be copied to C:\Windows\SysWOW64\WindowsPowerShell\v1.0
P.S. If this still does not help, could you please provide the exact error message that you get?