简体   繁体   English

如何将VB.NET类添加到GAC,并在隐藏代码中使用它

[英]How to add VB.NET Class to GAC, and use it in Code-Behind

I created a VB.NET Class, and created a strong key, and added it to the GAC using the GacUtil. 我创建了VB.NET类,并创建了一个强键,然后使用GacUtil将其添加到GAC中 That part has gone smoothly. 那部分进展顺利。 The Assembly is installed in the GAC and seems to be installed/configured correctly. 程序集已安装在GAC中,并且似乎已正确安装/配置。

FYI, the assembly is a Class called Tester, that exposes one public static method called HelloWorld, which returns a string, "Hello World". 仅供参考,程序集是一个称为Tester的类,它公开一个名为HelloWorld的公共静态方法,该方法返回字符串“ 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. 下一步是使用Visual Studio 2005,Windows XP SP3创建一个测试Web应用程序(VB.NET和ASP.NET 2.0)。 I created the test web application and added the following to the web.config file's configuration section. 我创建了测试Web应用程序,并将以下内容添加到了web.config文件的配置部分。

<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: 然后,我向aspx页面添加了一些内联代码,如下所示:

<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. 页面输出“ Hello World”,一切似乎都很好。

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. 我尝试导入程序集,就像“导入系统”一样,它没有出现在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. 我的目标是通过web.config文件而不是通过将其添加为项目引用来添加程序集,并在代码隐藏页中使用该程序集。

Any ideas? 有任何想法吗?

You can just reference a local version to use the DLL in Visual Studio, .NET will favour the GAC version when running the application. 您可以引用本地版本以在Visual Studio中使用DLL,.NET在运行应用程序时将优先使用GAC版本。 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. 此外,我认为当GAC中提供DLL时,您不必交付DLL,而必须通过菜单Project-> Add Reference来引用它。

Edit : This forumpost might be helpful: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/63bf8d34-42ad-4f3c-b0c9-cf7c33d77918 . 编辑 :此论坛帖子可能会有所帮助: http ://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/63bf8d34-42ad-4f3c-b0c9-cf7c33d77918。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法使用变量来控制 VB.NET 中代码隐藏页面的 html 标记的 ID? - Is there a way to use variables to control the ID of html tags for a code-behind page in VB.NET? 在代码隐藏文件中使用VB.Net编码填充ASP.Net DropDownList - Populating an ASP.Net DropDownList using VB.Net coding in code-behind file 从javascript(VB.NET)执行代码隐藏功能/子代码 - Perform code-behind Function/Sub from javascript (VB.NET) 如何在代码隐藏中将类CssClass及其属性添加到R​​adioButtonList - How to add class CssClass and its attributes to RadioButtonList in code-behind 如何在asp.net中使用vb.net的类代码 - How to use class code of vb.net in asp.net 在单击后边的代码中将类属性添加到母版页正文标签-vb.net - Add class attribute on click in code behind to Master Page body tag - vb.net 使用 FindControl 从 VB.Net 代码隐藏文件中定位 ASP.Net DetailsView 中的控件不起作用 - Using FindControl to locate controls in an ASP.Net DetailsView from a VB.Net code-behind file not working 如何在代码隐藏中添加GridView列? - How to add a GridView Column on code-behind? 如何在代码隐藏中添加&lt;%=%&gt;标记 - How to add <%= %> tag in code-behind Asp.Net(vb)在代码隐藏中强制回发 - Asp.Net (vb) Force Postback in code-behind
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM