public TestListCategorizer(string pathToVsmdiFile, string pathToSolution)
 {
     _workspace = MSBuildWorkspace.Create();
     _solution = _workspace.OpenSolutionAsync(pathToSolution).Result;
     var vsmdiParser = new VsmdiParser();
     _testlists = vsmdiParser.ReadFile(pathToVsmdiFile);
 }
示例#2
0
    static public bool TryCreateCompilation(Options options, out Task<Compilation> cu, out MSBuildWorkspace workspace, out Project project) 
    {
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out cu) != null); 
      Contract.Ensures(!Contract.Result<bool>() || Contract.ValueAtReturn(out workspace) != null);

      Output.WriteLine("Opening the solution {0}", options.Solution);

      workspace = MSBuildWorkspace.Create();
      cu = null;
      project = null;
      try
      {
        if (options.Project != null && options.Solution != null)
        {
          return CreateCompilationFromSolution(options, workspace, out cu, out project);
        }
        else
        {
          Output.WriteError("Failed to parse either the Project or Solution");
          // not implemented;
          return false;
        }
      }
      catch(Exception e)
      {
        Output.WriteError("Error while parsing the .csproj file. Exception from Roslyn: {0}", e.ToString());
        cu = null;
        return false;
      }
    }
 public SolutionAnalayzer(string solutionPath)
 {
     _workspace = MSBuildWorkspace.Create();
     _workspace.WorkspaceFailed += _workspace_WorkspaceFailed;
     _solution = _workspace.OpenSolutionAsync(solutionPath).Result;
     _refsourceLinkProvider.Init();
 }
 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)};
 }
示例#5
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};
        }
示例#6
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;
 }
示例#7
0
    private static bool CreateCompilationFromSolution(Options options, MSBuildWorkspace workspace, out Task<Compilation> compilationAsync, out Project project) 
    {
      var solution = workspace.OpenSolutionAsync(options.Solution).Result;
      var projects = solution.Projects.Where(proj => proj.FilePath.Equals(options.Project));
      if (projects.Any())
      {
        project = projects.First();
      }
      else
      {
        Output.WriteError("Unable to find the specified project in solution. Project {0}", options.Project);

        project = null;
        compilationAsync = null;
        return false;
      }

      compilationAsync = project.GetCompilationAsync();
      return true;
    }
        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();
            }
        }
        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);
        }
示例#10
0
 public bool UpgradeProject(MSBuildWorkspace workspace, UFile projectPath)
 {
     return true;
 }
示例#11
0
            public bool 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);
                }
                return true;
            }
示例#12
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);
        }