Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 278
Blankman Avatar asked Jun 05 '09 19:06

Blankman


People also ask

How do I add a reference to Visual Studio project?

You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.

How do I add a website reference in Visual Studio 2019?

To add a Web reference to a project. In Solution Explorer, right-click the name of the project to add the Web service to and then click Add Web Reference. The Add Web Reference dialog box is displayed. In the URL box, enter the URL of the Web service to use.

Which command is used to add reference of Web service to a website?

To add a Web Reference In the URL box of the Add Web Reference dialog box, type the URL to obtain the service description of the Excel Web Services, such as http://<server>/<customsite>/_vti_bin/excelservice.asmx or http://<server>/_vti_bin/excelservice.asmx .


1 Answers

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

like image 59
Rex M Avatar answered Sep 28 '22 12:09

Rex M