如何在Visual Studio网站项目类型中添加引用?

时间:2023-01-16 15:52:45

Normally when you add a new assembly you have to go into Visual Studio and add a reference (the .dll is stored in the /bin directory).

通常,当您添加新程序集时,您必须进入Visual Studio并添加引用(.dll存储在/ bin目录中)。

Since this website compiles on the fly, is it possible for me to just add the .dll to the live website, and then use that .dll in an .aspx page?

由于本网站即时编译,我是否可以将.dll添加到实时网站,然后在.aspx页面中使用.dll?

Currently in Visual Studio I can't see the .dll unless I go to 'add reference'.

目前在Visual Studio中,除非我去“添加引用”,否则我看不到.dll。

2 个解决方案

#1


You can indeed reference an assembly without going through Visual Studio. Steps:

您确实可以在不通过Visual Studio的情况下引用程序集。脚步:

  • Drop the desired assembly (DLL) into the bin folder
  • 将所需的程序集(DLL)拖放到bin文件夹中

  • Add <%@ Assembly Src="pathToDll" %> or <%@ Assembly Name="assemblyName" %> to the top of your ASPX page.
  • 将<%@ Assembly Src =“pathToDll”%>或<%@ Assembly Name =“assemblyName”%>添加到ASPX页面的顶部。

  • (Optionally) import the namespaces in the new assembly using <%@ Import Namespace="Foo.Bar" %> at the top of the page.
  • (可选)使用页面顶部的<%@ Import Namespace =“Foo.Bar”%>导入新程序集中的名称空间。

Then reference away!

然后参考!

Adding the reference in Visual Studio is only for compile-time support. Any static references to types in your non-ASPX code (e.g. codebehinds) must be resolved by the compiler, so all DLLs obviously need to be present. Since ASPXs are usually compiled on the server at request time, as long as the referenced DLLs are available then, everything will come together.

在Visual Studio中添加引用仅用于编译时支持。对非ASPX代码中的类型的任何静态引用(例如代码隐藏)必须由编译器解析,因此显然需要存在所有DLL。由于ASPX通常是在请求时在服务器上编译的,只要引用的DLL可用,那么一切都会聚集在一起。

#2


Yes, it's perfectly possible to change the DLL on the live Web site. Just swapping the DLL in the /bin directory will make the application bind to the new one. However, Visual Studio needs the DLL to exist at development time to provide IntelliSense and validate the Web site.

是的,完全可以更改实时网站上的DLL。只是在/ bin目录中交换DLL将使应用程序绑定到新的。但是,Visual Studio需要DLL在开发时存在才能提供IntelliSense并验证Web站点。

#1


You can indeed reference an assembly without going through Visual Studio. Steps:

您确实可以在不通过Visual Studio的情况下引用程序集。脚步:

  • Drop the desired assembly (DLL) into the bin folder
  • 将所需的程序集(DLL)拖放到bin文件夹中

  • Add <%@ Assembly Src="pathToDll" %> or <%@ Assembly Name="assemblyName" %> to the top of your ASPX page.
  • 将<%@ Assembly Src =“pathToDll”%>或<%@ Assembly Name =“assemblyName”%>添加到ASPX页面的顶部。

  • (Optionally) import the namespaces in the new assembly using <%@ Import Namespace="Foo.Bar" %> at the top of the page.
  • (可选)使用页面顶部的<%@ Import Namespace =“Foo.Bar”%>导入新程序集中的名称空间。

Then reference away!

然后参考!

Adding the reference in Visual Studio is only for compile-time support. Any static references to types in your non-ASPX code (e.g. codebehinds) must be resolved by the compiler, so all DLLs obviously need to be present. Since ASPXs are usually compiled on the server at request time, as long as the referenced DLLs are available then, everything will come together.

在Visual Studio中添加引用仅用于编译时支持。对非ASPX代码中的类型的任何静态引用(例如代码隐藏)必须由编译器解析,因此显然需要存在所有DLL。由于ASPX通常是在请求时在服务器上编译的,只要引用的DLL可用,那么一切都会聚集在一起。

#2


Yes, it's perfectly possible to change the DLL on the live Web site. Just swapping the DLL in the /bin directory will make the application bind to the new one. However, Visual Studio needs the DLL to exist at development time to provide IntelliSense and validate the Web site.

是的,完全可以更改实时网站上的DLL。只是在/ bin目录中交换DLL将使应用程序绑定到新的。但是,Visual Studio需要DLL在开发时存在才能提供IntelliSense并验证Web站点。