如何在C#项目中添加DLL [英] How to add dll in c# project

查看:58
本文介绍了如何在C#项目中添加DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中添加一个 [Science.dll] ,这应该是正确的。但是我遇到了问题。有人可以告诉我为什么吗?

I am trying to add a [Science.dll] in my project which should be staright forward. But I am getting a problem. Can someone tell me why?

我刚刚从互联网复制的C#项目。

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):错误CS0246:找不到类型或名称空间名称'Science'(您是否缺少using指令还是程序集引用?)

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?)

是因为我正在使用VS 2008吗?

Is it because I am using VS 2008?

Science.dll将运行在以下框架中。Net4.0和Visual C#2010 Express

Science.dll will run in the following frame .Net 4.0 and Visual C# 2010 Express

推荐答案

DLL必须一直存在-顾名思义,引用仅表明VS,您正在尝试使用DLL中的内容。在项目文件中,VS存储引用的DLL的实际路径和文件名。如果您移动或删除它,VS将无法再找到它。

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.

我通常创建一个 libs 文件夹在我的项目文件夹中,将未安装的DLL复制到GAC。然后,我实际上将此文件夹添加到VS中的项目中(在VS中显示隐藏文件,然后右键单击并包含在项目中)。然后,我从该文件夹中引用这些DLL,因此在签入源代码管理时,该库也会被签入。这使得当多个开发人员不得不更改项目时变得更加容易。

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.

(请确保将项目中的DLL的构建类型设置为 none和不复制到输出文件夹。)

(Please make sure to set the build type to "none" and "don't copy to output folder" for the DLL in your project.)

PS:我使用的是德语Visual Studio,因此我引用的标题可能与英文版本不完全匹配...

PS: I use a German Visual Studio, so the captions I quoted may not exactly match the English version...

这篇关于如何在C#项目中添加DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆