A: 

I would start by checking the "using" statments in your code files as well as any references in your .aspx, .ascx files. It sounds like you've referenced some of these (I know some are added by default from the Add New Item templates.

tforster
Not from my web-site, but through a shared assembly that references them.
Ian Boyd
References are not added by "using" statements.
erikkallen
Using statements have nothing to do with references.
Sebastian Good
+1  A: 

Remove the References.

  • If it is a web app: you can see the References under Solution Explorer.

  • If it's a website: right-click the project on Solution Explorer then select Property Pages. Manage them there.

HTH

Ferry Meidianto
Bah. i remove them from the Web-Site's **Property Pages**, but they come back next build.
Ian Boyd
+1  A: 

If a shared assembly references them, then they will be added to the calling project as well.

Since the Avatar library makes these other references, Visual Studio adds these references to the main project as well. Otherwise, a call into the Avatar library could fail since the reference it needs is missing.

David
Could, but in reality won't. And if someone forgot to put an assembly on the web-server, i'm okay with the delayed loading of the assembly throwing an error.
Ian Boyd
A: 

I don't believe you can prevent Visual Studio from automatically adding references to assemblies that are referenced by others.

One solution is to create a Web Setup project with a custom action that automates the removal of these unwanted assembly references from the web.config.

Mitch Wheat
+5  A: 

Maybe the "Avatar DotNet Library" is referencing those assemblies by itself. The references of a referenced assembly are needed to correctly deploy a project. Otherwise, how could the referenced assembly work?

Note that it's possible that your referenced assembly does not use its own references, although they exists.

Edit: You can use the great tool ".Net Reflector" to check this.

Juan Calero
The **Avatar DotNet Library** does indeed reference those assemblies. But the references of a referenced assembly are **not** needed to correctly deploy a project - because the referenced assemblies are never used.
Ian Boyd
Ok, I understand. But Visual Studio will, logically, add those assemblies, because it's probable they will be used.If Avatar Dot Net is a project you can modify, I recommend you to redesign the architecture and divide it in different assemblies and put all those unused references in a new assembly that you don't need to reference in your project.
Juan Calero
Problem with that solution, juancalero, is that it will be split up into different assemblies. Rather than one dll we'll have 10 or 20.
Ian Boyd
And the question still remains, how to stop Visual Studio from doing what it thinks is best.
Ian Boyd
I think you can't (or the solution it's too complicated). If you can't make it work, use the workaround you like the most. That's the reason of my answer. I tried to give you a workaround that worked for me.
Juan Calero
+1  A: 

Sorry, you cannot stop Visual Studio from adding assemblies to your web.config, but all is not lost.

I have hit this in the past; someone had added some references (including WinForms) to a low level data access assembly. The web-site used the low level data access assembly and therefore had WinForms etc added to the web.config file.

The solution was to move his code into the correct assembly and remove the incorrect reference.

If you can not sort how the assembly that has the unwanted references and you know you are not calling code that depends on the unwanted references. Then you can (none of these are nice)

  • Write a custom install action that automates the removal of these unwanted assembly references from the web.config
  • Write a custom MSBUILD action to remove then at the time of the build
  • Use a different hand-written web.config file when the application is installed.

It can take ages to find how why Visual Studio is adding a reference to the web.config file. You have to hand-check EVERY assembly that is used directly or indirection by the web site.

Ian Ringrose
Oh dear god. This opens up a whole can of worms, that cuts into why Visual Studio and Subversion were designed the way they were.
Ian Boyd
+3  A: 

I had this problem with Visual Studio 2005 (but I'm happy to report that the solution works for VS 2008, see bolded text below). There is a registry section that VS checks before it adds assemblies to the web.config file.

Here is the key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{E24C65DC-7377-472B-9ABA-BC803B73C61A}\FilteredGACReferences

So, let's say you don't want Visual Studio to add the Microsoft.VisualStudio.Designer.Interfaces assembly to your web.config. Add the following entry to your registry and you are set.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Projects\{E24C65DC-7377-472B-9ABA-BC803B73C61A}\FilteredGACReferences\Microsoft.VisualStudio.Designer.Interfaces

It worked perfectly for me. And yes, the rest of your team will have to do the same, but at least you don't have to manually remove the entries every time :)

To make it work for VS 2008 - just change the 8.0 in the registry path to 9.0

Nebakanezer
Sounds like a fine idea, except it has to be added to everyone's computer, updated periodically.
Ian Boyd
While this a terrible thing for MSFT to make us do, it seems like the only practical solution.
Sebastian Good
Looks like this solution was expounded here, to give credit where due. http://davidovitz.blogspot.com/2006/03/webconfig-contains-assembly-references.html
Sebastian Good
A: 

Those are all the assemblies required by your project, in some shape or manor and the aid the compilation that ASP.NET does on your pages at runtime. They are probably being imported in by either by code you are using in your project or another library that is using them.

But according to the documentation. These are the assemblies defined in your global web.config which can be found in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG:

<assemblies>
    <add assembly="mscorlib" />
    <add assembly="System, ..." />
    <add assembly="System.Configuration, ..." />
    <add assembly="System.Web, ..." />
    <add assembly="System.Data, ..." />
    <add assembly="System.Web.Services, ..." />
    <add assembly="System.Xml, ..." />
    <add assembly="System.Drawing, ..." />
    <add assembly="System.EnterpriseServices, ..." />
    <add assembly="System.Web.Mobile, ..." />
    <add assembly="*" />
</assemblies>

If you look there is an assembly="*" reference being added. And if you read the documentation about this command it says:

Optionally, you can specify the asterisk (*) wildcard character to add every assembly within the private assembly cache for the application, which is located either in the \bin subdirectory of an application or in the.NET Framework installation directory (%systemroot%\Microsoft.NET\Framework\version).

This means that any assembly in your /bin directory or in the .NET Framework installation directory is going to be included already.

What this tells me about your problem is that those assemblies that are being included are already referenced in some way to your project. And they are probably coming from the Avatar Dot Net Library or some controls on your page. Check the "References" folder in your Visual Studio project on the Avatar Library for these references you don't want. Because that is where the build process gets these libraries from.

So in other words if you don't want them to be included scrub your referenced projects of all references of these libraries.

Alternatively you can use a MSBuild XML parser to drop that section of the web.config each time you run your build process. Personally I use a task called XmlUpdate to modify certain parts of my web.config to get it production ready. If you would like to do the same it is part of the MSBuild Community Tasks.

Nick Berardi
+2  A: 

Convert you "Web Site" project to a "Web Application" project.

A "Web Site" does not have a project file, so it contains all assembly references in the web.config. A "Web Project" has a project file, and all references are stored in the project file.

Pete
+1  A: 

I know and appreciate why Microsoft invented Web Sites in ASP.NET 2.0, but sometimes they just plain suck. If it is practical for you, convert your site to a Web Application Project, and problems like this will go away.

If that is not practical for you, try to re-factor as much code as possible into a separate class library project. Any references you can move out of the web site and into the class library will cut down on web.config changes.

EDIT: To clarify, in a Web Site, the aspnet compiler compiles everything (markup, code-behind, the lot), so all assembly references must go into web.config. However, in a Web Application Project, the C# or VB compiler compiles the code-behind files into a separate DLL, which is then referenced by the aspnet compiler when it compiles the markup. In this scenario, assemblies that are only referenced in code-behind files will go into the code-behind DLL and not touch web.config at all. Only assemblies that are directly referenced in markup will go into web.config.

Christian Hayter
i would at least need to know what a Web Application Project is. Is it WebForms with .cs code-behind files?
Ian Boyd
A Web Application Project is a normal project, with a normal project file, that just happens to be hosted in IIS or VSDS, contain `aspx` files and a `web.config` file. A Web Site is a strange construct where Visual Studio just guesses what's in your project from the contents of the folders on disk. There is no project file. Describing all the differences would fill several pages of text, so here's a link - http://msdn.microsoft.com/en-us/library/ms227432.aspx
Christian Hayter
+1  A: 

Well this might seem like a hack but given your requirements another option would be to load the Avatar assembly dynamically using Assembly.Load or LoadFrom at runtime. This would keep a reference out of the main project and should then prevent the extra reference lines in the web.config. This would only really be practical though if you were only using a small number of classes from the Avatar project. I would make a third project that both projects referenced that held interfaces that one or more Avatar classes implemented in order for the main project to maintain strict typing when handling Avatar instances. I admit this could be a lot more work that previously submitted answers. If your interested in this method search google for creating plugins in .Net

Tim Santeford
+1  A: 

As long as you are using a website, rather than a webapp, I don't know of any way to stop Visual Studio from adding assemblies to your web.config. This same problem of sorts happens for my company's solutions as well.

Brisbe42
+1  A: 

You cannot stop Visual Studio from adding assemblies to your web.config.

manu08
A: 

If you are running on a vista or server 08 machine, you can use the appcmd command line utility to remove it after rebuilding rather than manually removing it.

http://technet.microsoft.com/en-us/library/cc772200(WS.10).aspx http://learn.iis.net/page.aspx/114/getting-started-with-appcmdexe/

tb
A: 

Hello,

see http://msdn.microsoft.com/en-us/library/ms178728.aspx

there it's explained that what you see in Property Page is not all, implicit references exist also in Machine.config file and are added at compile time. Hope this helps.

najmeddine