开发者

How to create Library project

I can see Console Application , WPF, WinForm, something else

But there is no Library, I need just a library .

开发者_StackOverflow社区

How can I trick it ? Or there is no way to create library with Iron Python ?


I don't know of any out-of-the-box solution, but you can definitely write your Python library (using, say, files with a build action of "None" that have been added to a C#/VB.NET class library project), then manually compile them into a DLL using the following IronPython snippet:

import clr
files = [ 'file1.py', 'file2.py' ]    # Look into os.walk() if you have more than a few files
clr.CompileModules('Foo.dll', *files)

If the code changes often enough, you can run this script as part of the build process (and if it starts taking too long, you can add some code to cache the last-modified dates of all the files and compare before building).

Keep in mind that you'll need to write some code to access your library from your .NET project(s) (it's unfortunately not as simple as adding a reference).


Check IronPython-2.7\Tools\Scripts\pyc.py - it can create both .exe and .dll from Python source.

ipy.exe pyc.py /out:my_dll /target:dll my_dll.py


My understanding is that there is no library project because the DLLs are fully verifiable but I could be wrong on that. There is some extra info on this blog post which goes into a little more detail on the code @Cameron posted.


SharpDevelop has an IronPython - "Class Library" template for creating IronPython dlls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜