10

Iv'e downloaded a C# interval tree collection class class from here http://intervaltree.codeplex.com/SourceControl/list/changesets -> Right hand side -> Download.

However I can't open the whole project on my Microsoft Visual C# 2010 Express (that also runs C# XNA) because

Solution folders are not supported in this version of the application

Also I just want the class to use separately in my own seprate project.

I tried to copy the three important seeming files Interval.cs, IntervalNode.cs and IntervalTree.cs into my project but this generated the compile error

There are no importers which handle this file type

I've also tried to copy and paste the contents of the three files into my project, encapsulating them into there own namespace as well as there was a lot of code. I had to rearange some of the usings a little but have run into the problem that possibly it wants PowerCollections .dll and .pcb files as using Wintellect.PowerCollections; causes

The type or namespace name 'Wintellect' could not be found (are you missing a using directive or an assembly reference?)

I'm not sure how to continue or if I'm doing the right thing at all in how to get this class to work.

alan2here
  • 3,223
  • 6
  • 37
  • 62
  • just check whether you have that dll in the list of references and whether it is present in the past enlisted in there. since you said you are using studio express, I'm not sure you will have the test framework which they have used. I had no problems with using this set up except inside the code, a few asserts failed. while two asserts on build time depends on what your system is doing at the time, there is one assert getting the intersections which has to be changed to reference the first array's count. – King Jan 08 '12 at 15:40
  • create a project ( a class library project) and add the reference to that [dll](http://powercollections.codeplex.com/releases/view/6863) depending on the platform you are going to build on (x86/x64) and build it. – King Jan 08 '12 at 15:59
  • 1
    This is not really a code question. – John Alexiou Jan 08 '12 at 16:09
  • 3
    But would the OP really get a correct answer anywhere else? – Jonathon Reinhart Jan 08 '12 at 16:21
  • 2
    @ja72 according to the faq, questions concerning "software tools commonly used by programmers" are appropriate for stackoverflow. – phoog Jan 08 '12 at 16:30

4 Answers4

14

Add the library to your solution

Copy the IntervalTreeLib directory into your solution directory. Then, right-click your solution, and add existing project. Point it at IntervalTreeLib.csproj in IntervalTreeLib, and click Open. That should add the IntervalTreeLib project to your solution.

Add Existing Project Screenshot

Add a reference to the library in your project

Then, in your project, add a reference to the IntervalTreeLib proejct: - Right click the References folder, and Add Reference. Click the Projects tab, and select IntervalTreeLib.

Add Reference Screenshot

Select Project Reference Screenshot

Use the classes in your code

To use classes from the library in your source then, you need to either add:

using IntervalTreeLib;

void Foo() {
    IntervalTree<int, int> tree = new ...
}

Or, refer to them by their full name:

IntervalTreeLib.IntervalTree<int, int> tree = new ...
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • Thanks, looks ok so far, very promising. I've got "The type or namespace name 'IntervalTree' could not be found (are you missing a using directive or an assembly reference?" when I try and use "IntervalTree intervals = new IntervalTree();". The "IntervalTreeLib" namespace seems equally missing. – alan2here Jan 08 '12 at 15:52
  • The type or namespace name 'IntervalTreeLib' could not be found (are you missing a using directive or an assembly reference?) – alan2here Jan 08 '12 at 16:00
  • Did you successfully add the reference to that project? And are the IntervalTreeLib files unmodified? – Jonathon Reinhart Jan 08 '12 at 16:01
  • I did "add -> existing project" and the three .cs files appeared inside a new item called IntervalTreeLib in the solution explorer. – alan2here Jan 08 '12 at 16:03
  • I just walked through the procedure above, and it all seems to work (granted this is with VS2010, not express, but it should work the same for you.) – Jonathon Reinhart Jan 08 '12 at 16:04
  • Okay, but you need to add a reference *in your project* to the IntervalTreeLib project, so that your code knows where to find that stuff. Then, you can use the classes in either of the two ways I've shown above. – Jonathon Reinhart Jan 08 '12 at 16:05
  • I've done the first paragraph of your description resulting in this http://img225.imageshack.us/img225/48/40418343.png Beyond this how do I add a reference in my project to the IntervalTreeLib project? – alan2here Jan 08 '12 at 16:11
  • I said it right there in my answer! Under your project, right click the References folder, and click Add Reference! Everything is above. – Jonathon Reinhart Jan 08 '12 at 16:12
  • Sorry. It's not as a straightforward as it could be but you'r answer is good. I think following you'r answer iv'e got it working now. – alan2here Jan 08 '12 at 16:20
  • Fantastic :¬) The answer is even better now with the pictures. I bet so many people have this problem. I wish I could give you more than one upvote. – alan2here Jan 08 '12 at 16:47
4

Open the IntervalTreeLib.csproj file if you want to be able to open the project in it's entirety (or in your current solution add an existing project (you can right-click on the solution) and select the IntervalTreeLib.csproj). If you are trying to grab just the code file in your project, ensure you also grab the PowerCollections.dll file (I see it is in the same folder as the code files) or your code will not compile (as you have discovered). You'll need to add a reference to it and include the needed using statement at the top of the code files making use of this library (or use fully qualified name with the namespace).

using IntervalTreeLib;

or

var myObj = new IntervalTreeLib.[WhateverClass](...);

Also, make sure you read the license.txt file. You may need to include it if you are using the code. Give credit where it is due.

UPDATE:

If the test project is causing you problems, just open the library project. Ideally you could just open that and compile it, adding the output DLL files that are generated directly into your solution. This is ideal unless you are planning on changing the library source code itself.

Jason Down
  • 21,731
  • 12
  • 83
  • 117
  • When I tried to open the csproj file, it went ahead and opened the .sln file anyway. And that will cause with OP issues. – Jonathon Reinhart Jan 08 '12 at 15:34
  • @JonathonReinhart: Well then better for him to do it the second way of adding an existing solution I guess. Can't test it here myself (on my Linux box this morning). – Jason Down Jan 08 '12 at 15:42
  • The set up itself worked just as it should. but as he is using different version of studio, he cannot open it as it is. But he can add everythign and then he should have referenced the dll properly. Just seeing the list of references and the path of the dll should do it. – King Jan 08 '12 at 15:46
  • @King: In theory he should be able to ditch the test project and open up the library project. This is not using the solution file and does not include the test code that he may not be able to load. If he is using VS 2010 and the project was written in an older version of VS, then he should be able to upgrade the project through the conversion wizard. That is assuming the conversion wizard is included in the express edition (I'm not sure if it is only available in the $$ version). – Jason Down Jan 08 '12 at 15:49
  • That is where his problem is. The solution project is in vs2010 professional or ultimate. While Visual studio has capabilities for upgrade, it doesn't allow the other way which makes perfect sense too. He should just create a project by himself ( a class library project) and add the reference to that [dll](http://powercollections.codeplex.com/releases/view/6863) depending on the platform he is going to build on (x86/x64) and build it. It works a charm. Its only must be an issue of adding the references. – King Jan 08 '12 at 15:58
  • It's all worked (I've been following Jonathon Reinhart as he posted first but they seem the same). Except that in game.cs Intelisence can't see IntervalTreeLib and it dosn't seem to exist. – alan2here Jan 08 '12 at 15:59
  • you are able to build the library but not use it in your project. Is that your question ? – King Jan 08 '12 at 16:03
  • @alan2here: Make sure you include the `using` statement at the top of the game.cs file. – Jason Down Jan 08 '12 at 16:06
  • @King, if he simply references the *project* in his own solution, he doesn't need to even point it at the DLL, VS will take care of that for him. – Jonathon Reinhart Jan 08 '12 at 16:06
  • The using fails because it can't see the namespace "IntervalTreeLib" as existing. – alan2here Jan 08 '12 at 16:08
  • @alan2here Did you add the reference, as I mentioned? – Jonathon Reinhart Jan 08 '12 at 16:10
  • I thought you were refering to the "right-click on the solution and select the IntervalTreeLib.csproj" part. How do I add the referance? – alan2here Jan 08 '12 at 16:12
  • @alan2here I tried in express edition and it worked. See below. – King Jan 08 '12 at 16:12
  • proj -> proj -> referances -> add referance -> IntervalTreeLib? – alan2here Jan 08 '12 at 16:14
3

Add the library to the references of the project you want to use it.

enter image description here

Harrish Selvarajah
  • 1,763
  • 12
  • 11
0

Since discussing that you are able to build Intervallib.dll, we will discuss about how you should the dll in your project.

Now in your proj, right click on the references part and add the dll intervallib.dll to your references. In your game.cs file, have the reference to the namespace as -- using IntervalTreeLib;

then you should actually copy the dll powercollections.dll to the bin directory of proj directory also.

you should copy this dll because there is an indirect link to the dll as it is used in IntervalTreeLib.dll

following these steps, I was able to execute this project.

King
  • 1,170
  • 2
  • 16
  • 33