1

我遵循将我的库类添加到全局程序集的主要说明。

1 - Create a strong name key pair (/ArchieDLLTesting/bin/Debug/ArchieDLLTesting.snk)
2 - Sign the assembly via Visual Studio (Project property, Sign, Browse that file and Save)
3 - Installing into the GAC (gacutil –I /ArchieDLLTesting/bin/Debug/ArchieDLLTesting.dll)

这是图书馆的代码(对于我拥有的唯一/单一类):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ArchieDLLTesting
{
    public class ArchieSayHello
    {
        public ArchieSayHello()
        {
        }

        public string SayHello()
        {
            return "Hello Archimedo";
        }
    }
}

全部操作成功!现在,如果我打开一个空项目,然后输入例如:

using ArchieDLLTesting;

它没有找到该程序集。我检查了 Windows/assembly/GAC_MSIL 文件夹,没有我的 DLL。

那么这里有什么问题呢?

4

3 回答 3

3

当然,您仍然需要添加对 DLL 的引用。仅插入一条using语句不会使用 GAC 中的 DLL。

于 2013-10-02T10:17:20.160 回答
2

I think you have confused what GAC means:

Global Assembly Cache is a central repository where you can store the assemblies that many application needs.

If you put an assembly in the GAC than you can reference it witouth needing the physical assembly in the bin directory

Think about Framework assembly

You don't need to copylocal them when you reference it.

So the solution is to add that reference to your project

Anyway it is not a good practice to put assembly in the GAC

There are very few situation when you should put them there:

When should I deploy my assemblies into the GAC?

于 2013-10-02T10:25:47.510 回答
2

似乎您的机器是 win 7,然后您的 dllC:\Windows\Microsoft.NET\assembly\GAC_64C:\Windows\Microsoft.NET\assembly\GAC_32.it 取决于您的位版本。只需检查那些文件夹。您的项目中的任何方式都绝对是您should add as project reference的那个dll。当运行时框架从 GAC 的 dll 中引用时。

更新:

但是,如果您继续更新 GAC dll 项目[ ArchieDLLTesting],请再次注意 GAC。否则运行时您的应用程序会引用该程序集的旧版本。在这种情况下,您可以使用以下构建后事件在该特定项目上自动将构建事件添加到 GAC。

"%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\x64\gacutil.exe" /i "$(TargetPath)"
于 2013-10-02T10:22:22.150 回答