使用其他代码的 C#
我从这里下载了一个 C# 间隔树集合类 http://intervaltree.codeplex.com/ SourceControl/list/changesets ->右手边->下载。
但是,我无法在 Microsoft Visual C# 2010 Express(也运行 C# XNA)上打开整个项目,因为
此版本的应用程序不支持解决方案文件夹
另外,我只想在我自己的单独项目中单独使用该类。
我尝试将三个看似重要的文件 Interval.cs
、IntervalNode.cs
和 IntervalTree.cs
复制到我的项目中,但这生成了编译错误
没有处理此文件类型的导入程序
我还尝试将三个文件的内容复制并粘贴到我的项目中,将它们封装到自己的命名空间中,并且有很多代码。我不得不稍微重新安排一些用法,但遇到了一个问题,可能它需要 PowerCollections .dll 和 .pcb 文件作为 using Wintellect.PowerCollections;
原因
找不到类型或命名空间名称“Wintellect”(是否缺少 using 指令或程序集引用?)
我不确定如何继续,或者我不确定在如何获取此类方面是否做了正确的事情去工作。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将库添加到您的解决方案
将 IntervalTreeLib 目录复制到您的解决方案目录中。然后,右键单击您的解决方案,然后添加现有项目。将其指向 IntervalTreeLib 中的
IntervalTreeLib.csproj
,然后单击“打开”。这应该将 IntervalTreeLib 项目添加到您的解决方案中。在您的项目中添加对库的引用
然后,在您的项目中添加对 IntervalTreeLib 项目的引用:
- 右键单击引用文件夹,然后添加引用。单击“项目”选项卡,然后选择“IntervalTreeLib”。
在代码中使用类
要在源代码中使用库中的类,您需要添加:
或者,通过全名引用它们:
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 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.
Use the classes in your code
To use classes from the library in your source then, you need to either add:
Or, refer to them by their full name:
如果您希望能够完整打开该项目,请打开 IntervalTreeLib.csproj 文件(或者在当前解决方案中添加现有项目(您可以右键单击该解决方案)并选择
IntervalTreeLib.csproj
)。如果您尝试仅获取项目中的代码文件,请确保还获取 PowerCollections.dll 文件(我看到它与代码文件位于同一文件夹中),否则您的代码将无法编译(正如您所发现的)。您需要添加对其的引用,并在使用该库的代码文件顶部包含所需的 using 语句(或使用带有命名空间的完全限定名称)。或者
此外,请确保您阅读了 license.txt 文件。如果您使用该代码,则可能需要包含它。给予应得的信任。
更新:
如果测试项目给您带来了问题,只需打开库项目即可。理想情况下,您可以打开它并编译它,将直接生成的输出 DLL 文件添加到您的解决方案中。除非您打算更改库源代码本身,否则这是理想的选择。
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 theIntervalTreeLib.csproj
). If you are trying to grab just the code file in your project, ensure you also grab thePowerCollections.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).or
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.
将库添加到您要使用它的项目的引用中。
Add the library to the references of the project you want to use it.
既然讨论了您可以构建Intervallib.dll,我们将讨论如何在您的项目中使用该dll。
现在在您的项目中,右键单击引用部分并将 dll Intervallib.dll 添加到您的引用中。在您的 game.cs 文件中,将命名空间引用为 --
using IntervalTreeLib;
那么您实际上应该将 dll powercollections.dll 也复制到 proj 目录的 bin 目录中。
您应该复制此 dll,因为有一个到该 dll 的间接链接,因为它在 IntervalTreeLib.dll 中使用,
按照以下步骤,我能够执行该项目。
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.