Exemplo n.º 1
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}'."));
        }
Exemplo n.º 2
0
        public static string GetPackageExecutable(string packageId, string packageExecutable, string framework = null)
        {
            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");

            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)));
        }