Пример #1
0
        public static string GetPackageExecutable(string packageId, string packageExecutable, string version = null, string framework = null)
        {
            ControlFlow.Assert(packageId != null && packageExecutable != null, "packageId != null && packageExecutable != null");

            string GetEmbeddedPackagesDirectory(string singlePackageId)
            {
                var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var embeddedDirectory = (PathConstruction.AbsolutePath)assemblyDirectory / singlePackageId;

                return(Directory.Exists(embeddedDirectory) ? embeddedDirectory : null);
            }

            string GetNuGetPackagesDirectory(string singlePackageId) =>
            NuGetPackagesConfigFile != null
                    ? NuGetPackageResolver.GetLocalInstalledPackage(
                singlePackageId,
                NuGetPackagesConfigFile,
                version)
            .NotNull($"Could not find package '{packageId}'{(version != null ? $" ({version})" : string.Empty)} via '{NuGetPackagesConfigFile}'.")
            .Directory
                    : null;

            string GetPaketPackagesDirectory(string singlePackageId) =>
            PaketPackagesConfigFile != null
                    ? PaketPackageResolver.GetLocalInstalledPackageDirectory(
                singlePackageId,
                PaketPackagesConfigFile)
                    : null;

            var packageIds       = packageId.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            var packageDirectory = packageIds
                                   .Select(x =>
                                           GetEmbeddedPackagesDirectory(x) ??
                                           GetNuGetPackagesDirectory(x) ??
                                           GetPaketPackagesDirectory(x))
                                   .FirstOrDefault().NotNull("packageDirectory != null");

            var packageExecutables         = packageExecutable.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            var absolutePackageExecutables = packageExecutables
                                             .Select(x => Directory.GetFiles(packageDirectory, x, SearchOption.AllDirectories))
                                             .FirstOrDefault(x => x.Length > 0)?.ToList();

            ControlFlow.Assert(absolutePackageExecutables != null,
                               $"Could not find {packageExecutables.Select(x => x.SingleQuote()).Join(", or")} inside '{packageDirectory}'.");
            if (absolutePackageExecutables.Count == 1 && framework == null)
            {
                return(absolutePackageExecutables.Single());
            }

            var frameworks = absolutePackageExecutables.Select(x => new FileInfo(x).Directory.NotNull().Name).ToList();

            ControlFlow.Assert(frameworks.Contains(framework, StringComparer.OrdinalIgnoreCase),
                               $"Package executable {packageExecutable} [{packageId}] requires a framework: {frameworks.JoinComma()}");

            return(absolutePackageExecutables.Single(x => new FileInfo(x).Directory.NotNull().Name.EqualsOrdinalIgnoreCase(framework)));
        }
Пример #2
0
        public static string GetPackageExecutable(string packageId, string packageExecutable)
        {
            ControlFlow.Assert(packageId != null && packageExecutable != null, "packageId != null && packageExecutable != null");
            var packagesConfigFile = NuGetPackageResolver.GetBuildPackagesConfigFile();
            var installedPackage   = NuGetPackageResolver.GetLocalInstalledPackage(packageId, packagesConfigFile)
                                     .NotNull($"Could not find package '{packageId}' via '{packagesConfigFile}'.");
            var packageDirectory = Path.GetDirectoryName(installedPackage.FileName).NotNull("packageDirectory != null");

            return(Directory.GetFiles(packageDirectory, packageExecutable, SearchOption.AllDirectories)
                   .SingleOrDefault()
                   .NotNull($"Could not find '{packageExecutable}' inside '{packageDirectory}'."));
        }
Пример #3
0
        public static string GetPackageExecutable(string packageId, string packageExecutable, string framework = null)
        {
            ControlFlow.Assert(packageId != null && packageExecutable != null, "packageId != null && packageExecutable != null");

            string GetEmbeddedPackagesDirectory()
            {
                var assemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var embeddedDirectory = (PathConstruction.AbsolutePath)assemblyDirectory / packageId;

                return(Directory.Exists(embeddedDirectory) ? embeddedDirectory : null);
            }

            string GetNuGetPackagesDirectory() =>
            NuGetPackagesConfigFile != null
                    ? NuGetPackageResolver.GetLocalInstalledPackage(
                packageId,
                NuGetPackagesConfigFile,
                resolveDependencies : false)
            ?.Directory
                    : null;

            string GetPaketPackagesDirectory() =>
            PaketPackagesConfigFile != null
                    ? PaketPackageResolver.GetLocalInstalledPackageDirectory(
                packageId,
                PaketPackagesConfigFile)
                    : null;

            var packageDirectory = (GetEmbeddedPackagesDirectory() ??
                                    GetNuGetPackagesDirectory() ??
                                    GetPaketPackagesDirectory()).NotNull("packageDirectory != null");

            var executables = Directory.GetFiles(packageDirectory, packageExecutable, SearchOption.AllDirectories);

            ControlFlow.Assert(executables.Length > 0, $"Could not find '{packageExecutable}' inside '{packageDirectory}'.");
            if (executables.Length == 1 && framework == null)
            {
                return(executables.Single());
            }

            var frameworks = executables.Select(x => new FileInfo(x).Directory.NotNull().Name).ToList();

            ControlFlow.Assert(frameworks.Contains(framework, StringComparer.OrdinalIgnoreCase),
                               $"Package executable {packageExecutable} [{packageId}] requires a framework: {frameworks.JoinComma()}");

            return(executables.Single(x => new FileInfo(x).Directory.NotNull().Name.EqualsOrdinalIgnoreCase(framework)));
        }
Пример #4
0
 private static string GetPackageDirectory(string[] packageIds, string version)
 {
     return(packageIds
            .SelectMany(x =>
                        new Func <string>[]
     {
         () => ExecutingAssemblyDirectory != null
                     ? Path.Combine(ExecutingAssemblyDirectory, x)
                     : null,
         () => NuGetAssetsConfigFile != null
                     ? NuGetPackageResolver.GetLocalInstalledPackage(x, NuGetAssetsConfigFile, version)?.Directory
                     : null,
         () => NuGetPackagesConfigFile != null
                     ? NuGetPackageResolver.GetLocalInstalledPackage(x, NuGetPackagesConfigFile, version)?.Directory
                     : null,
         () => PaketPackagesConfigFile != null
                     ? PaketPackageResolver.GetLocalInstalledPackageDirectory(x, PaketPackagesConfigFile)
                     : null
     })
            .Select(x => x.Invoke())
            .FirstOrDefault(Directory.Exists)
            .NotNull(
                new[]
     {
         $"Could not find package {packageIds.Select(x => x.SingleQuote()).JoinCommaOr()} " +
         $"{(version != null ? $"({version}) " : string.Empty)}" +
         "using:"
     }
                .Concat(
                    new[]
     {
         NukeBuild.BuildProjectDirectory == null
                             ? $"Embedded packages directory at '{ExecutingAssemblyDirectory}'"
                             : null,
         NuGetAssetsConfigFile != null
                             ? $"Project assets file '{NuGetAssetsConfigFile}'"
                             : null,
         NuGetPackagesConfigFile != null
                             ? $"NuGet packages config '{NuGetPackagesConfigFile}'"
                             : null,
         PaketPackagesConfigFile != null
                             ? $"Paket packages config '{PaketPackagesConfigFile}'"
                             : null
     }.WhereNotNull().Select(x => $" - {x}")).JoinNewLine()));
 }
Пример #5
0
        public static string GetPackageExecutable(string packageId, string packageExecutable, string framework = null)
        {
            ControlFlow.Assert(packageId != null && packageExecutable != null, "packageId != null && packageExecutable != null");

            string GetPackagesDirectory()
            {
                var embeddedDirectory = NukeBuild.BuildAssemblyDirectory / packageId;

                if (Directory.Exists(embeddedDirectory))
                {
                    return(embeddedDirectory);
                }

                if (NuGetPackagesConfigFile != null)
                {
                    return(NuGetPackageResolver.GetLocalInstalledPackage(
                               packageId,
                               NuGetPackagesConfigFile,
                               resolveDependencies: false)
                           ?.Directory);
                }

                return(PaketPackageResolver.TryGetLocalInstalledPackageDirectory(packageId));
            }

            var packageDirectory = GetPackagesDirectory().NotNull("packageDirectory != null");

            var executables = Directory.GetFiles(packageDirectory, packageExecutable, SearchOption.AllDirectories);

            ControlFlow.Assert(executables.Length > 0, $"Could not find '{packageExecutable}' inside '{packageDirectory}'.");
            if (executables.Length == 1 && framework == null)
            {
                return(executables.Single());
            }

            var frameworks = executables.Select(x => new FileInfo(x).Directory.NotNull().Name).ToList();

            ControlFlow.Assert(frameworks.Contains(framework, StringComparer.OrdinalIgnoreCase),
                               $"Package executable {packageExecutable} [{packageId}] requires a framework: {frameworks.JoinComma()}");

            return(executables.Single(x => new FileInfo(x).Directory.NotNull().Name.EqualsOrdinalIgnoreCase(framework)));
        }
Пример #6
0
        public static string GetPackageExecutable(string packageId, string packageExecutable, string framework = null)
        {
            ControlFlow.Assert(packageId != null && packageExecutable != null, "packageId != null && packageExecutable != null");
            var installedPackage = NuGetPackageResolver.GetLocalInstalledPackage(packageId);
            var packageDirectory = Path.GetDirectoryName(installedPackage.FileName).NotNull("packageDirectory != null");

            var executables = Directory.GetFiles(packageDirectory, packageExecutable, SearchOption.AllDirectories);

            ControlFlow.Assert(executables.Length > 0, $"Could not find '{packageExecutable}' inside '{packageDirectory}'.");
            if (executables.Length == 1 && framework == null)
            {
                return(executables.Single());
            }

            var frameworks = executables.Select(x => new FileInfo(x).Directory.NotNull().Name).ToList();

            ControlFlow.Assert(frameworks.Contains(framework, StringComparer.OrdinalIgnoreCase),
                               $"Package executable {packageExecutable} [{packageId}] requires a framework: {frameworks.JoinComma()}");

            return(executables.Single(x => new FileInfo(x).Directory.NotNull().Name.EqualsOrdinalIgnoreCase(framework)));
        }