C# – I’ve read that assemblies manually placed inside Bin are also automatically referenced by

asp.netassembliescnet

Q1

We can add assembly reference to a web project via Website –> Add Reference , and assembly will automatically be referenced by all pages in that web project.

But I’ve read somewhere that even if we simply copy ( thus we don’t add it via Website –> Add Reference ) an assembly to the Bin directory of a web project, that it will still be automatically referenced by all pages in that project. But as far as I can tell, that is not the case?!

Q2

A)Deployed web site project also generates PrecompiledApp.config and website1_deploy.wdproy.

Should these two files also be copied to the server?

B) Deployed Web application project also generates WebApplication1.csproj and WebApplication1.csproj.user.

  • Should the two files also be copied to the server? If so, why?

  • I assume obj directory shouldn’t be copied to the Web server?!

thanx

Best Answer

Q1: "add reference" in a web site project means more than just copying the dll to the bin directly. It also means to place a dependency in app.config and to place a hint file which helps Visual Studio to find the dll from the source. This path is used by visual studio to copy the dll back to the bin directly (if somehow it gets removed) and to provide the "update reference" functionality. Having the dll registered in the app.config is essential for the runtime to compile your code using the right version of the dll.

Q2A: website1_deploy.wdproy is not required. PrecompiledApp.config is. This file tells the runtime that the website was already precompiled and that the aspx files are just placeholders for IIS.

Q2B: you don't have to copy all those files. The .csproj file is just for visual studio to keep track of all files in your project. The runtime doesn't do anything with it. The .csproj.user file has your settings, again the runtime doesn't do anything with it. It doesn't even understand it. The obj folder is the temporary directory for the compiler. Also not needed after compilation.