When you use ASP.NET web site (instead of web application model) and add reference to an assembly from local folder, Visual Studio, it seems, understands that this local assembly is also in GAC and so does NOT copy this assembly to bin folder (as it does with non-GAC assemblies), but simply adds new record in web.config file.
Why such a behaviour? Is it possible to force copy to bin folder (I need this since .dll is not on target environment)? I can add assembly to bin folder as file and it will work, but in this case bin folder contents will be in source control, which is not good.
You can set the Copy Local property to True on the reference. That should add it to the bin folder - on a Web Application project.
But for a Web Site project, when you add a reference, all it does is add a line to the web.config that references the assembly. It will look for this file first in the bin folder, and then in the GAC if it is not found.
You have two options: require the assembly to be installed in the GAC on the target machine (in which case, XCOPY deployment is not possible) or include all required assemblies in the bin folder, either by copying them in or writing a post-build script that does so. You can find the .dll by using the command prompt and going to c:\windows\assembly\GAC, find the assembly you are interested in, cd into that directory and then cd into the directory with the version you are interested in. This will give you the path to use in your post-build script. For example, for the Accessibility assembly in the GAC, you'd end up with this path: c:\Windows\assembly\GAC\Accessibility\1.0.5000.0__b03f5f7f11d50a3a\Accessibility.dll
You say including the bin folder contents in source control is not good. This is generally regarded as true for binaries you build, but in your case, you have binary assets that are not compiled as part of your project. Philosophically, these are equivalent to images: binary assets not compiled as part of your project. I would argue they belong in source control as much as any other binary your project relies on. But it is a personal choice.
If you are using a website project in Visual Studio and a reference keeps pointing it to the GAC version instead of some other folder (eg lib), you will need to create a xxxx.dll.refresh
file in your /bin folder, where xxxx is the offending dll you are referencing.
This will resolve build problems with MSBuild too where the server will expect the dll to be in the GAC. The .refresh file will get the file from the correct relative path to do builds correctly.
At run time, assemblies must be in one of two locations: the output path of the project or the global assembly cache (see Working with Assemblies and the Global Assembly Cache). If the project contains a reference to an object that is not in one of these locations, then when the project is built, the reference must be copied to the output path of the project. The CopyLocal property indicates whether this copy needs to be made. If the value is true, the reference is copied. If false, the reference is not copied.
The project-assigned value of CopyLocal is determined in the following order:
Hope this helps
s
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With