简体   繁体   中英

How can I add a reference in a Visual Studio website project type?

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

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?

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

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

  • Drop the desired assembly (DLL) into the bin folder
  • Add <%@ Assembly Src="pathToDll" %> or <%@ Assembly Name="assemblyName" %> to the top of your ASPX page.
  • (Optionally) import the namespaces in the new assembly using <%@ Import Namespace="Foo.Bar" %> at the top of the page.

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 (eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM