Exemplo n.º 1
0
        private void ShowSlnInfo()
        {
            StringBuilder info = new StringBuilder();

            Solution3    sln = DTEObject.Solution as Solution3;
            SolutionNode sn  =
                new SolutionNode {
                FileName = sln.FileName, FullName = sln.FullName
            };

            foreach (Project proj in sln.Projects)
            {
                if (proj.Kind == ProjectKinds.vsProjectKindSolutionFolder)
                {
                    AddSolutionFolder(sn, proj);
                    //sn.SolutionFolderList.Add();
                }
                else
                {
                    AddProject(sn, proj);
                    //info.AppendLine(proj.FullName);
                }
            }

            //MessageBox.Show(info.ToString());
            Solution3 newSln = DTEObject.Solution as Solution3;

            newSln.Create(@"C:\solutions", "mySln");
            MessageBox.Show(newSln.FullName);
        }
Exemplo n.º 2
0
        private void btnConvert_Click(object sender, EventArgs e)
        {
            // Create a sln
            Solution3 newSln = DTEObject.Solution as Solution3;

            newSln.Create(@"C:\solutions", "mySln");

            // Add a proj
            string templatePath = newSln.GetProjectTemplate("ClassLibrary.zip", "CSharp");

            newSln.AddFromTemplate(templatePath, @"C:\solutions\NewProj", "mySln.NewProj", false);
            Project    proj   = newSln.Projects.Item(1);
            VSProject2 vsProj = proj.Object as VSProject2;

            vsProj.References.Add(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll");

            // Save the sln
            newSln.SaveAs(@"C:\solutions\mySln.sln");
            //newSln.Close(true);

            //ShowSlnInfo();
        }
        private void Generate(string slnName)
        {
            Solution3 sln = (DTEObject.Solution as Solution3);

            sln.Create(currentSlnPath, slnName);

            CopyExternalBinFolder(currentSlnPath);

            // Create solution folder
            Project sfProj = sln.AddSolutionFolder(ExternalBinDirectoryName);

            foreach (string file in Directory.GetFiles(ExternalBinPath))
            {
                sfProj.ProjectItems.AddFromFile(file);
            }

            // Create *.Domain Project
            string classLibProjTemplatePath =
                sln.GetProjectTemplate("ClassLibrary.zip", "CSharp");
            string domainProjName = slnName + "." + "Domain";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, domainProjName),
                                domainProjName, false);
            Project   domainProj   = GetProjectByName(sln, domainProjName);
            VSProject vsDomainProj = domainProj.Object as VSProject;

            vsDomainProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));

            // Create *.Persistence Project
            string persistProjName = slnName + "." + "Persistence";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, persistProjName),
                                persistProjName, false);
            Project   persistProj   = GetProjectByName(sln, persistProjName);
            VSProject vsPersistProj = persistProj.Object as VSProject;

            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataAccess.dll"));
            vsPersistProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataMapper.dll"));
            vsPersistProj.References.AddProject(domainProj);

            // Create *.Service Project
            string serviceProjName = slnName + "." + "Service";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, serviceProjName),
                                serviceProjName, false);
            Project   serviceProj   = GetProjectByName(sln, serviceProjName);
            VSProject vsServiceProj = serviceProj.Object as VSProject;

            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.DataAccess.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "Castle.DynamicProxy.dll"));
            vsServiceProj.References.Add(Path.Combine(ExternalBinPath, "log4net.dll"));
            vsServiceProj.References.AddProject(domainProj);
            vsServiceProj.References.AddProject(persistProj);

            // Create *.Presentation Project
            string presentProjName = slnName + "." + "Presentation";

            sln.AddFromTemplate(classLibProjTemplatePath, Path.Combine(currentSlnPath, presentProjName),
                                presentProjName, false);
            Project   presentProj   = GetProjectByName(sln, presentProjName);
            VSProject vsPresentProj = presentProj.Object as VSProject;

            vsPresentProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsPresentProj.References.AddProject(domainProj);
            vsPresentProj.References.AddProject(serviceProj);

            // Create *.Web Project
            string webProjTemplatePath =
                sln.GetProjectTemplate("WebApplicationProject.zip", "CSharp");
            string webProjName = slnName + "." + "Web";

            sln.AddFromTemplate(webProjTemplatePath, Path.Combine(currentSlnPath, webProjName),
                                webProjName, false);
            Project   webProj   = GetProjectByName(sln, webProjName);
            VSProject vsWebProj = webProj.Object as VSProject;

            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "Castle.DynamicProxy.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "IBatisNet.Common.Logging.Log4Net.dll"));
            vsWebProj.References.Add(Path.Combine(ExternalBinPath, "log4net.dll"));
            vsWebProj.References.AddProject(domainProj);
            vsWebProj.References.AddProject(presentProj);

            webProj.ProjectItems.AddFolder("css", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("images", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("Maps", Constants.vsProjectItemKindPhysicalFolder);
            webProj.ProjectItems.AddFolder("UserControls", Constants.vsProjectItemKindPhysicalFolder);

            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\dao.config"));
            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\providers.config"));
            webProj.ProjectItems.AddFromFileCopy(
                Path.Combine(GetAddinPath(), @"ibatis-config\SqlMap.config"));

            sln.SaveAs(slnName);
        }