Ejemplo n.º 1
0
        internal string FindXprojFile(string projectDirectory)
        {
            var allXprojFiles = Directory.EnumerateFiles(projectDirectory, "*.xproj", SearchOption.TopDirectoryOnly);

            if (allXprojFiles.Count() > 1)
            {
                MigrationErrorCodes
                .MIGRATE1017($"Multiple xproj files found in {projectDirectory}, please specify which to use")
                .Throw();
            }

            return(allXprojFiles.FirstOrDefault());
        }
Ejemplo n.º 2
0
        internal string FindXprojFile(string projectDirectory)
        {
            var allXprojFiles = Directory.EnumerateFiles(projectDirectory, "*.xproj", SearchOption.TopDirectoryOnly);

            if (allXprojFiles.Count() > 1)
            {
                MigrationErrorCodes
                .MIGRATE1017(String.Format(LocalizableStrings.MultipleXprojFilesError, projectDirectory))
                .Throw();
            }

            return(allXprojFiles.FirstOrDefault());
        }
Ejemplo n.º 3
0
        private IEnumerable <ProjectDependency> ResolveProjectDependencies(
            ProjectContext projectContext,
            IEnumerable <string> preResolvedProjects = null,
            SlnFile slnFile = null)
        {
            preResolvedProjects = preResolvedProjects ?? new HashSet <string>();

            var projectExports = projectContext.CreateExporter("_").GetDependencies();
            var possibleProjectDependencies =
                FindPossibleProjectDependencies(slnFile, projectContext.ProjectFile.ProjectFilePath);

            var projectDependencies = new List <ProjectDependency>();

            foreach (var projectExport in
                     projectExports.Where(p => p.Library.Identity.Type == LibraryType.Project))
            {
                var projectExportName = projectExport.Library.Identity.Name;
                ProjectDependency projectDependency;

                if (preResolvedProjects.Contains(projectExportName))
                {
                    continue;
                }

                if (!possibleProjectDependencies.TryGetValue(projectExportName, out projectDependency))
                {
                    if (projectExport.Library.Identity.Type.Equals(LibraryType.Project))
                    {
                        MigrationErrorCodes
                        .MIGRATE1014(String.Format(LocalizableStrings.MIGRATE1014Arg, projectExportName)).Throw();
                    }
                    else
                    {
                        continue;
                    }
                }

                projectDependencies.Add(projectDependency);
            }

            return(projectDependencies);
        }
Ejemplo n.º 4
0
        public IEnumerable <ProjectDependency> ResolveAllProjectDependenciesForFramework(
            ProjectDependency projectToResolve,
            NuGetFramework framework,
            IEnumerable <string> preResolvedProjects = null,
            SlnFile solutionFile = null)
        {
            var projects = new List <ProjectDependency> {
                projectToResolve
            };
            var allDependencies = new HashSet <ProjectDependency>();

            while (projects.Count > 0)
            {
                var project = projects.First();
                projects.Remove(project);
                if (!File.Exists(project.ProjectFilePath))
                {
                    MigrationErrorCodes
                    .MIGRATE1018(String.Format(LocalizableStrings.MIGRATE1018Arg, project.ProjectFilePath)).Throw();
                }

                var projectContext =
                    ProjectContext.CreateContextForEachFramework(project.ProjectFilePath).FirstOrDefault();
                if (projectContext == null)
                {
                    continue;
                }

                var dependencies = ResolveDirectProjectDependenciesForFramework(
                    projectContext.ProjectFile,
                    framework,
                    preResolvedProjects,
                    solutionFile,
                    HoistDependenciesThatAreNotDirectDependencies(projectToResolve, project)
                    );
                projects.AddRange(dependencies);
                allDependencies.UnionWith(dependencies);
            }

            return(allDependencies);
        }
Ejemplo n.º 5
0
        private void VerifyProject(IEnumerable <ProjectContext> projectContexts, string projectDirectory)
        {
            if (projectContexts.Count() > 1)
            {
                MigrationErrorCodes.MIGRATE20011($"Multi-TFM projects currently not supported.").Throw();
            }

            if (!projectContexts.Any())
            {
                MigrationErrorCodes.MIGRATE1013($"No projects found in {projectDirectory}").Throw();
            }

            var defaultProjectContext = projectContexts.First();

            if (defaultProjectContext.LockFile == null)
            {
                MigrationErrorCodes.MIGRATE1012(
                    $"project.lock.json not found in {projectDirectory}, please run dotnet restore before doing migration").Throw();
            }

            var diagnostics = defaultProjectContext.ProjectFile.Diagnostics;

            if (diagnostics.Any())
            {
                MigrationErrorCodes.MIGRATE1011(
                    $"{projectDirectory}{Environment.NewLine}{string.Join(Environment.NewLine, diagnostics.Select(d => d.Message))}")
                .Throw();
            }

            var compilerName =
                defaultProjectContext.ProjectFile.GetCompilerOptions(defaultProjectContext.TargetFramework, "_")
                .CompilerName;

            if (!compilerName.Equals("csc", StringComparison.OrdinalIgnoreCase))
            {
                MigrationErrorCodes.MIGRATE20013(
                    $"Cannot migrate project {defaultProjectContext.ProjectFile.ProjectFilePath} using compiler {compilerName}").Throw();
            }
        }
Ejemplo n.º 6
0
        public IEnumerable <ProjectDependency> ResolveProjectDependencies(ProjectContext projectContext, IEnumerable <string> preResolvedProjects = null)
        {
            preResolvedProjects = preResolvedProjects ?? new HashSet <string>();

            var projectExports = projectContext.CreateExporter("_").GetDependencies();
            var possibleProjectDependencies =
                FindPossibleProjectDependencies(projectContext.ProjectFile.ProjectFilePath);

            var projectDependencies = new List <ProjectDependency>();

            foreach (var projectExport in projectExports)
            {
                var projectExportName = projectExport.Library.Identity.Name;
                ProjectDependency projectDependency;

                if (preResolvedProjects.Contains(projectExportName))
                {
                    continue;
                }

                if (!possibleProjectDependencies.TryGetValue(projectExportName, out projectDependency))
                {
                    if (projectExport.Library.Identity.Type.Equals(LibraryType.Project))
                    {
                        MigrationErrorCodes
                        .MIGRATE1014($"Unresolved project dependency ({projectExportName})").Throw();
                    }
                    else
                    {
                        continue;
                    }
                }

                projectDependencies.Add(projectDependency);
            }

            return(projectDependencies);
        }