Пример #1
0
        public SolutionWrapper(string solutionName, VisualStudioVersion visualStudioVersion, ILogger logger)
        {
            _solutionName        = solutionName;
            _visualStudioVersion = visualStudioVersion;
            _logger          = logger;
            _projectWrappers = new List <ProjectWrapper>();
            _dte             = EnvDTEFactory.Create(visualStudioVersion);

            _nonUpdatedProjects = new ObservableCollection <ProjectWrapper>();
            NonUpdatedProjects  = new ReadOnlyCollection <ProjectWrapper>(_nonUpdatedProjects);
        }
Пример #2
0
        public async Task UpdateTargetFrameworkForProjects(TargetFramework framework)
        {
            await OpenSolution();

            var sourceDirectory = Path.GetDirectoryName(_solutionName);
            var suoFiles        = (new DirectoryInfo(sourceDirectory)).GetFiles("*.suo");

            if (!suoFiles.Any())
            {
                _logger.Log("No .suo file, closing and reopening solution");
                await CloseAsync();

                _dte = EnvDTEFactory.Create(_visualStudioVersion);
                await OpenSolution();
            }

            var iterations = 15;

            _logger.Log("Number of projects updating from the solution: {0}", _projectWrappers.Count());
            _logger.Log("Attempting to upgrade all projects to version {0} in {1} attempts", framework.ToDescription(), iterations);

            _nonUpdatedProjects.Clear();
            _projectWrappers.ToList().ForEach(p => _nonUpdatedProjects.Add(p));
            for (int i = 0; i < iterations && _nonUpdatedProjects.Any(p => !p.IsSpecialProject); i++)
            {
                _logger.Log("************ Attempt {0} ************", i + 1);

                var projects = _nonUpdatedProjects.ToArray();
                Parallel.ForEach(projects, async project =>
                {
                    await AttemptTo(() =>
                    {
                        UpdateProject(project, framework);
                    });
                });
            }

            await SaveAsync();
            await CloseAsync();
        }