Beispiel #1
0
        public BaseCommandRunner(BaseArgs baseArgs)
        {
            var packArgs = new PackArgs
            {
                CurrentDirectory = baseArgs.CurrentDirectory,
                Logger           = baseArgs.Console,
                Arguments        = new string[0],
                MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(null, null, baseArgs.Console).Value.Path)
            };

            // Get the input file
            packArgs.Path = PackCommandRunner.GetInputFile(packArgs);

            // Set the current directory if the files being packed are in a different directory
            PackCommandRunner.SetupCurrentDirectory(packArgs);
            packArgs.Build   = false;
            packArgs.Exclude = new string[0];
            switch (baseArgs.Verbosity)
            {
            case Verbosity.Detailed:
            {
                packArgs.LogLevel = LogLevel.Verbose;
                break;
            }

            case Verbosity.Normal:
            {
                packArgs.LogLevel = LogLevel.Information;
                break;
            }

            case Verbosity.Quiet:
            {
                packArgs.LogLevel = LogLevel.Minimal;
                break;
            }
            }
            this._packArgs = packArgs;
        }
Beispiel #2
0
        public override void ExecuteCommand()
        {
            var packArgs = new PackArgs();

            packArgs.Logger           = Console;
            packArgs.Arguments        = Arguments;
            packArgs.OutputDirectory  = OutputDirectory;
            packArgs.BasePath         = BasePath;
            packArgs.MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(MSBuildPath, MSBuildVersion, Console).Value.Path);

            if (!string.IsNullOrEmpty(PackagesDirectory))
            {
                packArgs.PackagesDirectory = Path.GetFullPath(PackagesDirectory);
            }

            if (!string.IsNullOrEmpty(SolutionDirectory))
            {
                packArgs.SolutionDirectory = Path.GetFullPath(SolutionDirectory);
            }

            // Get the input file
            packArgs.Path = PackCommandRunner.GetInputFile(packArgs);

            // Set the current directory if the files being packed are in a different directory
            PackCommandRunner.SetupCurrentDirectory(packArgs);

            Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildPackage"), Path.GetFileName(packArgs.Path));

            if (!string.IsNullOrEmpty(MinClientVersion))
            {
                if (!System.Version.TryParse(MinClientVersion, out _minClientVersionValue))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("PackageCommandInvalidMinClientVersion"));
                }
            }

            if (!string.IsNullOrEmpty(SymbolPackageFormat))
            {
                packArgs.SymbolPackageFormat = PackArgs.GetSymbolPackageFormat(SymbolPackageFormat);
            }
            packArgs.Deterministic             = Deterministic;
            packArgs.Build                     = Build;
            packArgs.Exclude                   = Exclude;
            packArgs.ExcludeEmptyDirectories   = ExcludeEmptyDirectories;
            packArgs.IncludeReferencedProjects = IncludeReferencedProjects;
            switch (Verbosity)
            {
            case Verbosity.Detailed:
            {
                packArgs.LogLevel = LogLevel.Verbose;
                break;
            }

            case Verbosity.Normal:
            {
                packArgs.LogLevel = LogLevel.Information;
                break;
            }

            case Verbosity.Quiet:
            {
                packArgs.LogLevel = LogLevel.Minimal;
                break;
            }
            }
            packArgs.MinClientVersion  = _minClientVersionValue;
            packArgs.NoDefaultExcludes = NoDefaultExcludes;
            packArgs.NoPackageAnalysis = NoPackageAnalysis;
            if (Properties.Any())
            {
                packArgs.Properties.AddRange(Properties);
            }
            packArgs.Suffix  = Suffix;
            packArgs.Symbols = Symbols;
            packArgs.Tool    = Tool;
            packArgs.InstallPackageToOutputPath    = InstallPackageToOutputPath;
            packArgs.OutputFileNamesWithoutVersion = OutputFileNamesWithoutVersion;

            if (!string.IsNullOrEmpty(Version))
            {
                NuGetVersion version;
                if (!NuGetVersion.TryParse(Version, out version))
                {
                    throw new PackagingException(NuGetLogCode.NU5010, string.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, Version));
                }
                packArgs.Version = version.ToFullString();
            }

            var packCommandRunner = new PackCommandRunner(packArgs, ProjectFactory.ProjectCreator);

            packCommandRunner.BuildPackage();
        }
        public static void Register(CommandLineApplication app, Func <ILogger> getLogger)
        {
            app.Command("pack", pack =>
            {
                pack.Description = Strings.PackCommand_Description;

                pack.Option(
                    CommandConstants.ForceEnglishOutputOption,
                    Strings.ForceEnglishOutput_Description,
                    CommandOptionType.NoValue);

                var basePath = pack.Option(
                    "-b|--base-path <basePath>",
                    Strings.BasePath_Description,
                    CommandOptionType.SingleValue);

                var build = pack.Option(
                    "--build",
                    Strings.Build_Description,
                    CommandOptionType.NoValue);

                var exclude = pack.Option(
                    "--exclude",
                    Strings.Exclude_Description,
                    CommandOptionType.MultipleValue);

                var excludeEmpty = pack.Option(
                    "-e|--exclude-empty-directories",
                    Strings.ExcludeEmptyDirectories_Description,
                    CommandOptionType.NoValue);

                var minClientVersion = pack.Option(
                    "--min-client-version <version>",
                    Strings.MinClientVersion_Description,
                    CommandOptionType.SingleValue);

                var noDefaultExcludes = pack.Option(
                    "--no-default-excludes",
                    Strings.NoDefaultExcludes_Description,
                    CommandOptionType.NoValue);

                var noPackageAnalysis = pack.Option(
                    "--no-package-analysis",
                    Strings.NoPackageAnalysis_Description,
                    CommandOptionType.NoValue);

                var outputDirectory = pack.Option(
                    "-o|--output-directory <outputDirectory>",
                    Strings.OutputDirectory_Description,
                    CommandOptionType.SingleValue);

                var properties = pack.Option(
                    "-p|--properties <properties>",
                    Strings.OutputDirectory_Description,
                    CommandOptionType.SingleValue);

                var suffix = pack.Option(
                    "--suffix <suffix>",
                    Strings.Suffix_Description,
                    CommandOptionType.SingleValue);

                var symbols = pack.Option(
                    "-s|--symbols",
                    Strings.Symbols_Description,
                    CommandOptionType.NoValue);

                var verbosity = pack.Option(
                    "--verbosity <level>",
                    Strings.Switch_Verbosity,
                    CommandOptionType.SingleValue);

                var versionOption = pack.Option(
                    "-v|--version <version>",
                    Strings.Version_Description,
                    CommandOptionType.SingleValue);

                var arguments = pack.Argument(
                    "nuspec or project.json file",
                    Strings.InputFile_Description,
                    multipleValues: true);

                pack.OnExecute(() =>
                {
                    var logger         = getLogger();
                    var packArgs       = new PackArgs();
                    packArgs.Logger    = logger;
                    packArgs.Arguments = arguments.Values;
                    packArgs.Path      = PackCommandRunner.GetInputFile(packArgs);

                    // Set the current directory if the files being packed are in a different directory
                    PackCommandRunner.SetupCurrentDirectory(packArgs);

                    logger.LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.PackageCommandAttemptingToBuildPackage, Path.GetFileName(packArgs.Path)));

                    // If the BasePath is not specified, use the directory of the input file (nuspec / proj) file
                    packArgs.BasePath = !basePath.HasValue() ? Path.GetDirectoryName(Path.GetFullPath(packArgs.Path)) : basePath.Value();
                    packArgs.BasePath = packArgs.BasePath.TrimEnd(Path.DirectorySeparatorChar);

                    packArgs.Build   = build.HasValue();
                    packArgs.Exclude = exclude.Values;
                    packArgs.ExcludeEmptyDirectories = excludeEmpty.HasValue();
                    packArgs.LogLevel = XPlatUtility.GetLogLevel(verbosity);

                    if (minClientVersion.HasValue())
                    {
                        Version version;
                        if (!Version.TryParse(minClientVersion.Value(), out version))
                        {
                            throw new ArgumentException(Strings.PackageCommandInvalidMinClientVersion);
                        }
                        packArgs.MinClientVersion = version;
                    }

                    packArgs.MachineWideSettings = new CommandLineXPlatMachineWideSetting();
                    packArgs.MsBuildDirectory    = new Lazy <string>(() => string.Empty);
                    packArgs.NoDefaultExcludes   = noDefaultExcludes.HasValue();
                    packArgs.NoPackageAnalysis   = noPackageAnalysis.HasValue();
                    packArgs.OutputDirectory     = outputDirectory.Value();

                    if (properties.HasValue())
                    {
                        foreach (var property in properties.Value().Split(';'))
                        {
                            int index = property.IndexOf('=');
                            if (index > 0 && index < property.Length - 1)
                            {
                                packArgs.Properties.Add(property.Substring(0, index), property.Substring(index + 1));
                            }
                        }
                    }

                    packArgs.Suffix  = suffix.Value();
                    packArgs.Symbols = symbols.HasValue();
                    if (versionOption.HasValue())
                    {
                        NuGetVersion version;
                        if (!NuGetVersion.TryParse(versionOption.Value(), out version))
                        {
                            throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Strings.PackageVersionInvalid, versionOption.Value()));
                        }
                        packArgs.Version = version.ToNormalizedString();
                    }

                    PackCommandRunner packCommandRunner = new PackCommandRunner(packArgs, null);
                    packCommandRunner.BuildPackage();

                    return(0);
                });
            });
        }
Beispiel #4
0
        public override void ExecuteCommand()
        {
            PackArgs packArgs = new PackArgs();

            packArgs.Logger          = Console;
            packArgs.Arguments       = Arguments;
            packArgs.OutputDirectory = OutputDirectory;

            // The directory that contains msbuild
            packArgs.MsBuildDirectory = new Lazy <string>(() => MsBuildUtility.GetMsbuildDirectory(MSBuildVersion, Console));

            // Get the input file
            packArgs.Path = PackCommandRunner.GetInputFile(packArgs);

            // Set the current directory if the files being packed are in a different directory
            PackCommandRunner.SetupCurrentDirectory(packArgs);

            Console.WriteLine(LocalizedResourceManager.GetString("PackageCommandAttemptingToBuildPackage"), Path.GetFileName(packArgs.Path));

            // If the BasePath is not specified, use the directory of the input file (nuspec / proj) file
            BasePath = String.IsNullOrEmpty(BasePath) ? Path.GetDirectoryName(Path.GetFullPath(packArgs.Path)) : BasePath;
            BasePath = BasePath.TrimEnd(Path.DirectorySeparatorChar);

            if (!String.IsNullOrEmpty(MinClientVersion))
            {
                if (!System.Version.TryParse(MinClientVersion, out _minClientVersionValue))
                {
                    throw new CommandLineException(LocalizedResourceManager.GetString("PackageCommandInvalidMinClientVersion"));
                }
            }

            packArgs.BasePath = BasePath;
            packArgs.Build    = Build;
            packArgs.Exclude  = Exclude;
            packArgs.ExcludeEmptyDirectories   = ExcludeEmptyDirectories;
            packArgs.IncludeReferencedProjects = IncludeReferencedProjects;
            switch (Verbosity)
            {
            case Verbosity.Detailed:
            {
                packArgs.LogLevel = Common.LogLevel.Verbose;
                break;
            }

            case Verbosity.Normal:
            {
                packArgs.LogLevel = Common.LogLevel.Information;
                break;
            }

            case Verbosity.Quiet:
            {
                packArgs.LogLevel = Common.LogLevel.Minimal;
                break;
            }
            }
            packArgs.MinClientVersion  = _minClientVersionValue;
            packArgs.NoDefaultExcludes = NoDefaultExcludes;
            packArgs.NoPackageAnalysis = NoPackageAnalysis;
            if (Properties.Any())
            {
                packArgs.Properties.AddRange(Properties);
            }
            packArgs.Suffix  = Suffix;
            packArgs.Symbols = Symbols;
            packArgs.Tool    = Tool;

            if (!string.IsNullOrEmpty(Version))
            {
                NuGetVersion version;
                if (!NuGetVersion.TryParse(Version, out version))
                {
                    throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, NuGetResources.InstallCommandPackageReferenceInvalidVersion, Version));
                }
                packArgs.Version = version.ToNormalizedString();
            }

            PackCommandRunner packCommandRunner = new PackCommandRunner(packArgs, ProjectFactory.ProjectCreator);

            packCommandRunner.BuildPackage();
        }