private static async Task<IEnumerable<Project>>  GetProjects(string solutionFilePath, CancellationToken cancellationToken,
     MSBuildWorkspace msWorkspace)
 {
     if (solutionFilePath.EndsWith(".sln"))
     {
         var solution = await msWorkspace.OpenSolutionAsync(solutionFilePath, cancellationToken);
         return solution.Projects;
     }
     return new [] { await msWorkspace.OpenProjectAsync(solutionFilePath, cancellationToken)};
 }
Ejemplo n.º 2
0
        private static IEnumerable<Project> LoadProjectsFromFile(string filename, MSBuildWorkspace workspace)
        {
            if (Path.GetExtension(filename) == ".sln")
            {
                var solution = workspace.OpenSolutionAsync(filename).Result;
                return solution.Projects;
            }

            var project = workspace.OpenProjectAsync(filename).Result;
            return new List<Project> {project};
        }
        public void Analyze()
        {
            workspace = MSBuildWorkspace.Create();
            try
            {
                var project = workspace.OpenProjectAsync(Path).Result;
                if (!project.HasDocuments && !project.IsCSharpProject())
                {
                    return;
                }
                
                Type = project.GetProjectType();

                foreach (var document in project.Documents)
                {
                    AnalyzeSourceFile(document);
                }
                IsAnalyzed = true;
            }
            catch (Exception ex)
            {
                IsAnalyzed = false;
                if (ex is InvalidProjectFileException ||
                    ex is FormatException ||
                    ex is ArgumentException ||
                    ex is PathTooLongException ||
                    ex is AggregateException)
                {
                    Logs.ErrorLog.Info("Project not analyzed: {0}: Reason: {1}", Path, ex.Message);
                }
                else
                    throw;
            }
            finally
            {
                workspace.Dispose();
            }
        }
Ejemplo n.º 4
0
        private async Task UpgradeProject(MSBuildWorkspace workspace, UFile projectPath)
        {
            // Upgrade .csproj file
            // TODO: Use parsed file?
            var fileContents = File.ReadAllText(projectPath);

            // Rename referenced to the package, shaders and effects
            var newFileContents = fileContents.Replace(".pdx", ".xk");

            // Rename variables
            newFileContents = newFileContents.Replace("Paradox", "Xenko");

            // Save file if there were any changes
            if (newFileContents != fileContents)
            {
                File.WriteAllText(projectPath, newFileContents);
            }

            // Upgrade source code
            var project = await workspace.OpenProjectAsync(projectPath.ToWindowsPath());
            var compilation = await project.GetCompilationAsync();
            var tasks = compilation.SyntaxTrees.Select(syntaxTree => Task.Run(() => UpgradeSourceFile(syntaxTree))).ToList();

            await Task.WhenAll(tasks);
        }
Ejemplo n.º 5
0
 private static IEnumerable<Project> LoadProjectsFromFile(string filename, MSBuildWorkspace ws)
 {
     IEnumerable<Project> projects;
     if (Path.GetExtension(filename) == ".sln")
     {
         var solution = ws.OpenSolutionAsync(filename).Result;
         projects = solution.Projects;
     }
     else
     {
         var project = ws.OpenProjectAsync(filename).Result;
         projects = new List<Project> { project };
     }
     return projects;
 }
Ejemplo n.º 6
0
        private async Task UpgradeProject(MSBuildWorkspace workspace, UFile projectPath)
        {
            // Upgrade .csproj file
            // TODO: Use parsed file?
            var fileContents = File.ReadAllText(projectPath);

            // Rename referenced to the package, shaders and effects
            var newFileContents = fileContents.Replace(".pdx", ".xk");

            // Rename variables
            newFileContents = newFileContents.Replace("Paradox", "Xenko");

            // Create fallback for old environment variable
            var index = newFileContents.IndexOf("<SiliconStudioCurrentPackagePath>", StringComparison.InvariantCulture);
            if (index >= 0)
            {
                newFileContents = newFileContents.Insert(index, "<SiliconStudioXenkoDir Condition=\"'$(SiliconStudioXenkoDir)' == ''\">$(SiliconStudioParadoxDir)</SiliconStudioXenkoDir>\n    ");
            }

            // Save file if there were any changes
            if (newFileContents != fileContents)
            {
                File.WriteAllText(projectPath, newFileContents);
            }

            // Upgrade source code
            var project = await workspace.OpenProjectAsync(projectPath.ToWindowsPath());
            var compilation = await project.GetCompilationAsync();
            var tasks = compilation.SyntaxTrees.Select(syntaxTree => Task.Run(() => UpgradeSourceFile(syntaxTree))).ToList();

            await Task.WhenAll(tasks);
        }