问题
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