Python for .NET compilation for .NET3.5 and Python3.x

橙三吉。 提交于 2019-12-10 11:44:08

问题


Recently I've been working on a project which needs to use a .NET 3.5 Dll library, and the team is using Python3.x environment.

So I went to the Python for .NET's github repo and downloaded the source code and tried compiling myself using Visual Studio 2013.

In the source, there is a MVSC solution file named pythonnet, and I just opened the project and tried compiling Python.Runtime.

By default, the Conditional compilation symbols is PYTHON27, UCS4. So I changed it to PYTHON35, UCS2 to match my requirement. And I was able to compile it successfully.

But since it needs to work with .NET Framework 3.5, then I changed Target Framework from .NET Framework 4.0 to .NET Framework 3.5. But this time I got a lot of errors when compiling and the compilation failed.

Could anyone please help me with the compilation so that I can compile the Python for .NET which works for both .NET 3.5 and Python3.x?


回答1:


Latest pythonnet is using HashSet from CLR 4.0 and also dynamic from DLR which cannot be easily backported to older .NET versions.

What you can do is redirect your other DLLs from .NET 3.5 to CLR 4.0 using app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0"/>
    </startup>
</configuration>


来源:https://stackoverflow.com/questions/37477439/python-for-net-compilation-for-net3-5-and-python3-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!