在程序中引用C++/CLI 3.5类库
如果需要在C#中使用C++/CLI 3.5类库,需要添加App.config应用程序配置文件:
<?xml version="1.0"?>
<configuration>
<startup uselegacyv2runtimeactivationpolicy="true">
<supportedruntime version="v4.0.30319">
<supportedruntime version="v2.0.50727">
</supportedruntime></supportedruntime></startup>
</configuration>
另外还需要注意,C#目标平台应该设置为x86,默认的Any CPU不适用于混合程序,否则在64位系统上会产生错误。
如果需要让单独的C++/CLI程序运行在.NET 4.0以上版本,需要自行将App.config复制为与可执行文件同名的.exe.config文件,Visual Studio不会自动复制。