Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create Library project

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

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

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

like image 847
cnd Avatar asked Jan 22 '23 00:01

cnd


1 Answers

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).

like image 99
Cameron Avatar answered Jan 30 '23 00:01

Cameron