Exemplo n.º 1
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);
        }
 public ProjectRewriter(ProjectRewriteContext context)
 {
     // rewrite csproj references like <ProjectReference Include="..\$ext_safeprojectname$.Business\$ext_safeprojectname$.Business.csproj">
     Context = context;
 }