예제 #1
0
        private void IncludeFiles(string folder, Project project)
        {
            var validExtentions = new string[] { "xml", "linq" };

            ThreadHelper.ThrowIfNotOnUIThread();
            var di = new DirectoryInfo(folder);

            foreach (var item in di.GetFileSystemInfos())
            {
                if (item is FileInfo)
                {
                    // only LINQ files
                    if (validExtentions.Any(s => s.IndexOf(item.Name, StringComparison.OrdinalIgnoreCase) >= 0))
                    {
                        project.ProjectItems.AddFromFile(item.FullName);
                    }
                }
                else if (item is DirectoryInfo)
                {
                    SolutionFolder solutionFolder    = (SolutionFolder)project.Object;
                    var            newSolutionFolder = solutionFolder.AddSolutionFolder(item.Name);
                    IncludeFiles(item.FullName, newSolutionFolder);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Creates solution directory and includes files from destination
        /// </summary>
        private void createSolutionDirAndFiles(string SolutionDir, string SourcePath, string DestinationPath)
        {
            // Add a solution Folder for the //Solution Items ( from root )
            string[]       dirs = SolutionDir.Split('\\');
            EnvDTE.Project solutionsFolderProject = _solution.AddSolutionFolder(dirs[0]);
            // Add sub directories if needed
            for (int i = 1; i < dirs.Count(); i++)
            {
                SolutionFolder SF = (SolutionFolder)solutionsFolderProject.Object;
                solutionsFolderProject = SF.AddSolutionFolder(dirs[i]);
            }


            // Copy and add the files
            foreach (string newPath in Directory.GetFiles(SourcePath, "*.*", SearchOption.TopDirectoryOnly))
            {
                // The filename to copy over
                string fileName = newPath.Replace(SourcePath, DestinationPath);
                // Don't add the fake project
                if (!fileName.EndsWith("proj"))
                {
                    // Strip out extra directory character
                    fileName = fileName.Replace("\\\\", "\\");
                    // Copy to new home on hard drive
                    File.Copy(newPath, fileName, true);
                    Logger.Log("Rootwizard ~~~~ Adding File to solution=" + fileName);
                    // Add the item from the local hard drive to the project
                    EnvDTE.ProjectItem addedFile = solutionsFolderProject.ProjectItems.AddFromFile(fileName);
                    // Optionally close the pointless window to clean up the solution from the start
                    addedFile.DTE.ActiveWindow.Close(vsSaveChanges.vsSaveChangesNo);
                }
            }
        }
        public void Create(string folderName, SolutionFolder parentFolder)
        {
            var folder = GetByName(folderName);

            if (folder != null)
            {
                return;
            }
            parentFolder.AddSolutionFolder(folderName);
        }
        public static SolutionFolder AddSolutionFolderEx(this SolutionFolder solutionFolder, string folderName)
        {
            SolutionFolder folder = solutionFolder.GetSolutionFolderEx(folderName);

            if (folder == null)
            {
                folder = solutionFolder.AddSolutionFolder(folderName).Object;
            }

            return(folder);
        }
예제 #5
0
        private static Project GetCreateSolutionFolder(this SolutionFolder solutionFolder, string folderName)
        {
            var projectItems        = solutionFolder.Parent.ProjectItems.OfType <ProjectItem>();
            var existingProjectItem = projectItems.FirstOrDefault(item => item.Name == folderName);

            if (existingProjectItem != null)
            {
                return((Project)existingProjectItem.Object);
            }
            return(solutionFolder.AddSolutionFolder(folderName));
        }
        public void RunFinished()
        {
            Solution2 solution = (Solution2)dte.Solution;
            Project   project  = GetProject(
                solution.Projects.OfType <Project>(),
                parameters["$projectname$"]);

            // remove the created project from the solution
            solution.Remove(project);

            string destinationDir = parameters["$destinationdirectory$"];

            // check that the project was created in the right path. If not, we move it
            string properPath = Path.Combine(parameters["$solutiondirectory$"], "src", parameters["$layer$"], parameters["$safeprojectname$"]);

            if (String.Compare(destinationDir, properPath) != 0)
            {
                Directory.Move(destinationDir, properPath);
                destinationDir = properPath;

                // notify the user that the destination dir was changed
                string message = String.Format("To comply with the Helix guidlines, the module was installed in the folder '{0}'.", destinationDir);
                MessageBox.Show(message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            // rename the project folder to 'code'
            string currentPath = Path.Combine(destinationDir, parameters["$modulefullname$"]);
            string newPath     = Path.Combine(destinationDir, parameters["$modulewebsitefolder$"]);

            Directory.Move(currentPath, newPath);

            // add the new project to the solution and save it
            SolutionFolder layerFolder = GetLayerFolder(parameters["$layer$"], solution);

            if (layerFolder == null)
            {
                throw new Exception(String.Format("Could not found the folder '´{0}' in the solution.", parameters["$layer$"]));
            }
            else
            {
                Project        folderProject   = layerFolder.AddSolutionFolder(parameters["$projectname$"]);
                SolutionFolder solutionFolder  = (SolutionFolder)folderProject.Object;
                string         projectFilePath = Path.Combine(newPath, String.Concat(parameters["$modulefullname$"], ".csproj"));
                solutionFolder.AddFromFile(projectFilePath);

                // delete serialization files and folders from disk
                string serializationFolder = Path.Combine(destinationDir, "serialization");
                Directory.Delete(Path.Combine(serializationFolder, "bin"), true);
                Directory.Delete(Path.Combine(serializationFolder, "obj"), true);
                File.Delete(Path.Combine(serializationFolder, "serialization.csproj"));
                File.Delete(Path.Combine(serializationFolder, "serialization.csproj.user"));
            }
        }
        private ISolutionFolder AddSolutionFolderSubFolder(string folder)
        {
            var parent = SolutionFolder.Parent;

            foreach (ProjectItem item in parent.ProjectItems)
            {
                if (item.Name == folder)
                {
                    return(new VisualStudioSolutionFolder((Project)item.Object));
                }
            }
            return(new VisualStudioSolutionFolder(SolutionFolder.AddSolutionFolder(folder)));
        }
예제 #8
0
 public void addFilesToSolution(Project solutionFolderProject, SolutionFolder solutionFolder, string basePath)
 {
     //For each file, add to the folder
     foreach (var file in Directory.EnumerateFiles(basePath))
     {
         //Add the file as a copy into the solution folder
         solutionFolderProject.ProjectItems.AddFromFileCopy(file);
     }
     //for each directory, create a new solution folder and add the files
     foreach (var dir in Directory.EnumerateDirectories(basePath))
     {
         //Create a new solution folder and return a Project object
         Project folderProject = solutionFolder.AddSolutionFolder(Path.GetFileName(dir));
         //Cast the Project object to a SolutionFolder to be able to create more Solution Folders children
         SolutionFolder solFolder = (SolutionFolder)folderProject.Object;
         //Call the function to add the original files to the solution folder
         addFilesToSolution(folderProject, solFolder, dir);
     }
 }
예제 #9
0
 public void addFilesToSolution(Project solutionFolderProject, SolutionFolder solutionFolder, string basePath)
 {
     //For each file, add to the folder
     foreach (var file in Directory.EnumerateFiles(basePath))
     {
         //Add the file as a copy into the solution folder
         solutionFolderProject.ProjectItems.AddFromFileCopy(file);
     }
     //for each directory, create a new solution folder and add the files
     foreach (var dir in Directory.EnumerateDirectories(basePath))
     {
         //Create a new solution folder and return a Project object
         Project folderProject = solutionFolder.AddSolutionFolder(Path.GetFileName(dir));
         //Cast the Project object to a SolutionFolder to be able to create more Solution Folders children
         SolutionFolder solFolder = (SolutionFolder)folderProject.Object;
         //Call the function to add the original files to the solution folder
         addFilesToSolution(folderProject, solFolder, dir);
     }
 }
예제 #10
0
 public ShellProject AddSolutionFolder(string Name)
 {
     return(new ShellProject(_folder.AddSolutionFolder(Name)));
 }
예제 #11
0
        private void CreateSolutionFolder(
            SolutionFolder solutionFolder,
            SolutionFolderData solutionFolderData,
            Action<double> progressAction,
            SolutionDataViewModel solutionData,
            CancellationToken ct)
        {
            if (!solutionData.CreateTests &&
                solutionFolder == null &&
                solutionFolderData.Name == "Tests")
            {
                return;
            }

            if (!solutionData.CreateFakes &&
                solutionFolderData.Name == "Fake")
            {
                return;
            }

            var addedProject = solutionFolder == null
                ? GetSolution().AddSolutionFolder(solutionFolderData.Name)
                : solutionFolder.AddSolutionFolder(solutionFolderData.Name);

            if (solutionFolderData.Items.Length == 0)
            {
                return;
            }

            SolutionFolder subFolder = addedProject.Object as SolutionFolder;
            var k = 1.0/solutionFolderData.Items.Length;
            for (int i = 0; i < solutionFolderData.Items.Length; ++i)
            {
                var pr = k*i;
                progressAction(pr);
                int j = i;
                CreateSolutionItem(
                    subFolder,
                    solutionFolderData.Items[i], progress =>
                    {
                        pr = k*j + progress*k;
                        progressAction(pr);
                    },
                    solutionData,
                    ct);
                ct.ThrowIfCancellationRequested();
            }
        }
예제 #12
0
        private void AddSolutionFolder(SolutionFolder parent, SolutionFolderTemplate solutionFolder,
            IList<Project> projects, SolutionDataViewModel solutionData)
        {
            if (!solutionData.CreateTests &&
                parent == null &&
                solutionFolder.Name == "Tests")
            {
                return;
            }

            if (!solutionData.CreateFakes &&
                solutionFolder.Name == "Fake")
            {
                return;
            }

            var addedProject = parent == null
                ? GetSolution().AddSolutionFolder(solutionFolder.Name)
                : parent.AddSolutionFolder(solutionFolder.Name);

            foreach (var item in solutionFolder.Items)
            {
                AddProjectToSolution(addedProject.Object as SolutionFolder, item, projects, solutionData);
            }
        }
예제 #13
0
        void EnvDTE.IDTWizard.Execute(object Application, int hwndOwner, ref object[] ContextParams, ref object[] CustomParams, ref EnvDTE.wizardResult retval)
        {
            IVsTemplate vsTemplate = null;

            try
            {
                DTE dte = new DTETemplate((DTE)Application);
                CustomParams[0] = Environment.ExpandEnvironmentVariables((string)CustomParams[0]);

                if (!Path.IsPathRooted((string)CustomParams[0]) && CustomParams.Length >= 2)
                {
                    var guidancePackageName = (string)CustomParams[1];

                    var guidancePackageConfigurationFile = RecipeManager.GetConfigurationFile(RecipeManagerPackage.Singleton, guidancePackageName);

                    if (!string.IsNullOrEmpty(guidancePackageConfigurationFile))
                    {
                        var template = Path.Combine(Path.GetDirectoryName(guidancePackageConfigurationFile), (string)CustomParams[0]);

                        if (File.Exists(template))
                        {
                            CustomParams[0] = template;
                        }
                    }
                }
                string templateFileName             = (string)CustomParams[0];
                IVsTemplatesService templateService = (IVsTemplatesService)
                                                      ServiceHelper.GetService(
                    (IRecipeManagerService)
                    new VsServiceProvider(Application).GetService(typeof(IRecipeManagerService)),
                    typeof(IVsTemplatesService), this);
                vsTemplate = templateService.GetTemplate(templateFileName);
                string wizardKind = ((string)ContextParams[0]).ToUpper(CultureInfo.InvariantCulture);
                if (wizardKind == Constants.vsWizardNewProject)
                {
                    string destDir = (string)ContextParams[2];
                    //Web projects can pass in an empty directory, if so don't create the dest directory.
                    if ((new System.Uri(destDir)).IsFile)
                    {
                        Directory.CreateDirectory(destDir);
                    }

                    //If adding the project as exclusive, close the current solution then check to see if a
                    //  solution name is specified. If so, then create Ona solution with that name.
                    if (((bool)ContextParams[4]) == true)
                    {
                        vsPromptResult promptResult = dte.ItemOperations.PromptToSave;
                        if (promptResult == vsPromptResult.vsPromptResultCancelled)
                        {
                            retval = wizardResult.wizardResultCancel;
                            return;
                        }
                        dte.Solution.Close(false);
                        if (string.IsNullOrEmpty(((string)ContextParams[5])) == false)
                        {
                            dte.Solution.Create(destDir, ((string)ContextParams[5]));
                        }
                        ContextParams[4] = false;
                    }
                    // Create a new Solution Folder for the multiproject template
                    else if (vsTemplate.VSKind == WizardRunKind.AsMultiProject)
                    {
                        string folderName = (string)ContextParams[1];
                        if (dte.SelectedItems.Count == 1)
                        {
                            object item = DteHelper.GetTarget(dte);
                            if (item is Solution2)
                            {
                                ((Solution2)item).AddSolutionFolder(folderName);
                            }
                            else if (item is Project)
                            {
                                SolutionFolder slnFolder = (SolutionFolder)(((Project)item).Object);
                                slnFolder.AddSolutionFolder(folderName);
                            }
                        }
                    }
                }

                // Pre-fill state with context parameters.
                context = new System.Collections.Specialized.HybridDictionary();
                // See http://msdn.microsoft.com/library/en-us/vsintro7/html/vxlrfcontextparamsenum.asp
                string kind = ((string)ContextParams[0]).ToUpper();
                if (kind == Constants.vsWizardNewProject.ToUpper())
                {
                    FillNewProject(ContextParams, context);
                }
                else if (kind == Constants.vsWizardAddSubProject.ToUpper())
                {
                    FillAddSubProject(ContextParams, context);
                }
                else if (kind == Constants.vsWizardAddItem.ToUpper())
                {
                    FillAddItem(ContextParams, context);
                }

                IDTWizard wizard = new Microsoft.VisualStudio.TemplateWizard.Wizard();
                wizard.Execute(dte, hwndOwner, ref ContextParams, ref CustomParams, ref retval);
            }
            catch (Exception ex)
            {
                retval = wizardResult.wizardResultCancel;
                if (!(ex is COMException) || ((COMException)ex).ErrorCode != VSConstants.E_ABORT)
                {
                    ErrorHelper.Show(this.Site, ex);
                }
            }
            finally
            {
                Debug.Assert(UnfoldTemplate.UnfoldingTemplates.Count == 0);
                UnfoldTemplate.UnfoldingTemplates.Clear();
            }
        }
예제 #14
0
        public INVsSolutionFolder AddSolutionFolder(string name)
        {
            var solutionFolder = _SolutionFolder.AddSolutionFolder(name);

            return(new NVsSolutionFolder(_Solution, solutionFolder));
        }
        protected internal virtual void AddProjectItemsToSolution(SolutionFolder solutionFolder, IEnumerable<ProjectItem> projectItems, string sourceDirectoryPath, string destinationDirectoryPath)
        {
            if(solutionFolder == null)
                throw new ArgumentNullException("solutionFolder");

            if(projectItems == null)
                throw new ArgumentNullException("projectItems");

            foreach(var projectItem in projectItems)
            {
                if(projectItem.IsPhysicalFolder())
                {
                    var childItem = solutionFolder.Parent.ProjectItems.Cast<ProjectItem>().FirstOrDefault(item => string.Equals(item.Name, projectItem.Name, StringComparison.OrdinalIgnoreCase));

                    // ReSharper disable ConvertIfStatementToNullCoalescingExpression
                    if(childItem == null)
                        childItem = solutionFolder.AddSolutionFolder(projectItem.Name).ParentProjectItem;
                    // ReSharper restore ConvertIfStatementToNullCoalescingExpression

                    SolutionFolder childSolutionFolder = null;

                    if(childItem.SubProject != null)
                        childSolutionFolder = childItem.SubProject.Object as SolutionFolder;

                    if(childSolutionFolder == null)
                        throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "The project-item \"{0}\" already exists but is not a solution-folder.", childItem.Name));

                    this.AddProjectItemsToSolution(childSolutionFolder, projectItem.ProjectItems.Cast<ProjectItem>(), this.FileSystem.Path.Combine(sourceDirectoryPath, projectItem.Name), this.FileSystem.Path.Combine(destinationDirectoryPath, projectItem.Name));
                }
                else
                {
                    this.AddProjectItemToSolutionPhysicallyIfNecessary(projectItem, sourceDirectoryPath, destinationDirectoryPath);

                    var itemAlreadyExists = solutionFolder.Parent.ProjectItems.Cast<ProjectItem>().Any(item => string.Equals(item.Name, projectItem.Name, StringComparison.OrdinalIgnoreCase));

                    if(itemAlreadyExists)
                        continue;

                    var filesToDelete = new List<FileInfoBase>();

                    var destinationFilePath = this.FileSystem.Path.Combine(destinationDirectoryPath, projectItem.Name);

                    if(!this.FileSystem.File.Exists(destinationFilePath))
                    {
                        var file = this.FileSystem.FileInfo.FromFileName(destinationFilePath);

                        if(!file.Directory.Exists)
                            file.Directory.Create();

                        using(this.FileSystem.File.Create(destinationFilePath)) {}

                        filesToDelete.Add(file);
                    }

                    solutionFolder.Parent.ProjectItems.AddFromFile(destinationFilePath);

                    var document = this.DevelopmentToolsEnvironment.Documents.Cast<Document>().FirstOrDefault(item => string.Equals(item.FullName, destinationFilePath, StringComparison.OrdinalIgnoreCase));

                    if(document != null)
                        document.Close();

                    foreach(var item in filesToDelete)
                    {
                        var directory = item.Directory;

                        if(item.Exists)
                            item.Delete();

                        if(!directory.GetFileSystemInfos().Any())
                            directory.Delete();
                    }
                }
            }
        }