예제 #1
0
 public PackCommandRunner(PackArgs packArgs, CreateProjectFactory createProjectFactory)
 {
     this._createProjectFactory = createProjectFactory;
     this._packArgs             = packArgs;
     Rules = DefaultPackageRuleSet.Rules;
     GenerateNugetPackage = true;
 }
예제 #2
0
        // Gets the full path of the resulting nuget package including the file name
        public static string GetOutputPath(PackageBuilder builder, PackArgs packArgs, bool symbols = false, NuGetVersion nugetVersion = null, string outputDirectory = null, bool isNupkg = true)
        {
            string version;

            if (nugetVersion != null)
            {
                version = nugetVersion.ToNormalizedString();
            }
            else
            {
                if (String.IsNullOrEmpty(packArgs.Version))
                {
                    if (builder.Version == null)
                    {
                        // If the version is null, the user will get an error later saying that a version
                        // is required. Specifying a version here just keeps it from throwing until
                        // it gets to the better error message. It won't actually get used.
                        version = "1.0.0";
                    }
                    else
                    {
                        version = builder.Version.ToNormalizedString();
                    }
                }
                else
                {
                    version = packArgs.Version;
                }
            }

            // Output file is {id}.{version}
            string outputFile = builder.Id + "." + version;

            string extension        = isNupkg ? NuGetConstants.PackageExtension : NuGetConstants.ManifestExtension;
            string symbolsExtension = isNupkg
                ? NuGetConstants.SymbolsExtension
                : NuGetConstants.ManifestSymbolsExtension;

            // If this is a source package then add .symbols.nupkg to the package file name
            if (symbols)
            {
                outputFile += symbolsExtension;
            }
            else
            {
                outputFile += extension;
            }

            string finalOutputDirectory = packArgs.OutputDirectory ?? packArgs.CurrentDirectory;

            finalOutputDirectory = outputDirectory ?? finalOutputDirectory;
            return(Path.Combine(finalOutputDirectory, outputFile));
        }
 public static IProjectFactory ProjectCreator(PackArgs packArgs, string path)
 {
     return(new MSBuildProjectFactory()
     {
         PackArgs = packArgs,
         IsTool = packArgs.Tool,
         Logger = packArgs.Logger,
         MachineWideSettings = packArgs.MachineWideSettings,
         Build = false,
         PackTargetArgs = packArgs.PackTargetArgs,
         Files = new HashSet <ManifestFile>()
     });
 }
예제 #4
0
        internal static string GetInputFile(PackArgs packArgs, IEnumerable <string> files)
        {
            if (files.Count() == 1 && Directory.Exists(files.First()))
            {
                string first = files.First();
                files = Directory.GetFiles(first);
            }

            var    candidates = files.Where(file => _allowedExtensions.Contains(Path.GetExtension(file))).ToList();
            string result;

            candidates.RemoveAll(ext => ext.EndsWith(".lock.json", StringComparison.OrdinalIgnoreCase) ||
                                 (ext.EndsWith(".json", StringComparison.OrdinalIgnoreCase) &&
                                  !Path.GetFileName(ext).Equals(ProjectJsonPathUtilities.ProjectConfigFileName, StringComparison.OrdinalIgnoreCase) &&
                                  !ext.EndsWith(ProjectJsonPathUtilities.ProjectConfigFileEnding, StringComparison.OrdinalIgnoreCase)));

            if (!candidates.Any())
            {
                throw new ArgumentException(Strings.InputFileNotSpecified);
            }
            if (candidates.Count == 1)
            {
                result = candidates[0];
            }
            else
            {
                // Remove all nuspec files
                candidates.RemoveAll(file => Path.GetExtension(file).Equals(NuGetConstants.ManifestExtension, StringComparison.OrdinalIgnoreCase));
                if (candidates.Count == 1)
                {
                    result = candidates[0];
                }
                else
                {
                    // Remove all json files
                    candidates.RemoveAll(file => Path.GetExtension(file).Equals(".json", StringComparison.OrdinalIgnoreCase));
                    if (candidates.Count == 1)
                    {
                        result = candidates[0];
                    }
                    else
                    {
                        throw new ArgumentException(Strings.InputFileNotSpecified);
                    }
                }
            }

            return(Path.Combine(packArgs.CurrentDirectory, result));
        }
        public static void SetupCurrentDirectory(PackArgs packArgs)
        {
            string directory = Path.GetDirectoryName(packArgs.Path);

            if (!directory.Equals(packArgs.CurrentDirectory, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(packArgs.OutputDirectory))
                {
                    packArgs.OutputDirectory = packArgs.CurrentDirectory;
                }

                packArgs.CurrentDirectory = directory;
                Directory.SetCurrentDirectory(packArgs.CurrentDirectory);
            }
        }
예제 #6
0
        public static void SetupCurrentDirectory(PackArgs packArgs)
        {
            string directory = Path.GetDirectoryName(packArgs.Path);

            if (!directory.Equals(packArgs.CurrentDirectory, StringComparison.OrdinalIgnoreCase))
            {
                if (string.IsNullOrEmpty(packArgs.OutputDirectory))
                {
                    packArgs.OutputDirectory = packArgs.CurrentDirectory;
                }
                packArgs.OutputDirectory = Path.GetFullPath(packArgs.OutputDirectory);

                if (!string.IsNullOrEmpty(packArgs.BasePath))
                {
                    // Make sure base path is not relative before changing the current directory
                    packArgs.BasePath = Path.GetFullPath(packArgs.BasePath);
                }

                packArgs.CurrentDirectory = directory;
                Directory.SetCurrentDirectory(packArgs.CurrentDirectory);
            }
        }
예제 #7
0
        // Gets the full path of the resulting nuget package including the file name
        public static string GetOutputPath(PackageBuilder builder, PackArgs packArgs, bool symbols = false, NuGetVersion nugetVersion = null, string outputDirectory = null, bool isNupkg = true)
        {
            NuGetVersion versionToUse;

            if (nugetVersion != null)
            {
                versionToUse = nugetVersion;
            }
            else
            {
                if (string.IsNullOrEmpty(packArgs.Version))
                {
                    if (builder.Version == null)
                    {
                        // If the version is null, the user will get an error later saying that a version
                        // is required. Specifying a version here just keeps it from throwing until
                        // it gets to the better error message. It won't actually get used.
                        versionToUse = NuGetVersion.Parse("1.0.0");
                    }
                    else
                    {
                        versionToUse = builder.Version;
                    }
                }
                else
                {
                    versionToUse = NuGetVersion.Parse(packArgs.Version);
                }
            }

            var outputFile = GetOutputFileName(builder.Id, versionToUse, isNupkg: isNupkg, symbols: symbols);


            var finalOutputDirectory = packArgs.OutputDirectory ?? packArgs.CurrentDirectory;

            finalOutputDirectory = outputDirectory ?? finalOutputDirectory;
            return(Path.Combine(finalOutputDirectory, outputFile));
        }
예제 #8
0
 public PackCommandRunner(PackArgs packArgs, CreateProjectFactory createProjectFactory, PackageBuilder packageBuilder) : this(packArgs, createProjectFactory)
 {
     this._packageBuilder = packageBuilder;
 }
예제 #9
0
        public static string GetInputFile(PackArgs packArgs)
        {
            IEnumerable <string> files = packArgs.Arguments != null && packArgs.Arguments.Any() ? packArgs.Arguments : Directory.GetFiles(packArgs.CurrentDirectory);

            return(GetInputFile(packArgs, files));
        }