Exemplo n.º 1
0
        private void Fix(string project, string reference)
        {
            var moduleName = Helper.GetRootFolder(reference);

            if (moduleName == rootModuleName && reference.ToLower().Contains("\\packages\\"))
            {
                return;
            }

            if (!Directory.Exists(Path.Combine(Helper.CurrentWorkspace, moduleName)))
            {
                if (!missingModules.Contains(moduleName))
                {
                    ConsoleWriter.WriteError($"Can't find module '{moduleName}'");
                    missingModules.Add(moduleName);
                }
                return;
            }
            if (!File.Exists(Path.Combine(Helper.CurrentWorkspace, moduleName, Helper.YamlSpecFile)))
            {
                fixReferenceResult.NoYamlModules.Add(moduleName);
                return;
            }

            var installFiles = InstallHelper.GetAllInstallFiles(moduleName).ToList();
            var withSameName = installFiles.Where(file => Path.GetFileName(file).Equals(Path.GetFileName(reference))).ToList();

            if (!withSameName.Any())
            {
                withSameName = InstallHelper.GetAllInstallFiles().Where(file => Path.GetFileName(file).Equals(Path.GetFileName(reference))).ToList();
            }
            if (withSameName.Any(r => Path.GetFullPath(r) == Path.GetFullPath(reference)))
            {
                TryAddToDeps(reference, project);
                return;
            }

            if (!withSameName.Any())
            {
                if (Helper.GetRootFolder(reference) != rootModuleName)
                {
                    fixReferenceResult.NotFound[project].Add(reference);
                }
                return;
            }

            var newReference = withSameName.Count == 1 && moduleName != rootModuleName
                ? withSameName.First()
                : UserChoseReplace(project, reference, withSameName);

            if (newReference != null)
            {
                UpdateReference(newReference, project);
                TryAddToDeps(newReference, project);
                hasFixedReferences = true;
            }
        }