public int Execute(NuLinkCommandOptions options) { Console.WriteLine( $"Checking status of packages in {(options.ProjectIsSolution ? "solution" : "project")}: {options.ConsumerProjectPath}"); var allProjects = new WorkspaceLoader().LoadProjects(options.ConsumerProjectPath, options.ProjectIsSolution); var referenceLoader = new PackageReferenceLoader(); var allPackages = referenceLoader.LoadPackageReferences(allProjects); foreach (var package in allPackages) { Console.WriteLine(); Console.WriteLine($"- {package.PackageId} [{package.Version}] @ {package.LibFolderPath}"); var status = package.CheckStatus(); Console.WriteLine($" LibFolderExists ....... {status.LibFolderExists}"); Console.WriteLine($" IsLibFolderLinked ..... {status.IsLibFolderLinked}"); Console.WriteLine($" LibFolderLinkTargetPath {(status.IsLibFolderLinked ? $"-> {status.LibFolderLinkTargetPath}" : "N/A")}"); Console.WriteLine($" LibBackupFolderExists.. {status.LibBackupFolderExists}"); } Console.WriteLine(); return(0); }
public int Execute(NuLinkCommandOptions options) { _ui.ReportMedium(() => $"Checking status of packages in {(options.ProjectIsSolution ? "solution" : "project")}: {options.ConsumerProjectPath}"); var allProjects = new WorkspaceLoader().LoadProjects(options.ConsumerProjectPath, options.ProjectIsSolution); var referenceLoader = new PackageReferenceLoader(_ui); var allPackages = referenceLoader.LoadPackageReferences(allProjects); var orderedPackages = allPackages.OrderBy(p => $"{p.PackageId}@{p.Version}"); _ui.ReportHigh(() => $"{"--- package status ---"}", ConsoleColor.Yellow); foreach (var package in orderedPackages) { var status = package.CheckStatus(); if (status.IsLinkable) { PrintPackage(package, status); } } return(0); void PrintPackage(PackageReferenceInfo reference, PackageStatusInfo status) { var statusColor = (status.IsCorrupt ? ConsoleColor.Red : ConsoleColor.Green); var statusText = (status.IsCorrupt ? "corrupt" : "ok"); var linkedPath = status.LibFolderLinkTargetPath; if (status.IsLibFolderLinked) { _ui.ReportData( () => $"{reference.PackageId} {reference.Version} {statusText} -> {linkedPath}", ConsoleColor.White, ConsoleColor.Cyan, statusColor, ConsoleColor.Magenta); } else { _ui.ReportData( () => $"{reference.PackageId} {reference.Version} {statusText}", ConsoleColor.Gray, ConsoleColor.Cyan, statusColor); } } }
public int Execute(NuLinkCommandOptions options) { Console.WriteLine( $"Checking package references in {(options.ProjectIsSolution ? "solution" : "project")}: {options.ConsumerProjectPath}"); var allProjects = new WorkspaceLoader().LoadProjects(options.ConsumerProjectPath, options.ProjectIsSolution); var referenceLoader = new PackageReferenceLoader(); var allPackages = referenceLoader.LoadPackageReferences(allProjects); var requestedPackage = allPackages.FirstOrDefault(p => p.PackageId == options.PackageId); if (requestedPackage == null) { throw new Exception($"Error: Package not referenced: {options.PackageId}"); } var status = requestedPackage.CheckStatus(); if (!status.LibFolderExists) { throw new Exception($"Error: Cannot link package {options.PackageId}: 'lib' folder not found, expected {requestedPackage.LibFolderPath}"); } if (status.IsLibFolderLinked) { throw new Exception($"Error: Package {requestedPackage.PackageId} is already linked to {status.LibFolderLinkTargetPath}"); } if (!status.LibBackupFolderExists) { Directory.Move(requestedPackage.LibFolderPath, requestedPackage.LibBackupFolderPath); } else { Console.WriteLine($"Warning: backup folder was not expected to exist: {requestedPackage.LibBackupFolderPath}"); } var linkTargetPath = Path.Combine(Path.GetDirectoryName(options.LocalProjectPath), "bin", "Debug"); CreateSymbolicLink(linkPath: requestedPackage.LibFolderPath, targetPath: linkTargetPath); Console.WriteLine($"Linked {requestedPackage.LibFolderPath} -> {linkTargetPath}"); return(0); }
public int Execute(NuLinkCommandOptions options) { _ui.ReportMedium(() => $"Checking package references in {(options.ProjectIsSolution ? "solution" : "project")}: {options.ConsumerProjectPath}"); var allProjects = new WorkspaceLoader().LoadProjects(options.ConsumerProjectPath, options.ProjectIsSolution); var referenceLoader = new PackageReferenceLoader(_ui); var allPackages = referenceLoader.LoadPackageReferences(allProjects); var requestedPackage = allPackages.FirstOrDefault(p => p.PackageId == options.PackageId); if (requestedPackage == null) { throw new Exception($"Error: Package not referenced: {options.PackageId}"); } var status = requestedPackage.CheckStatus(); if (!status.LibFolderExists) { throw new Exception($"Error: Cannot unlink package {options.PackageId}: 'lib' folder not found, expected {requestedPackage.LibFolderPath}"); } if (!status.IsLibFolderLinked) { throw new Exception($"Error: Package {requestedPackage.PackageId} is not linked."); } if (!status.LibBackupFolderExists) { throw new Exception($"Error: Cannot unlink package {options.PackageId}: backup folder not found, expected {requestedPackage.LibBackupFolderPath}"); } Directory.Delete(requestedPackage.LibFolderPath); Directory.Move(requestedPackage.LibBackupFolderPath, requestedPackage.LibFolderPath); _ui.ReportSuccess(() => $"Unlinked {requestedPackage.PackageId}"); _ui.ReportSuccess(() => $" {"-X->"} {status.LibFolderLinkTargetPath}", ConsoleColor.Red, ConsoleColor.DarkYellow); return(0); }
public int Execute(NuLinkCommandOptions options) { _ui.ReportMedium(() => $"Searching package reference in {(options.ProjectIsSolution ? "solution" : "project")}: {options.ConsumerProjectPath}"); var requestedPackage = GetPackageInfo(); var status = requestedPackage.CheckStatus(); var linkTargetPath = options.LocalProjectOutputPath; ValidateOperation(); PerformOperation(); _ui.ReportSuccess(() => $"Linked {requestedPackage.LibFolderPath}"); _ui.ReportSuccess(() => $" -> {linkTargetPath}", ConsoleColor.Magenta); return(0); PackageReferenceInfo GetPackageInfo() { var allProjects = new WorkspaceLoader().LoadProjects(options.ConsumerProjectPath, options.ProjectIsSolution); var referenceLoader = new PackageReferenceLoader(_ui); var package = referenceLoader.LoadPackageReference(allProjects, options.PackageId); return(package ?? throw new Exception($"Error: Package not referenced: {options.PackageId}")); } void ValidateOperation() { if (!status.LibFolderExists) { throw new Exception($"Error: Cannot link package {options.PackageId}: 'lib' folder not found, expected {requestedPackage.LibFolderPath}"); } if (status.IsLibFolderLinked) { throw new Exception($"Error: Package {requestedPackage.PackageId} is already linked to {status.LibFolderLinkTargetPath}"); } if (!Directory.Exists(linkTargetPath)) { throw new Exception($"Error: Target link directory doesn't exist: {linkTargetPath}"); } } void PerformOperation() { if (!status.LibBackupFolderExists) { Directory.Move(requestedPackage.LibFolderPath, requestedPackage.LibBackupFolderPath); } else { _ui.ReportWarning(() => $"Warning: backup folder was not expected to exist: {requestedPackage.LibBackupFolderPath}"); } try { SymbolicLinkWithDiagnostics.Create( fromPath: requestedPackage.LibFolderPath, toPath: linkTargetPath); } catch { RevertOperation(); throw; } } void RevertOperation() { try { _ui.ReportError(() => "Failed to create symlink, reverting changes to package folders."); Directory.Move(requestedPackage.LibBackupFolderPath, requestedPackage.LibFolderPath); } catch (Exception e) { _ui.ReportError(() => $"FAILED to revert package changes: {e.Message}"); _ui.ReportError(() => $"You have to recover manually!"); _ui.ReportError(() => "--- MANUAL RECOVERY INSTRUCTIONS ---"); _ui.ReportError(() => $"1. Go to {Path.GetDirectoryName(requestedPackage.LibFolderPath)}"); _ui.ReportError(() => $"2. Rename '{Path.GetFileName(requestedPackage.LibBackupFolderPath)}'" + $" to '{Path.GetFileName(requestedPackage.LibFolderPath)}'"); _ui.ReportError(() => "--- END OF RECOVERY INSTRUCTIONS ---"); } } }