示例#1
0
        private Project MoveProjectTo(string targetSubFolder, EnvDTE.Project project, string solutionFolderName)
        {
            string projectName      = project.Name;
            string originalLocation = GetSolutionRootPath() + GetSolutionName() + "\\" + projectName;

            if (Directory.Exists(originalLocation))
            {
                Solution2 solution = dte.Solution as Solution2;
                Log("MoveProjectTo: Removing " + projectName + " from solution");
                solution.Remove(project);
                // Give the solution time to release the lock on the project file
                System.Threading.Thread.Sleep(MIN_TIME_FOR_PROJECT_TO_RELEASE_FILE_LOCK);
                PerformManualProjectReplacementsTo(originalLocation + "\\" + projectName + ".csproj");
                string targetLocation = GetSolutionRootPath() + GetSolutionName() + targetSubFolder + projectName;
                Log("MoveProjectTo: Moving " + projectName + " from " + originalLocation + " to target location at " + targetLocation);
                Directory.Move(originalLocation, targetLocation);
                if (!string.IsNullOrEmpty(solutionFolderName))
                {
                    SolutionFolder solutionFolder = (SolutionFolder)solution.AddSolutionFolder(solutionFolderName).Object;
                    Log("MoveProjectTo: Adding " + projectName + " to solution folder " + targetLocation);
                    return(solutionFolder.AddFromFile(targetLocation + "\\" + projectName + ".csproj"));
                }
                else
                {
                    Log("MoveProjectTo: Adding " + projectName + " to solution");
                    return(solution.AddFromFile(targetLocation + "\\" + projectName + ".csproj", false));
                }
            }
            else
            {
                throw new ApplicationException("Couldn't find " + originalLocation + " to move");
            }
        }
示例#2
0
        private Project AddProjectToSolution(SolutionFolder solutionFolder, string newProjectFileName, string fullProjectName, string newProjectDirectory)
        {
            UpdateStatusBar("Adding the new project to the solution...");

            var parentProjectDirectory = new DirectoryInfo(fullProjectName).Parent;

            if (parentProjectDirectory == null)
            {
                throw new InvalidOperationException("The Project Parent Directory Is Null!");
            }

            // Yes, my naming is... perfect?
            var parentProjectParentDirectory = parentProjectDirectory.Parent;

            if (parentProjectParentDirectory == null)
            {
                throw new InvalidOperationException("The Parent Project Parent Directory Is Null!");
            }

            // If there's no solution folder, we can add the project directory to the solution.
            if (solutionFolder == null)
            {
                return(RenameData.Dte.Solution.AddFromFile(
                           Path.Combine(Path.Combine(parentProjectParentDirectory.FullName, newProjectDirectory), newProjectFileName)));
            }

            // Otherwise we must add the renamed project to the solution folder.
            return(solutionFolder.AddFromFile(
                       Path.Combine(Path.Combine(parentProjectParentDirectory.FullName, newProjectDirectory), newProjectFileName)));
        }
		public void RunFinished()
		{
			if (File.Exists(pathToNewSolution))
			{
				File.Delete(pathToNewSolution);
			}

			//if the selected folder exist - we will add the project manually
			if (selectedFolderName != null)
			{
				solution.Open(pathToOldSolution);
				Project selectedProj = solution.FindProjectInSolution(selectedFolderName);
				if (selectedProj != null)
				{
					SolutionFolder selectedFolder = (SolutionFolder)(selectedProj.Object);
					foreach (string projPath in newProjectsPathToAdd)
					{
						selectedFolder.AddFromFile(projPath);
					}
				}
			}

			BuildDependency webApiDependencies = solution.SolutionBuild.BuildDependencies.Item(webApiUniqueID);
			if (webApiDependencies != default)
			{
				foreach (string projUniqueID in newProjectsUniqueIds)
				{
					webApiDependencies.AddProject(projUniqueID);
				}
			}
		}
示例#4
0
        private void AddImportTargets()
        {
            var msBuildEngine = new Microsoft.Build.BuildEngine.Engine();

            foreach (Project prj in _solution.Projects)
            {
                prj.Save();
                var fileName = prj.FullName;
                var prjName  = prj.Name;

                SolutionFolder folder = null;

                if (prj.ParentProjectItem != null)
                {
                    folder = (SolutionFolder)prj.ParentProjectItem.ContainingProject.Object;
                }
                _solution.Remove(prj);

                var msBuildProj = new Microsoft.Build.BuildEngine.Project(msBuildEngine);
                msBuildProj.Load(fileName);

                msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.nuget\nuget.targets", null);
                if (prjName.EndsWith(".Common"))
                {
                    msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\common.targets", null);
                }
                else if (prjName.EndsWith(".Client"))
                {
                    msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\client.targets", null);
                }
                else if (prjName.EndsWith(".Client.WPF"))
                {
                    msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\clientwpf.targets", null);
                }
                else if (prjName.EndsWith(".WPF"))
                {
                    msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\wpf.targets", null);
                }
                else if (prjName.EndsWith(".Server"))
                {
                    msBuildProj.Imports.AddNewImport(@"$(SolutionDir)\.zetbox\server.targets", null);
                }

                msBuildProj.Save(fileName);

                if (folder != null)
                {
                    folder.AddFromFile(fileName);
                }
                else
                {
                    _solution.AddFromFile(fileName);
                }
            }
        }
示例#5
0
 public void AddProjectFromFile(string filePath, SolutionFolder parentFolder)
 {
     try
     {
         parentFolder.AddFromFile(filePath);
     }
     catch (Exception innerException)
     {
         throw new ArgumentException($"Cannot add file {filePath} to solution folder {parentFolder.Parent.Name}.", innerException);
     }
 }
        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"));
            }
        }
        public void RunFinished()
        {
            if (File.Exists(pathToNewSolution))
            {
                File.Delete(pathToNewSolution);
            }

            //if the selected folder exist - we will add the project manually
            if (selectedFolderName != null)
            {
                solution.Open(pathToOldSolution);
                Project selectedProj = solution.FindProjectInSolution(selectedFolderName);
                if (selectedProj != null)
                {
                    SolutionFolder selectedFolder = (SolutionFolder)(selectedProj.Object);
                    foreach (string projPath in projectsToAdd)
                    {
                        selectedFolder.AddFromFile(projPath);
                    }
                }
            }
        }
 public ShellProject AddFromFile(string FileName)
 {
     return(new ShellProject(_folder.AddFromFile(FileName)));
 }
        public void RunFinished()
        {
            Solution2 solution2             = (Solution2)this._dte2.Solution;
            string    slClassLibProjectPath = this._slClassLibProject.FullName;
            string    classLibName          = this._replacementsDictionary["$safeprojectname$"];

            // Determine whether the SL project was created in a Solution Folder.
            // If the user explicitly asked to Add Project under a Solution Folder,
            // it will be non-null.  However if they ask to Create New Project under
            // a Solution Folder but change their mind to say "Add to Solution",
            // they will end up with the Silverlight project as a child of the SLN.
            ProjectItem    projectItem   = this._slClassLibProject.ParentProjectItem;
            ProjectItems   projectItems  = projectItem == null ? null : projectItem.Collection;
            Project        parentProject = projectItems == null ? null : projectItems.Parent as Project;
            SolutionFolder slProjectParentSolutionFolder = (parentProject != null && parentProject.Kind == ProjectKinds.vsProjectKindSolutionFolder)
                                                            ? parentProject.Object as SolutionFolder
                                                            : null;

            // If the SL project was created in a Solution Folder, it wins because we cannot move it (see below).
            // However if the SL project was created as a child of the Solution, we have a choice.  If a Solution Folder
            // was active when the user added the template, that is the one we will use.  But if there was no active
            // Solution Folder, then we unconditionally create a new Solution Folder as a child of the Solution.
            SolutionFolder libFolder = slProjectParentSolutionFolder ?? this._activeSolutionFolder;

            if (libFolder == null)
            {
                try
                {
                    // SL project was created directly under the Solution.  Create a Solution Folder
                    // to hold the pair of projects.
                    libFolder = (SolutionFolder)((Project)solution2.AddSolutionFolder(classLibName)).Object;
                }
                catch (COMException)
                {
                    libFolder = null;
                }
            }

            bool   isVb     = this._slClassLibProject.CodeModel.Language.Equals(CodeModelLanguageConstants.vsCMLanguageVB, StringComparison.OrdinalIgnoreCase);
            string language = isVb ? "VisualBasic" : "CSharp";

            // CSDMain 228876
            // Appending the FrameworkVersion to the file name when calling GetProjectTemplate is an undocumented way to request a specific $targetframeworkversion$ token
            // to become available to the child template.  Without doing this, the default target framework value is used, which for VS 11 is 4.5.
            // Reference: http://www.visualstudiodev.com/visual-studio-extensibility/using-automation-to-create-templates-using-different-framework-versions-in-vs2008-23148.shtml
            string templateName = "ClassLibrary.zip|FrameworkVersion=" + this._replacementsDictionary["$targetframeworkversion$"];
            string netClassLibProjectTemplate = solution2.GetProjectTemplate(templateName, language);
            string netClassLibProjectName     = classLibName + ".Web";
            string destination = Path.Combine(Path.GetDirectoryName(Path.GetDirectoryName(slClassLibProjectPath)), netClassLibProjectName);

            // This code executes if we either created our own SolutionFolder or are using
            // the one the user chose.
            if (libFolder != null)
            {
                // Create the .NET class library in whichever SolutionFolder we decided to use above
                libFolder.AddFromTemplate(netClassLibProjectTemplate, destination, netClassLibProjectName);

                // If the SL project was created as a child of the Solution, we need to move it
                // into our new Solution Folder.  However, if it was created in a Solution Folder,
                // we leave it as is.  Dev10 bug 893488 disallows moving the SL project from one
                // Solution Folder to another, so this strategy avoids that issue.
                if (slProjectParentSolutionFolder == null)
                {
                    // Move the Silverlight library under the folder
                    solution2.Remove(this._slClassLibProject);

                    this._slClassLibProject = libFolder.AddFromFile(slClassLibProjectPath);
                }
            }
            else
            {
                solution2.AddFromTemplate(netClassLibProjectTemplate, destination, netClassLibProjectName, false);
            }


            // Link the two class libraries together

            string       extension   = Path.GetExtension(slClassLibProjectPath);
            IVsSolution  ivsSolution = (IVsSolution)Package.GetGlobalService(typeof(SVsSolution));
            IVsHierarchy hierarchy;

            ivsSolution.GetProjectOfUniqueName(_slClassLibProject.UniqueName, out hierarchy);
            IVsBuildPropertyStorage buildPropertyStorage = (IVsBuildPropertyStorage)hierarchy;

            buildPropertyStorage.SetPropertyValue("LinkedOpenRiaServerProject", null,
                                                  (uint)_PersistStorageType.PST_PROJECT_FILE,
                                                  Path.Combine("..", Path.Combine(netClassLibProjectName, netClassLibProjectName + extension)));
            buildPropertyStorage.SetPropertyValue("DisableFastUpToDateCheck", null,
                                                  (uint)_PersistStorageType.PST_PROJECT_FILE,
                                                  "true");
        }
示例#10
0
        private void CreateProject(
            SolutionFolder solutionFolder,
            ProjectData projectData,
            Action<double> progressAction,
            CancellationToken ct)
        {
            var projectName = $"{_replacementsDictionary["$safeprojectname$"]}.{projectData.Name}";

            var sourceFileName = Path.Combine(_tmpFolder, projectData.FileName);
            var sourceDir = Path.GetDirectoryName(sourceFileName);
            var solutionDir = _replacementsDictionary["$solutiondirectory$"];
            var destDir = Path.Combine(solutionDir, projectName);

            var replacementDictionary = CreateProjectReplacementDictionary(projectName);
            CopyDirectory(replacementDictionary, sourceDir, destDir, progressAction, ct);

            var oldFileName = Path.GetFileName(sourceFileName);
            var ext = Path.GetExtension(oldFileName);
            var newFileName = projectName + ext;
            var newFullFileName = Path.Combine(destDir, newFileName);

            File.Move(Path.Combine(destDir, oldFileName), newFullFileName);

            var solutionData = _wizardDataViewModel.SelectedSolution;
            ModifyProject(newFullFileName, solutionData);

            var addedProject = solutionFolder == null
                ? GetSolution().AddFromFile(newFullFileName)
                : solutionFolder.AddFromFile(newFullFileName);

            foreach (SolutionConfiguration solutionConfiguration in GetSolution().SolutionBuild.SolutionConfigurations)
            {
                var solutionContext = solutionConfiguration.SolutionContexts
                    .OfType<SolutionContext>()
                    .Single(x => x.ProjectName.EndsWith(newFileName));

                Debug.WriteLine("Project Name: " + projectName);

                var name = solutionConfiguration.Name;
                name = $"{name}|{solutionContext.PlatformName}";

                var projectConfiguration = projectData.ProjectConfigurations.SingleOrDefault(x => x.Name == name);

                if (projectConfiguration == null && System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debugger.Break();
                }

                Debug.Assert(projectConfiguration != null, "ProjectConfiguration not found for " + name);

                try
                {
                    solutionContext.ConfigurationName = projectConfiguration.ConfigurationName;
                    solutionContext.ShouldBuild = projectConfiguration.IncludeInBuild;
                }
                catch (COMException)
                {
                }
            }

            if (projectData.IsStartup)
            {
                GetSolution().Properties.Item("StartupProject").Value = addedProject.Name;
            }

            progressAction(1.0);
        }
示例#11
0
        private void AddProject(SolutionFolder parent, ProjectTemplate project, IList<Project> projects)
        {
            var projectFullName = project.FileName;
            var projectFileName = Path.GetFileName(projectFullName);
            var projectDirectory = Path.GetDirectoryName(projectFullName);

            Debug.Assert(projectDirectory != null, "projectDirectory != null");

            var directoryName = Path.GetDirectoryName(projectDirectory);
            var path1 = Path.GetDirectoryName(directoryName);

            Debug.Assert(path1 != null, "path1 != null");

            var newProjectDirectory = Path.Combine(path1, Path.GetFileName(projectDirectory));

            Debug.Assert(projectFileName != null, "projectFileName != null");

            var newProjectFullName = Path.Combine(newProjectDirectory, projectFileName);

            CopyDirectory(projectDirectory, newProjectDirectory);

            var addedProject = parent == null
                ? GetSolution().AddFromFile(newProjectFullName)
                : parent.AddFromFile(newProjectFullName);

            projects.Add(addedProject);
        }
示例#12
0
        public INVsProject AddExistingProject(string projectFilePath)
        {
            var project = _SolutionFolder.AddFromFile(projectFilePath);

            return(new NVsProject(_Solution, project));
        }