示例#1
0
 private static string GetPackageDirectory(string[] packageIds, string version)
 {
     return(packageIds
            .SelectMany(x =>
                        new[]
     {
         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
     })
            .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()));
 }
示例#2
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)));
        }
示例#3
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)));
        }