views:

740

answers:

2

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.

+2  A: 

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.

Don
How can I set this property? When I open Property Pages of the web site, I see list of references, but Copy Local is not available there. Please note that this is web site (not web application)
Konstantin
It's a property of the reference, not the web site. But I see now why you are specifying that it is a web site and not a web application. I'll edit my answer.
Don
I've marked this answer as accepted, thanks Don! However, I still don't understand the logic of VS - if I add local assembly - why search for it in GAC and then reference it from the GAC?
Konstantin
The reference in web.config doesn't specify the location; at run time the assembly will be looked for first in your bin folder, then in the GAC if it's not found locally. It shouldn't search the GAC if you've got it in the bin folder. When adding the reference in VS, the .NET tab only shows what's in the GAC. You'd have to use the Browse tab to find your local reference.
Don
+1  A: 

Hi Konstantin,

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:

  1. If the reference is another project, called a project-to-project reference, then the value is true.
  2. If the assembly is found in the global assembly cache, the value is false.
  3. As a special case, the value for the mscorlib.dll reference is false.
  4. If the assembly is found in the Framework SDK folder, then the value is false. Otherwise, the value is true.

Hope this helps

Muse VSExtensions