Powershell and enums defined in C++/CLI assembly
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 /开发者_Go百科d 1
reg add hklm\software\wow6432node\microsoft\.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1
Has anyone had issues like this?
It works for me. My steps:
I build a C++/CLI .NET 4.0 assembly with a single source file (except stdafx.*):
#include "stdafx.h"
namespace Fix
{
public enum class Side
{
SideBuy = '1',
SideSell = '2'
};
}
Then I create and invoke this test script:
Add-Type -Path "C:\...\TryEnum40.dll"
[Fix.Side]::SideBuy
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).
<?xml version="1.0"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319"/>
<supportedRuntime version="v2.0.50727"/>
</startup>
</configuration>
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?
精彩评论