Exemple #1
0
        public static bool PackageExists(LocalDirectoryNugetRepository repository, PackageID packageID, Version packageVersion)
        {
            // Does the version directory of the package directory exist?
            var packageVersionDirectoryPath = LocalDirectoryNugetRepository.GetPackageVersionDirectoryPath(repository, packageID, packageVersion);

            if (!packageVersionDirectoryPath.Exists())
            {
                return(false);
            }

            var nuspecFilePath = NuGetIoUtilities.GetNuspecFilePath(packageVersionDirectoryPath);

            // Does the nuspec file in the correct directory actually state the specified packageID and version number?
            var packageSpecification = NuGetIoUtilities.GetPackageSpecification(nuspecFilePath);

            if (packageSpecification.ID != packageID)
            {
                return(false);
            }

            if (packageSpecification.Version != packageVersion)
            {
                return(false);
            }

            return(true);
        }
Exemple #2
0
        public static PackageDirectoryPath GetPackageDirectoryPath(LocalDirectoryNugetRepository repository, PackageID packageID)
        {
            var packageDirectoryName = NuGetIoUtilities.GetPackageDirectoryName(packageID);

            var packageDirectoryPath = PathUtilitiesExtra.Combine(repository.DirectoryPath, packageDirectoryName).Value.AsPackageDirectoryPath();

            return(packageDirectoryPath);
        }
Exemple #3
0
        public static void ListAllPackageVersions(LocalDirectoryNugetRepository repository, PackageID packageID, TextWriter writer)
        {
            var packageDirectoryName = NuGetIoUtilities.GetPackageDirectoryName(packageID);

            var packageDirectoryPath = PathUtilitiesExtra.Combine(repository.DirectoryPath, packageDirectoryName).Value.AsPackageDirectoryPath();

            LocalDirectoryNugetRepository.ListAllPackageVersions(packageDirectoryPath, writer);
        }
Exemple #4
0
        public static void ListPackageVersionInformationNuspec(NuspecFilePath nuspecFilePath, TextWriter writer)
        {
            var packageSpecification = NuGetIoUtilities.GetPackageSpecification(nuspecFilePath);

            var versionForDisplay = packageSpecification.Version.ToStringDisplay();

            writer.WriteLine($"{packageSpecification.ID} {versionForDisplay}");
        }
Exemple #5
0
        public static VersionDirectoryPath GetPackageVersionDirectoryPath(LocalDirectoryNugetRepository repository, PackageID packageID, Version packageVersion)
        {
            var packageDirectoryPath = LocalDirectoryNugetRepository.GetPackageDirectoryPath(repository, packageID);

            var versionDirectoryName = NuGetIoUtilities.GetVersionDirectoryName(packageVersion);

            var packageVersionDirectoryPath = PathUtilitiesExtra.Combine(packageDirectoryPath, versionDirectoryName).Value.AsVersionDirectoryPath();

            return(packageVersionDirectoryPath);
        }
        public static NupkgFilePath Pack(FilePath dotnetExecutableFilePath, ProjectFilePath projectFilePath, DirectoryPath outputDirectoryPath, PackageID packageID, IEnumerable <string> sources, ILogger logger)
        {
            // Determine the project version.
            var projectVersion = VsUtilities.GetVersion(projectFilePath);

            var packageFileName = NugetIoUtilities.GetNupkgFileName(packageID, projectVersion);

            // Determine the .nupkg file-name and file-path (using output directory-path, project ID, project version, and .nupkg file-extension).
            var packageFilePath = PathUtilitiesExtra.GetFilePath(outputDirectoryPath, packageFileName).AsNupkgFilePath();

            logger.LogDebug($"{projectFilePath} - Packing project to:\n{packageFilePath}");

            var arguments = $@"pack ""{projectFilePath}"" --output ""{outputDirectoryPath}"" -p:PackageID={packageID}";

            if (sources.Count() > 0)
            {
                foreach (var source in sources)
                {
                    arguments = arguments.Append($@" --source ""{source}""");
                }
            }

            var outputCollector = ProcessRunner.Run(dotnetExecutableFilePath.Value, arguments);

            // Test for success.
            var lastLine = outputCollector.GetOutputLines().Last().Trim();

            var expectedLastLine = $"Successfully created package '{packageFilePath}'.";

            if (expectedLastLine != lastLine)
            {
                throw new Exception($"dotnet automation error. Command:\n{ ProcessRunner.GetCommandLineIncantation(dotnetExecutableFilePath.Value, arguments) }\n\nOutput:\n{ outputCollector.GetOutputText()}\n\nError:\n{ outputCollector.GetErrorText()}\n");
            }

            logger.LogInformation($"{projectFilePath} - Packed project to:\n{packageFilePath}");

            return(packageFilePath);
        }