如何将 VB.NET 类添加到 GAC,并在代码隐藏中使用它
我创建了一个 VB.NET 类,并创建了一个强密钥,并将其添加到 GAC使用 GacUtil。这部分进展顺利。该程序集已安装在 GAC 中,并且似乎已正确安装/配置。
仅供参考,该程序集是一个名为 Tester 的类,它公开一个名为 HelloWorld 的公共静态方法,该方法返回一个字符串“Hello World”。
下一步是使用 Visual Studio 2005、Windows XP SP3 创建一个测试 Web 应用程序(VB.NET 和 ASP.NET 2.0)。我创建了测试 Web 应用程序并将以下内容添加到 web.config 文件的配置部分。
<assemblies>
<add assembly="BenGACTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e5b6cecb56999ca" />
</assemblies>
然后,我向我的 aspx 页面添加了一些内联代码,如下所示:
<div><%=BenGACTest.Tester.HelloWorld()%></div>
当我在 Web 浏览器中运行该页面时,实际上一切都按预期运行。该页面输出“Hello World”,一切看起来都很好。
但是,我不知道如何在 代码隐藏< /a> 页面。我尝试导入程序集,就像“导入系统”一样,但它没有出现在 IntelliSense 中。
此外,当我尝试将程序集添加为项目的引用时,在已安装程序集的列表中找不到该程序集。我相信这是因为该列表是从注册表中提取的,而不是从已安装程序集的动态列表中提取的。
我的目标是通过 web.config 文件添加程序集,而不是将其添加为项目引用,并在代码隐藏页面中使用程序集。
有什么想法吗?
I created a VB.NET Class, and created a strong key, and added it to the GAC using the GacUtil. That part has gone smoothly. The Assembly is installed in the GAC and seems to be installed/configured correctly.
FYI, the assembly is a Class called Tester, that exposes one public static method called HelloWorld, which returns a string, "Hello World".
The next step was to create a test web application (VB.NET and ASP.NET 2.0), using Visual Studio 2005, Windows XP SP3. I created the test web application and added the following to the web.config file's configuration section.
<assemblies>
<add assembly="BenGACTest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e5b6cecb56999ca" />
</assemblies>
I then added some inline code to my aspx page as follows:
<div><%=BenGACTest.Tester.HelloWorld()%></div>
When I run the page in the web browser, indeed everything works as expected. The page outputs "Hello World" and all seems good.
However, I don't know how to use this code in the code-behind page. I try to import the assembly, just like "imports system" and it doesn't appear in the IntelliSense.
Also, when I try to add the assembly as a reference to the project, the assembly is not found in the list of installed assemblies. I believe this is because the list is pulled from the registry, not from a dynamic list of installed assemblies.
My goal is to add the assembly via the web.config file, not by adding it as a project reference, and to use the assembly in the code-behind page.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需引用本地版本即可在 Visual Studio 中使用 DLL,.NET 在运行应用程序时将优先使用 GAC 版本。此外,我认为当 DLL 在 GAC 中可用时,您不必发布该 DLL,但您必须通过菜单“项目”->“添加引用”来引用它。
编辑:此论坛帖子可能会有所帮助:http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/63bf8d34-42ad-4f3c-b0c9-cf7c33d77918。
You can just reference a local version to use the DLL in Visual Studio, .NET will favour the GAC version when running the application. Furthermore, I don't believe you have to ship the DLL when it's available in GAC, yet you have to reference it through menu Project->Add Reference.
Edit: This forumpost might be helpful: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/63bf8d34-42ad-4f3c-b0c9-cf7c33d77918.