This project has moved and is read-only. For the latest updates, please go here.

Intellisense for my custom .net libraries

May 14, 2014 at 10:49 PM
Ok, First. Amazing tool. Just awesome.

I'm hosting IronPython 2.7.4 in an application to provide scripting.
The intellisense that I need is for my application dlls exposed to Ironpython.

I've read on the internets that the only way to get this to work is to put assemblies into the GAC. This is a horror story for me. The GAC is not fun or useful in my situation as it adds overhead to my deployment strategy.

Is there any way to provide PTVS with the information it needs to get intellisense for dlls in a local bin folder?

As a workaround I wonder if I could define an IP file as a wrapper to my internal dll types and get intellisense that way.
May 15, 2014 at 12:46 AM
You should just need to add a reference to the DLL to get IntelliSense. See our References doc page for details on how to do this.

You may also need a search path to help IronPython find it when running your application, though if it currently works then that's probably unnecessary. Ideally we wouldn't require two steps here, but right now we do (though they're doing quite different things, and it helps some people to keep them separate, so maybe it's better this way).
May 15, 2014 at 12:54 AM
Note that this would require actually having a PTVS project. If what you have right now is a C# project for your app, and a bunch of .py files somewhere in a subfolder, then you'll have to add a PTVS project to your solution and use Add as Link on all those files.
May 30, 2014 at 6:35 AM
Thanks for the reply.
Nothing suggested works (unless I'm missing something)
I have added references to my dll's in my Python project.
I have added search paths
No intellisense other than "unknown type".
May 30, 2014 at 5:28 PM
You may also need to have an import clr statement in the file (or possibly just the project...).

The IronPython mode of our code analysis was designed for running in ipy.exe, where importing clr is an indicator that you want it to be special. It's possible that we need to see that statement to look at any .NET libraries, though I'm not sure as I've never spent much time looking an the code.

Depending on how you're using your hosted IronPython may make a difference here (I've done it myself and know that there's a few different approaches). Chances are we don't currently support any of them very well... :(
May 30, 2014 at 6:32 PM
Still having issues but I did get closer.
The first problem was that I didn't have IronPython added to the environment, only Python. This is because I installed Ironpython via Nuget and not from the msi installer. Duh! Once that was set, intellisense was available for standard .net libraries but not mine.

I do have import clr listed in my scripts. I also use clr.AddReference to add my custom libraries (also added as a ref in the Ironpython project).
I just can't get intellisense for my libraries.

Just to be clear, I shouldn't need to add my libraries to the GAC, correct?
Intellisense should work by :
  1. creating a Project for my IronPython scripts
  2. adding my .net libraries as project references
  3. including import clr in my scripts
  4. adding library locations to the search path
PTVS is a fantastic tool, I don't want to sound as if I'm complaining. lol
May 30, 2014 at 6:35 PM
A work around that I'm considering is wrapping my .net api's in another python file that the user will import. It won't give them deep api access or discoverability but they will at least be able to get intellisense to discover the most important functions.
May 30, 2014 at 6:56 PM
Adding the library as a reference and including imports for it should be sufficient. You shouldn't need to GAC them. If you can run your script in IronPython (outside of your hosted process) without error then it should be fine - as I said, we've tested that scenario and not the hosted one.

That workaround is okay. You can even add Python stubs to provide more type information:
if False: # so the code is never actually executed
    def my_func(a, b, c):
        return "a string"
    my_func(123, "abc", [])
my_func will now show up as something like my_func(a: int, b: str, c: list) -> str in the editor.
Jun 2, 2014 at 3:12 PM
I have the same experience. I have added dll to references and the following:
import clr
import os
clr.AddReferenceToFileAndPath(os.path.join(os.getcwd(), "Cheafcso.Eamod.Docgen.Common"))
import Cheafcso.Eamod.Docgen.Common
passes clear when run with Ctrl-F5, but Intellisense does not show anything.

I have created issue: