如何在c#项目中添加dll
我正在尝试在我的项目中添加一个 [Science.dll] ,这应该是直接的。但我遇到了问题。有人能告诉我为什么吗?
我刚刚从互联网上复制的 C# 项目。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using Science.Mathematics.VectorCalculus;
namespace using_science_dll
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>`enter code here`
}
}
C:\Csharptutorial\using_science_dll\using_science_dll\Program.cs(7,7): 错误 CS0246: 找不到类型或命名空间名称“Science”(是否缺少 using 指令或程序集引用?)< /p>
是因为我我使用的是 VS 2008?
Science.dll
将在以下框架中运行 .Net 4.0 和 Visual C# 2010 Express
I am trying to add a [Science.dll] in my project which should be straight forward. But I am getting a problem. Can someone tell me why?
My C# project which I just copied from internet.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.ComponentModel;
using System.Data;
using Science.Mathematics.VectorCalculus;
namespace using_science_dll
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>`enter code here`
}
}
C:\Csharptutorial\using_science_dll\using_science_dll\Program.cs(7,7): error CS0246: The type or namespace name 'Science' could not be found (are you missing a using directive or an assembly reference?)
Is it because I am using VS 2008?
Science.dll
will run in the following frame .Net 4.0 and Visual C# 2010 Express
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
DLL 必须始终存在 - 正如名称所示,引用仅告诉 VS 您正在尝试使用 DLL 中的内容。在项目文件中,VS存储了引用的DLL的实际路径和文件名。如果您移动或删除它,VS 将无法再找到它。
我通常在项目文件夹中创建一个
libs
文件夹,将未安装到 GAC 的 DLL 复制到其中。然后,我实际上将此文件夹添加到 VS 中的项目中(在 VS 中显示隐藏文件,然后右键单击并“包含在项目中”)。然后,我引用该文件夹中的 DLL,因此在签入源代码管理时,也会签入该库。这使得当多个开发人员必须更改项目时变得更加容易。(请确保将项目中的 DLL 的构建类型设置为“无”并且“不复制到输出文件夹”。)
PS:我使用德国 Visual Studio,因此我引用的标题可能与英文版...
The DLL must be present at all times - as the name indicates, a reference only tells VS that you're trying to use stuff from the DLL. In the project file, VS stores the actual path and file name of the referenced DLL. If you move or delete it, VS is not able to find it anymore.
I usually create a
libs
folder within my project's folder where I copy DLLs that are not installed to the GAC. Then, I actually add this folder to my project in VS (show hidden files in VS, then right-click and "Include in project"). I then reference the DLLs from the folder, so when checking into source control, the library is also checked in. This makes it much easier when more than one developer will have to change the project.(Please make sure to set the build type to "none" and "don't copy to output folder" for the DLL in your project.)
PS: I use a German Visual Studio, so the captions I quoted may not exactly match the English version...
您是否已将 dll 添加到项目引用列表中?
如果没有,请右键单击项目“References”文件夹并选择“Add Reference”,然后使用浏览找到您的 science.dll,选择它并单击“确定”。
编辑
我看不到某些人提到的您的 VS 实例的映像,我注意到您现在说它可以在 Net4.0 和 VS2010 中运行。
VS2008项目默认支持NET 3.5。我预计这就是问题所在,因为您的 DLL 可能兼容 NET 4.0,但不兼容 NET 3.5。
Have you added the dll into your project references list?
If not right click on the project "References" folder and selecet "Add Reference" then use browse to locate your science.dll, select it and click ok.
edit
I can't see the image of your VS instance that some people are referring to and I note that you now say that it works in Net4.0 and VS2010.
VS2008 projects support NET 3.5 by default. I expect that is the problem as your DLL may be NET 4.0 compliant but not NET 3.5.
在解决方案资源管理器下的右侧栏中,您可以看到“科学”引用旁边被标记为警告。这要么意味着它无法找到它,要么意味着它因其他原因而反对它。虽然是这种情况,并且您的代码需要它(并且不仅仅在引用列表中),但它不会编译。
请发布警告消息,我们可以进一步帮助您。
In the right hand column under your solution explorer, you can see next to the reference to "Science" its marked as a warning. Either that means it cant find it, or its objecting to it for some other reason. While this is the case and your code requires it (and its not just in the references list) it wont compile.
Please post the warning message, we can try help you further.