コード例 #1
0
        private static async Task <Project> CreateProjectFromTemplateAsync(
            Solution2 solution2,
            string solutionFolderName,
            string projectTemplateFilePath,
            string destPath,
            string projectName)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (string.IsNullOrEmpty(solutionFolderName))
            {
                solution2.AddFromTemplate(projectTemplateFilePath, destPath, projectName, Exclusive: false);
                return(null);
            }
            else
            {
                var solutionFolderProject
                    = await VSSolutionHelper.GetSolutionFolderProjectAsync(solution2, solutionFolderName);

                var solutionFolder = (SolutionFolder)solutionFolderProject.Object;
                solutionFolder.AddFromTemplate(projectTemplateFilePath, destPath, projectName);

                return(solutionFolderProject);
            }
        }
コード例 #2
0
        public static async Task <EnvDTE.SolutionBuild> GetSolutionBuildAsync()
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var solution2 = await VSSolutionHelper.GetDTESolutionAsync();

            var isSolutionAvailable = await VSSolutionHelper.IsSolutionAvailableAsync(solution2);

            if (!isSolutionAvailable)
            {
                throw new ArgumentException("Solution is not available");
            }

            return(solution2.SolutionBuild);
        }
コード例 #3
0
        private static async Task <object> NewProjectAsync(
            string templatePath,
            string outputPath,
            string templateName,
            string projectName,
            string solutionFolderName)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            await VSSolutionHelper.EnsureSolutionAsync(outputPath);

            string projectTemplateFilePath = null;

            var     dte                   = ServiceLocator.GetInstance <DTE>();
            var     dte2                  = (DTE2)dte;
            var     solution2             = dte2.Solution as Solution2;
            Project solutionFolderProject = null;

            dynamic newProject = null;

            projectTemplateFilePath = await GetProjectTemplateFilePathAsync(solution2, templateName, templatePath);

            var solutionDir = Path.GetDirectoryName(solution2.FullName);

            string destPath = null;

            if (string.IsNullOrEmpty(solutionFolderName))
            {
                destPath = Path.Combine(solutionDir, projectName);
            }
            else
            {
                destPath = Path.Combine(solutionDir, Path.Combine(solutionFolderName, projectName));
            }

            var window = dte2.ActiveWindow as Window2;

            solutionFolderProject = await CreateProjectFromTemplateAsync(
                solution2,
                solutionFolderName,
                projectTemplateFilePath,
                destPath,
                projectName);

            await CloseOpenDocumentsAsync(dte2);

            await Activatex86ConfigurationsAsync(dte2);

            window.SetFocus();

            await GetProjectAsync(solution2, projectName, solutionFolderProject);

            // HACK: May need to be fixed
            if (newProject == null)
            {
                newProject = await GetProjectAsync(solution2, projectName, solutionFolderProject);
            }

            if (newProject == null)
            {
                throw new InvalidOperationException(
                          "Could not create new project or could not locate newly created project");
            }

            return(newProject);
        }