Example #1
0
        private void UpdateSolution()
        {
            string basePath = m_configuration["solution.path"];

            AddToStatus("Adding AndroMDA support to solution...");

            Project commonProject       = null;
            Project coreProject         = null;
            Project schemaExportProject = null;

            // Create/find the common project
            if (m_configuration["projects.common.create"] == "true")
            {
                AddToStatus("Creating common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.common.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.common.name"], m_applicationObject.Solution);
            }
            //CreateDirectory(basePath + "\\" + m_configuration["projects.common.dir"] + "\\src");
            //CreateDirectory(basePath + "\\" + m_configuration["projects.common.dir"] + "\\target");
            commonProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder);
            commonProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder);

            WriteFile(basePath + "\\" + m_configuration["projects.common.dir"] + "\\project.xml", ParseVariables(Resource1.common_project_xml));

            // Create/find the common project
            if (m_configuration["projects.core.create"] == "true")
            {
                AddToStatus("Creating core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.core.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.core.name"], m_applicationObject.Solution);
            }
            //CreateDirectory(basePath + "\\" + m_configuration["projects.core.dir"] + "\\src");
            //CreateDirectory(basePath + "\\" + m_configuration["projects.core.dir"] + "\\target");
            coreProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder);
            coreProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder);
            WriteFile(basePath + "\\" + m_configuration["projects.core.dir"] + "\\project.xml", ParseVariables(Resource1.core_project_xml));

            // Create the schema export project
            if (m_configuration["projects.schemaexport.create"] == "true")
            {
                AddToStatus("Creating schema export project " + m_configuration["projects.schemaexport.name"] + "...");
                schemaExportProject = VSSolutionUtils.AddConsoleAppProjectToSolution(m_configuration["projects.schemaexport.name"], (Solution2)m_applicationObject.Solution);
                WriteFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\App.config", ParseVariables(Resource1.SchemaExport_App_config));
                WriteFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\nhibernate.config", ParseVariables(Resource1.SchemaExport_nhibernate_config));
                WriteFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\Program.cs", ParseVariables(Resource1.SchemaExport_Program_cs));
                ProjectItem appConfig        = schemaExportProject.ProjectItems.AddFromFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\App.config");
                ProjectItem nhibernateConfig = schemaExportProject.ProjectItems.AddFromFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\nhibernate.config");

                // Set the config files 'Copy to Output Directory' property to 'Copy if Newer'
                appConfig.Properties.Item("CopyToOutputDirectory").Value        = 2;
                appConfig.Properties.Item("BuildAction").Value                  = VSLangProj.prjBuildAction.prjBuildActionContent;
                nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                nhibernateConfig.Properties.Item("BuildAction").Value           = VSLangProj.prjBuildAction.prjBuildActionContent;

                schemaExportProject.ProjectItems.AddFromFile(basePath + "\\" + m_configuration["projects.schemaexport.dir"] + "\\Program.cs");
            }

            // Render /maven.xml
            WriteFile(basePath + "\\maven.xml", ParseVariables(Resource1.maven_xml));
            // Render /project.properties
            WriteFile(basePath + "\\project.properties", ParseVariables(Resource1.project_properties));
            // Render /project.xml
            WriteFile(basePath + "\\project.xml", ParseVariables(Resource1.project_xml));

            // Create mda directory
            CreateDirectory(basePath + "\\mda");
            // Render /mda/maven.xml
            WriteFile(basePath + "\\mda\\maven.xml", ParseVariables(Resource1.mda_maven_xml));
            // Render /mda/project.properties
            WriteFile(basePath + "\\mda\\project.properties", ParseVariables(Resource1.mda_project_properties));
            // Render /mda/project.xml
            WriteFile(basePath + "\\mda\\project.xml", ParseVariables(Resource1.mda_project_xml));

            // Create mda/conf directory
            CreateDirectory(basePath + "\\mda\\conf");
            // Render /mda/conf/andromda.xml
            WriteFile(basePath + "\\mda\\conf\\andromda.xml", ParseVariables(Resource1.mda_conf_andromda_xml));

            // Create mda/src directory
            System.IO.Directory.CreateDirectory(basePath + "\\mda\\src");
            // Create mda/uml directory
            System.IO.Directory.CreateDirectory(basePath + "\\mda\\src\\uml");
            // Create the empty model file
            WriteCompressedFile(m_configuration["application.model.filename.unzipped"], basePath + "\\mda\\src\\uml\\" + m_configuration["application.model.filename"], Resource1.mda_src_uml_empty_model_xml);

            // Create the lib directory
            CreateDirectory(basePath + "\\Lib");
            // Write the libraries out
            WriteFile(basePath + "\\Lib\\AndroMDA.NHibernateSupport.dll", Resource1.lib_AndroMDA_NHibernateSupport_dll);
            WriteFile(basePath + "\\Lib\\Bamboo.Prevalence.dll", Resource1.lib_Bamboo_Prevalence_dll);
            WriteFile(basePath + "\\Lib\\Castle.DynamicProxy.dll", Resource1.lib_Castle_DynamicProxy_dll);
            WriteFile(basePath + "\\Lib\\HashCodeProvider.dll", Resource1.lib_HashCodeProvider_dll);
            WriteFile(basePath + "\\Lib\\Iesi.Collections.dll", Resource1.lib_Iesi_Collections_dll);
            WriteFile(basePath + "\\Lib\\log4net.dll", Resource1.lib_log4net_dll);
            WriteFile(basePath + "\\Lib\\NHibernate.Caches.Prevalence.dll", Resource1.lib_NHibernate_Caches_Prevalence_dll);
            WriteFile(basePath + "\\Lib\\NHibernate.Caches.SysCache.dll", Resource1.lib_NHibernate_Caches_SysCache_dll);
            WriteFile(basePath + "\\Lib\\NHibernate.dll", Resource1.lib_NHibernate_dll);
            WriteFile(basePath + "\\Lib\\NHibernate.Nullables2.dll", Resource1.lib_NHibernate_Nullables2_dll);

            AddToStatus("Adding project references...");

            // Add the references to all the DLLs we just put in /Lib
            AddBinaryReferences(commonProject, basePath);
            AddBinaryReferences(coreProject, basePath);

            // Add a reference from the core project to the common project
            AddProjectReference(coreProject, commonProject);

            // If we created the schema export project
            if (schemaExportProject != null)
            {
                // Add the references to the DLLs
                AddBinaryReferences(schemaExportProject, basePath);

                // Add references to the core and common projects
                AddProjectReference(schemaExportProject, commonProject);
                AddProjectReference(schemaExportProject, coreProject);
            }
        }
        /// <summary>
        /// The actually processing happens in this method
        /// </summary>
        private void UpdateSolution()
        {
            AddToStatus("Adding AndroMDA support to solution...");

            Project commonProject       = null;
            Project coreProject         = null;
            Project schemaExportProject = null;
            Project testProject         = null;
            Project webProject          = null;
            Project webCommonProject    = null;

            m_srcPath = m_settings.SolutionWizardResourcesLocation + "\\";
            m_dstPath = m_configuration["solution.path"] + "\\";

            string versionControlType = m_configuration["application.versioncontrol"];
            bool   versionControl     = versionControlType != "None";
            string ignoreFile         = string.Empty;

            switch (versionControlType)
            {
            case "CVS":
                ignoreFile = ".cvsignore";
                break;
            }

            nvelocityContext = new VelocityContext();
            foreach (string key in m_configuration.Keys)
            {
                object value = m_configuration[key];
                if (m_configuration[key] == "true" || m_configuration[key] == "false")
                {
                    value = GetConfigSettingBool(key);
                }

                nvelocityContext.Put("wizard." + key, value);
                nvelocityContext.Put("wizard_" + key.Replace('.', '_'), value);
            }

            AddToStatus("Creating AndroMDA configuration files...");

            // Create mda directory
            CreateDirectory("mda");
            // Create mda/conf directory
            CreateDirectory("mda/conf");

            // Render /cvsignore
            if (versionControl)
            {
                WriteFile("cvsignore", ignoreFile);
            }

            if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x")
            {
                // Render /pom.xml
                WriteFile("pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Render /mda/pom.xml
                WriteFile("mda/pom.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Render /mda/conf/andromda.xml
                WriteFile("mda/conf/andromda.xml", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);

                // Create mda/conf/mappings directory
                CreateDirectory("mda/conf/mappings");

                // Render /mda/conf/mappings/MergeMappings.xml
                WriteFile("mda/conf/mappings/MergeMappings.xml");

                // Render /mda/conf/mappings/NHibernateTypeMappings.xml (Required for NHibernate 1.2)
                WriteFile("mda/conf/mappings/NHibernateTypeMappings.xml");

                // Create mda/resources
                CreateDirectory("mda/resources");

                // Create mda/resources
                CreateDirectory("mda/resources/templates");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/cs");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/nspring");

                // Create mda/resources
                CreateDirectory("mda/resources/templates/nhibernate");
            }

            // Write mda/cvsignore
            if (versionControl)
            {
                WriteFile("mda/cvsignore", "mda/" + ignoreFile);
            }


            AddToStatus("Creating empty model file...");
            // Create mda/src directory
            CreateDirectory("mda/src");
            // Create mda/src/uml directory
            CreateDirectory("mda/src/uml");

            {
                string modelPackageXML = "<UML:Model xmi.id='_9_5_1_874026a_1149883877463_480535_0' name='" + m_configuration["solution.name"] + "'><UML:Namespace.ownedElement>";
                string xmiIdBase       = "_9_5_1_874026a_" + DateTime.Now.Ticks.ToString();
                modelPackageXML += GetXMI(m_configuration["solution.name"].Split('.'), xmiIdBase);
                modelPackageXML += "</UML:Namespace.ownedElement></UML:Model>";

                string emptyModelFileData = ReadFile("mda/src/uml/empty-model.xmi");

                emptyModelFileData = emptyModelFileData.Replace("${wizard.model.packagestructure.xml}", modelPackageXML);

                WriteFileProperties modelProperties = WriteFileProperties.SourceFileIsContent | WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables;
                if (GetConfigSettingBool("application.model.zipped"))
                {
                    modelProperties |= WriteFileProperties.Compressed;
                }
                WriteFile(emptyModelFileData, "mda/src/uml/" + m_configuration["application.model.filename"], modelProperties);
            }



            // Create the AndroMDA solution folder
            AddToStatus("Adding solution folder...");
            Solution2 sol            = m_applicationObject.Solution as Solution2;
            Project   solutionFolder = null;

            try
            {
                solutionFolder = sol.AddSolutionFolder("AndroMDA");
                if (m_configuration["application.andromda.bootstrap"] == "Apache Maven 2.x")
                {
                    solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\pom.xml");
                }
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\andromda.xml");
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\MergeMappings.xml");
                solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\conf\\mappings\\NHibernateTypeMappings.xml");
                //solutionFolder.ProjectItems.AddFromFile(m_dstPath + "mda\\src\\uml\\" + m_configuration["application.model.filename"]);
            }
            catch { }

            //////////////////////////////////
            // Create/find the common project
            if (GetConfigSettingBool("projects.common.create"))
            {
                AddToStatus("Creating common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.common.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing common project " + m_configuration["projects.common.name"] + "...");
                commonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.common.name"], m_applicationObject.Solution);
            }

            try { commonProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch { }
            try { commonProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { }

            // Write common/cvsignore
            if (versionControl)
            {
                WriteFile("Common/cvsignore", m_configuration["projects.common.dir"] + "/" + ignoreFile);
            }


            //////////////////////////////////
            // Create/find the core project
            if (GetConfigSettingBool("projects.core.create"))
            {
                AddToStatus("Creating core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.core.name"], (Solution2)m_applicationObject.Solution);
            }
            else
            {
                AddToStatus("Using existing core project " + m_configuration["projects.core.name"] + "...");
                coreProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.core.name"], m_applicationObject.Solution);
            }
            try { coreProject.ProjectItems.AddFolder("src", Constants.vsProjectItemKindPhysicalFolder); } catch {}
            try { coreProject.ProjectItems.AddFolder("target", Constants.vsProjectItemKindPhysicalFolder); } catch { }

            // Write core/cvsignore
            if (versionControl)
            {
                WriteFile("Core/cvsignore", m_configuration["projects.core.dir"] + "/" + ignoreFile);
            }


            //////////////////////////////////
            // Create the schema export project
            if (GetConfigSettingBool("projects.schemaexport.create"))
            {
                AddToStatus("Creating schema export project " + m_configuration["projects.schemaexport.name"] + "...");
                schemaExportProject = VSSolutionUtils.AddConsoleAppProjectToSolution(m_configuration["projects.schemaexport.name"], (Solution2)m_applicationObject.Solution);

                WriteFile("SchemaExport/App.config", m_configuration["projects.schemaexport.dir"] + "/App.config");
                WriteFile("SchemaExport/nhibernate.config", m_configuration["projects.schemaexport.dir"] + "/nhibernate.config");
                WriteFile("SchemaExport/SchemaExport.cs", m_configuration["projects.schemaexport.dir"] + "/SchemaExport.cs");
                WriteFile("SchemaExport/TestDataManager.cs", m_configuration["projects.schemaexport.dir"] + "/TestDataManager.cs");

                ProjectItem appConfig        = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\App.config");
                ProjectItem nhibernateConfig = schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\nhibernate.config");

                // Set the config files 'Copy to Output Directory' property to 'Copy if Newer'
                appConfig.Properties.Item("CopyToOutputDirectory").Value        = 2;
                appConfig.Properties.Item("BuildAction").Value                  = VSLangProj.prjBuildAction.prjBuildActionContent;
                nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                nhibernateConfig.Properties.Item("BuildAction").Value           = VSLangProj.prjBuildAction.prjBuildActionContent;

                schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\SchemaExport.cs");
                schemaExportProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.schemaexport.dir"] + "\\TestDataManager.cs");

                // Write SchemaExport/cvsignore
                if (versionControl)
                {
                    WriteFile("SchemaExport/cvsignore", m_configuration["projects.schemaexport.dir"] + "/" + ignoreFile);
                }
            }


            //////////////////////////////////
            // Configure the web project
            if (GetConfigSettingBool("projects.web.configure"))
            {
                //////////////////////////////////
                // Create/find the web project
                if (GetConfigSettingBool("projects.web.create"))
                {
                    AddToStatus("Creating web project " + m_configuration["projects.web.name"] + "...");
                    webProject = VSSolutionUtils.AddWebProjectToSolution(m_configuration["projects.web.name"], (Solution2)m_applicationObject.Solution);
                }
                else
                {
                    AddToStatus("Using existing web project " + m_configuration["projects.web.name"] + "...");
                    webProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.dir"], m_applicationObject.Solution);
                }

                // Write the nhibernate.config if required
                if (GetConfigSettingBool("projects.web.usenhibernateconfig"))
                {
                    WriteFile("Web/nhibernate.config", webProject.Name + "nhibernate.config", WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables);
                }

                string webConfigDstFile = webProject.Name + "Web.config";

                if (!System.IO.File.Exists(webConfigDstFile))
                {
                    // Write out the web.config file
                    WriteFile("Web/web.config", webConfigDstFile, WriteFileProperties.DestinationPathAlreadyComplete | WriteFileProperties.ParseVariables);
                    webProject.ProjectItems.AddFromFile(webConfigDstFile);
                }

                // Open the web.config file
                System.Configuration.Configuration webconfig = OpenWebConfig(webConfigDstFile);

                // If the nhibernate settings are stored in nhibernate.config
                if (GetConfigSettingBool("projects.web.usenhibernateconfig"))
                {
                    // Add that to the app settings
                    if (webconfig.AppSettings.Settings["nhibernate.config"] == null)
                    {
                        webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config");
                    }
                    else
                    {
                        webconfig.AppSettings.Settings.Add("nhibernate.config", "~/nhibernate.config");
                    }
                    // Remove the nhibernate section if it exists
                    if (webconfig.Sections.Get("nhibernate") != null)
                    {
                        webconfig.Sections.Remove("nhibernate");
                    }
                }
                else
                {
                    // Remove the nhibernate.config app setting if it exists
                    if (webconfig.AppSettings.Settings["nhibernate.config"] != null)
                    {
                        webconfig.AppSettings.Settings.Remove("nhibernate.config");
                    }

                    // Add the nhibernate config to the web.config
                    DefaultSection nhibernateSection = new DefaultSection();
                    nhibernateSection.SectionInformation.Type = "System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089";

                    nhibernateSection.SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.nhibernate")));

                    webconfig.Sections.Add("nhibernate", nhibernateSection);
                }

                // Write Web/cvsignore and Web\Bin\cvsignore
                if (versionControl)
                {
                    WriteFile("web/cvsignore", webProject.Name + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete);
                    CreateDirectory(webProject.Name + "Bin", false);
                    WriteFile("web/bin/cvsignore", webProject.Name + "Bin\\" + ignoreFile, WriteFileProperties.DestinationPathAlreadyComplete);
                }

                if (GetConfigSettingBool("projects.web.common.configure"))
                {
                    // Create/find the core project
                    if (GetConfigSettingBool("projects.web.common.create"))
                    {
                        AddToStatus("Creating web common project " + m_configuration["projects.web.common.name"] + "...");
                        webCommonProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.web.common.name"], (Solution2)m_applicationObject.Solution);
                    }
                    else
                    {
                        AddToStatus("Using existing web common project " + m_configuration["projects.web.common.name"] + "...");
                        webCommonProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.web.common.name"], m_applicationObject.Solution);
                    }
                }

                // Get the web site object
                VsWebSite.VSWebSite webSite = webProject.Object as VsWebSite.VSWebSite;

                // Refresh folder view
                webSite.Refresh();

                // Add Membership support
                if (GetConfigSettingBool("projects.web.addmembership"))
                {
                    AddToStatus("Adding membership support...");

                    string      file;
                    ProjectItem membershipFolder = VSSolutionUtils.FindProjectFolder(webCommonProject, "Membership");
                    if (membershipFolder == null)
                    {
                        membershipFolder = webCommonProject.ProjectItems.AddFolder("Membership", Constants.vsProjectItemKindPhysicalFolder);
                    }

                    // Render DomainMembershipProvider.cs
                    WriteFile("Membership/DomainMembershipProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipProvider.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipProvider.cs");

                    // Render DomainRoleProvider.cs
                    WriteFile("Membership/DomainRoleProvider.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainRoleProvider.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainRoleProvider.cs");

                    // Render DomainMembershipUser.cs
                    WriteFile("Membership/DomainMembershipUser.cs", m_configuration["projects.web.common.dir"] + "/Membership/DomainMembershipUser.cs");
                    membershipFolder.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.web.common.dir"] + "\\Membership\\DomainMembershipUser.cs");

                    // Create core/src/* folder tree from namespace
                    string   solutionName = m_configuration["solution.name"];
                    string[] namespaces   = solutionName.Split('.');
                    file = m_configuration["projects.core.dir"] + "\\src\\";
                    foreach (string folder in namespaces)
                    {
                        file = file + folder;
                        CreateDirectory(file);
                        file = file + "\\";
                    }
                    CreateDirectory(file + "Domain");
                    CreateDirectory(file + "Service");

                    // Render UserDao.cs
                    WriteFile("Membership/UserDao.cs", file + "Domain/UserDao.cs");
                    coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Domain\\UserDao.cs");

                    // Render MembershipService.cs
                    WriteFile("Membership/MembershipService.cs", file + "Service/MembershipService.cs");
                    coreProject.ProjectItems.AddFromFile(m_dstPath + file + "Service\\MembershipService.cs");

                    ConfigurationSectionGroup systemweb = webconfig.SectionGroups["system.web"];

                    systemweb.Sections["membership"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.membershipsection")));
                    systemweb.Sections["roleManager"].SectionInformation.SetRawXml(ParseVariables(ReadFile("web/web.config.rolesection")));

                    systemweb.Sections["membership"].SectionInformation.ForceSave  = true;
                    systemweb.Sections["roleManager"].SectionInformation.ForceSave = true;

                    // Turn on authentication
                    systemweb.Sections["authentication"].SectionInformation.SetRawXml("<authentication mode=\"Forms\"> <forms name=\"FormsAuth\" timeout=\"30\" loginUrl=\"~/Public/Login.aspx\" defaultUrl=\"~/Default.aspx\" path=\"/\" protection=\"All\"/></authentication>");
                }

                // Save the changes to the web.config
                webconfig.Save();
            }

            // Create the lib directory
            CreateDirectory("Lib");

            // Write the libraries out
            WriteBinaryFile("Lib/AndroMDA.NHibernateSupport.dll");
            WriteBinaryFile("Lib/Bamboo.Prevalence.dll");
            WriteBinaryFile("Lib/Castle.DynamicProxy.dll");
            //WriteBinaryFile("Lib/HashCodeProvider.dll");
            WriteBinaryFile("Lib/Iesi.Collections.dll");
            WriteBinaryFile("Lib/log4net.dll");
            WriteBinaryFile("Lib/NHibernate.Caches.Prevalence.dll");
            WriteBinaryFile("Lib/NHibernate.Caches.SysCache.dll");
            WriteBinaryFile("Lib/NHibernate.dll");
            //WriteBinaryFile("Lib/NHibernate.Nullables2.dll");
            WriteBinaryFile("Lib/Nullables.dll");
            WriteBinaryFile("Lib/Nullables.NHibernate.dll");


            //////////////////////////////////
            // Configure the tests project
            if (GetConfigSettingBool("projects.tests.configure"))
            {
                // Create/find the core project
                if (GetConfigSettingBool("projects.tests.create"))
                {
                    AddToStatus("Creating testing project " + m_configuration["projects.tests.name"] + "...");
                    testProject = VSSolutionUtils.AddClassLibraryProjectToSolution(m_configuration["projects.tests.name"], (Solution2)m_applicationObject.Solution);
                }
                else
                {
                    AddToStatus("Using existing testing project " + m_configuration["projects.tests.name"] + "...");
                    testProject = VSSolutionUtils.FindProjectByName(m_configuration["projects.tests.name"], m_applicationObject.Solution);
                }
                WriteFile("Tests/App.config", m_configuration["projects.tests.dir"] + "/App.config", WriteFileProperties.RenderTemplate | WriteFileProperties.ParseVariables);
                WriteFile("Tests/nhibernate.config", m_configuration["projects.tests.dir"] + "/nhibernate.config");

                ProjectItem appConfig        = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\App.config");
                ProjectItem nhibernateConfig = testProject.ProjectItems.AddFromFile(m_dstPath + m_configuration["projects.tests.dir"] + "\\nhibernate.config");

                // Set the config files 'Copy to Output Directory' property to 'Copy if Newer'
                appConfig.Properties.Item("CopyToOutputDirectory").Value        = 2;
                appConfig.Properties.Item("BuildAction").Value                  = VSLangProj.prjBuildAction.prjBuildActionContent;
                nhibernateConfig.Properties.Item("CopyToOutputDirectory").Value = 2;
                nhibernateConfig.Properties.Item("BuildAction").Value           = VSLangProj.prjBuildAction.prjBuildActionContent;

                AddToStatus("Writing NUnit assemblies...");

                WriteBinaryFile("Lib/nunit.core.dll");
                WriteBinaryFile("Lib/nunit.framework.dll");

                AddToStatus("Adding NUnit references...");

                VSProject vsTestProj = (VSProject)testProject.Object;
                vsTestProj.References.Add(m_dstPath + "Lib\\nunit.core.dll");
                vsTestProj.References.Add(m_dstPath + "Lib\\nunit.framework.dll");

                if (GetConfigSettingBool("projects.tests.scenariounit"))
                {
                    AddToStatus("Writing ScenarioUnit assemblies...");
                    WriteBinaryFile("Lib/NXUnit.Framework.dll");
                    WriteBinaryFile("Lib/AndroMDA.ScenarioUnit.dll");
                    AddToStatus("Adding ScenarioUnit references...");
                    vsTestProj.References.Add(m_dstPath + "Lib\\NXUnit.Framework.dll");
                    vsTestProj.References.Add(m_dstPath + "Lib\\AndroMDA.ScenarioUnit.dll");
                    ProjectItem testDataFolder = testProject.ProjectItems.AddFolder("TestData", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("actual_output", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("expected_output", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("rules", Constants.vsProjectItemKindPhysicalFolder);
                    testDataFolder.ProjectItems.AddFolder("input", Constants.vsProjectItemKindPhysicalFolder);
                }
            }

            // Add the references to all the DLLs we just put in /Lib
            AddToStatus("Adding project references to common project...");
            AddBinaryReferences(commonProject);
            AddToStatus("Adding project references to core project...");
            AddBinaryReferences(coreProject);

            // Add a reference from the core project to the common project
            AddProjectReference(coreProject, commonProject);

            // If we created the schema export project
            if (schemaExportProject != null)
            {
                VSProject proj = schemaExportProject.Object as VSProject;
                AddToStatus("Adding references to schema export project...");
                // Add the references to the DLLs
                AddBinaryReferences(schemaExportProject);

                // Add references to the core and common projects
                AddProjectReference(schemaExportProject, commonProject);
                AddProjectReference(schemaExportProject, coreProject);

                AddToStatus("Adding System.Configuration reference to schema export project...");
                try { proj.References.Add("System.Configuration"); } catch { }
            }

            // If we created the schema export project
            if (testProject != null)
            {
                AddToStatus("Adding references to testing project...");
                // Add the references to the DLLs
                AddBinaryReferences(testProject);

                // Add references to the core and common projects
                AddProjectReference(testProject, commonProject);
                AddProjectReference(testProject, coreProject);
            }


            if (webProject != null)
            {
                AddToStatus("Adding project references to web project...");

                VsWebSite.VSWebSite proj = webProject.Object as VsWebSite.VSWebSite;

                proj.References.AddFromFile(m_dstPath + "Lib\\AndroMDA.NHibernateSupport.dll");

                try { proj.References.AddFromProject(commonProject); } catch {}
                try { proj.References.AddFromProject(coreProject); } catch {}
                if (webCommonProject != null)
                {
                    try { proj.References.AddFromProject(webCommonProject); } catch { }
                }
                //m_applicationObject.Solution.Properties.Item("StartupProject").Value = webProject.Name;
            }

            if (webCommonProject != null)
            {
                VSProject proj = webCommonProject.Object as VSProject;
                AddToStatus("Adding common project reference to web common project...");
                try { proj.References.AddProject(commonProject); } catch { }
                AddToStatus("Adding core project reference to web common project...");
                try { proj.References.AddProject(coreProject); } catch { }
                AddToStatus("Adding System.Configuration reference to web common project...");
                try { proj.References.Add("System.Configuration"); } catch { }
                AddToStatus("Adding System.Web reference to web common project...");
                try { proj.References.Add("System.Web"); } catch { }
            }

            AddToStatus("Processing complete, cleaning up...");
        }