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

Project References to C# project

Mar 11, 2013 at 6:56 PM

I tried PTVS 1.5 with VS.NET 2012 and one of the things that is really important for me is to be able to add the IronPython project(s) to a solution that contains the C# projects. I was able to do it however here are set of issues that I ran into -

a) After adding the reference to the project ("MyClassLibrary") I added following code in my python script

import clr

import MyClassLibrary

The intellisense is able to see the "MyClassLibrary" however when I execute I get an error that the module "MyClassLibrary" could not be found.

I understand that I am not providing the path to the assembly and/or modifying the system path but I would assume that "adding the reference" would have done the trick.

Since I work in a team we work with relative paths and hardcoding the path to "MyClassLibrary" assembly would not work out.

May be I am doing something incorrect.

Please guide

Regards & thanks
Mar 11, 2013 at 7:29 PM
Can you set the output path of your C# project to be the location where your Python code is (or add a post-build step to do the copy)? I think that would should make this work.

In theory this could also be done the other direction if we had MSBuild support ( so that we could copy the Python files to where the C# project is outputted. But I think we actually need a little more than that (we would also need to make F5 run from the output directory). This is something I think we're planning on doing for 2.0, but that won't help you immediately.
Mar 11, 2013 at 7:40 PM
Thanks Dinov for the quick reply.

Unfortunately there will be issues in both the approaches for following reasons -

Setting the post build step and changing the output path are tedious jobs as I took an example of one project. In our source repository we have 20 to 30 projects so adding a post build step for every assembly is a little problem.

When doing development using C# the default settings are that all the outputs of project references are copied to the project's output direction. I think this approach should be there in IronPython projects also.

I see that 2.0 Alpha is out. Is it part of it already or will be available before the 2.0 final release.

Many thanks for replying.

Mar 11, 2013 at 8:00 PM
The build support isn't in the alpha unfortunately - it'll likely be in the next beta.

One other idea is to use AddReferenceToFile() and make sure the output path of the C# assemblies is on sys.path. You can do that by adding the output path to the Search Paths node in the Python project. Then AddReferenceToFile will search sys.path to find the assembly.
Jul 8, 2013 at 6:46 PM
Hi Dinov,

I just noticed the 2.0 Beta release and tried out the same use case I mentioned above and it seems like the requested feature could not make it to this release either.

Is this something planned for next releases ?

Regards & thanks