예제 #1
0
 public ProjectRewriteContext(ProjectRewriteCache cache, string projectPath, CancellationToken cancellationToken, Configuration configuration, SolutionExplorer explorer)
 {
     Cache             = cache ?? throw new ArgumentNullException(nameof(cache));
     ProjectPath       = projectPath ?? throw new ArgumentNullException(nameof(projectPath));
     CancellationToken = cancellationToken;
     Configuration     = configuration;
     Explorer          = explorer;
 }
예제 #2
0
        public async Task <bool> RewriteAsync()
        {
            Log.Debug($"Rewriting folder \"{Folder}\".");
            if (!MoveContentFiles(out var contentFolder))
            {
                return(false);
            }

            var solutionFile = FileHelper.FindSolutionAsync(contentFolder);

            if (!File.Exists(solutionFile))
            {
                Log.Error($"Solution file at \"{contentFolder}\" not found.");
                return(false);
            }

            var explorer = await SolutionExplorer.CreateAsync(solutionFile, Context.Progress, Context.CancellationToken);

            var rootTemplatePath = Path.Combine(Folder, "root.vstemplate");

            var projectRewriteCache = new ProjectRewriteCache(explorer, rootTemplatePath);

            projectRewriteCache.Build();
            try
            {
                CreateRootVsTemplate(Context, projectRewriteCache, rootTemplatePath);
            }
            catch (Exception e)
            {
                Context.Progress.Report($"Failed to create {rootTemplatePath}.");
                await Task.Delay(3000);

                Log.Error(e);
                return(false);
            }

            foreach (var pair in explorer.ProjectsLookup)
            {
                var             context  = new ProjectRewriteContext(projectRewriteCache, pair.Key, Context.CancellationToken, Context.Configuration, explorer);
                ProjectRewriter rewriter = new ProjectRewriter(context);
                await rewriter.ExecuteAsync();
            }

            try
            {
                File.Delete(solutionFile);
            }
            catch (Exception e)
            {
                Log.Error(e);
                return(false);
            }

            Log.Info($"Rewriting complete.");
            return(true);
        }
예제 #3
0
        private IEnumerable <ProjectRewriteCacheEntry> GetSortedSolutionReferences(ProjectRewriteCache cache)
        {
            var references = cache.GetSolutionProjectReferences().ToArray();
            var pp         = Context.Configuration.PrimaryProject;

            if (!string.IsNullOrEmpty(pp) && references.Any(d => string.Equals(pp, d.OriginalAssemblyName, StringComparison.OrdinalIgnoreCase)))
            {
                return(references
                       .Where(d => string.Equals(pp, d.OriginalAssemblyName, StringComparison.OrdinalIgnoreCase))
                       .Concat(references.Where(d => d.OriginalAssemblyName != pp)
                               .OrderBy(d => d.OriginalAssemblyName)));
            }
            else
            {
                return(references.OrderBy(d => d.OriginalAssemblyName));
            }
        }
예제 #4
0
        private void CreateRootVsTemplate(SolutionRewriteContext context, ProjectRewriteCache cache, string templatePath)
        {
            var template = new VsTemplate();

            template.Type = Constants.VsTemplate.ProjectTypes.ProjectGroup;
            template.TemplateData.Hidden             = context.Configuration.HideSubProjects;
            template.TemplateData.CreateInPlace      = context.Configuration.CreateInPlace;
            template.TemplateData.CreateNewFolder    = context.Configuration.CreateNewFolder;
            template.TemplateData.DefaultName        = context.Configuration.DefaultName;
            template.TemplateData.Description        = context.Configuration.Description;
            template.TemplateData.Name               = context.Configuration.Name;
            template.TemplateData.ProvideDefaultName = context.Configuration.ProvideDefaultName;
            template.TemplateData.CodeLanguage       = context.Configuration.CodeLanguage;
            template.TemplateData.Icon               = PackageHelper.GetConfigurationIcon(context.Configuration);

            template.TemplateContent = BuildRootTemplateContent(cache);

            SaveTemplate(template, templatePath);
        }
예제 #5
0
        private TemplateContent BuildRootTemplateContent(ProjectRewriteCache cache)
        {
            /**
             *	root.vstemplate links like
             *	<ProjectTemplateLink ProjectName="$safeprojectname$.Interface" CopyParameters="true">
             *        Interface\InterfaceTemplate.vstemplate
             *      </ProjectTemplateLink>
             */

            var content = new TemplateContent();

            var contentBuilder = new SolutionTemplateContentBuilder(cache, Context);

            content.Children = new NestableContent[]
            {
                contentBuilder.BuildProjectCollection()
            };
            return(content);
        }
예제 #6
0
 public SolutionTemplateContentBuilder(ProjectRewriteCache cache, SolutionRewriteContext context)
 {
     Cache   = cache;
     Context = context;
 }