Exemple #1
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);
        }
Exemple #2
0
        private ProjectData CreateProjectData(IProjectTemplateInfo projectInfo, string destinationFolder)
        {
            ProjectData projectData = new ProjectData
            {
                Name = projectInfo.NameWithoutRoot,
                IsStartup = projectInfo.IsStartup,
                FileName = Utils.GetRelativePath(projectInfo.DestinationFileName, destinationFolder),
                ProjectConfigurations = CreateProjectConfigurations(projectInfo.ProjectConfigurations)
            };


            return projectData;
        }