void AssignToGroup(BuildProvider buildProvider, List <BuildProviderGroup> groups)
        {
            if (IsDependencyCycle(buildProvider))
            {
                throw new HttpException("Dependency cycles are not suppported: " + buildProvider.VirtualPath);
            }

            BuildProviderGroup myGroup       = null;
            string             bpVirtualPath = buildProvider.VirtualPath;
            string             bpPath        = VirtualPathUtility.GetDirectory(bpVirtualPath);
            bool canAdd;

            if (BuildManager.HasCachedItemNoLock(buildProvider.VirtualPath))
            {
                return;
            }

            if (buildProvider is ApplicationFileBuildProvider || buildProvider is ThemeDirectoryBuildProvider)
            {
                // global.asax and theme directory go into their own assemblies
                myGroup            = new BuildProviderGroup();
                myGroup.Standalone = true;
                InsertGroup(myGroup, groups);
            }
            else
            {
                Type bpCodeDomType = GetBuildProviderCodeDomType(buildProvider);
                foreach (BuildProviderGroup group in groups)
                {
                    if (group.Standalone)
                    {
                        continue;
                    }

                    if (group.Count == 0)
                    {
                        myGroup = group;
                        break;
                    }

                    canAdd = true;
                    foreach (BuildProvider bp in group)
                    {
                        if (IsDependency(buildProvider, bp))
                        {
                            canAdd = false;
                            break;
                        }

                        // There should be one assembly per virtual dir
                        if (String.Compare(bpPath, VirtualPathUtility.GetDirectory(bp.VirtualPath), stringComparer) != 0)
                        {
                            canAdd = false;
                            break;
                        }

                        // Different languages go to different assemblies
                        if (bpCodeDomType != null)
                        {
                            Type type = GetBuildProviderCodeDomType(bp);
                            if (type != null)
                            {
                                if (type != bpCodeDomType)
                                {
                                    canAdd = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (!canAdd)
                    {
                        continue;
                    }

                    myGroup = group;
                    break;
                }

                if (myGroup == null)
                {
                    myGroup = new BuildProviderGroup();
                    InsertGroup(myGroup, groups);
                }
            }

            myGroup.AddProvider(buildProvider);
            if (String.Compare(bpPath, virtualPathDirectory, stringComparer) == 0)
            {
                myGroup.Master = true;
            }
        }