当前位置: 首页>>代码示例>>C#>>正文


C# PackageBuilder.Populate方法代码示例

本文整理汇总了C#中NuGet.PackageBuilder.Populate方法的典型用法代码示例。如果您正苦于以下问题:C# PackageBuilder.Populate方法的具体用法?C# PackageBuilder.Populate怎么用?C# PackageBuilder.Populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NuGet.PackageBuilder的用法示例。


在下文中一共展示了PackageBuilder.Populate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Create NuGet Package via Code");
            ManifestMetadata metadata = new ManifestMetadata()
            {
                Authors = "Authors Name",
                Version = "1.0.0.0",
                Id = "NuGetId",
                Description = "NuGet Package Description goes here!",
            };

            PackageBuilder builder = new PackageBuilder();


            var path = AppDomain.CurrentDomain.BaseDirectory + "..\\..\\DemoContent\\";

            builder.PopulateFiles(path, new[] { new ManifestFile { Source = "**", Target = "content" } });
            builder.Populate(metadata);

            using (FileStream stream = File.Open("test.nupkg", FileMode.OpenOrCreate))
            {
                builder.Save(stream);
            }

            Console.WriteLine("... and extract NuGet Package via Code");

            NuGet.ZipPackage package = new ZipPackage("test.nupkg");
            var content = package.GetContentFiles();

            Console.WriteLine("Package Id: " + package.Id);
            Console.WriteLine("Content-Files-Count: " + content.Count());

            Console.ReadLine();
        }
开发者ID:ledgarl,项目名称:Samples,代码行数:34,代码来源:Program.cs

示例2: BuildPackage

 public void BuildPackage(string baseUrl, ManifestMetadata metadata, ManifestFile[] files)
 {
     NuGet.PackageBuilder packageBuilder = new NuGet.PackageBuilder();
     packageBuilder.Populate(metadata);
     packageBuilder.PopulateFiles(baseUrl, files);
     var saveDir = Path.Combine(DEFAULT_PACKAGES_SAVE_PATH, packageBuilder.Id, packageBuilder.Version.ToString().Replace('.', '_'));
     Directory.CreateDirectory(saveDir);
     var saveStream = File.Create(Path.Combine(saveDir, packageBuilder.Id + ".nupkg"));
     packageBuilder.Save(saveStream);
 }
开发者ID:MichaelSL,项目名称:nugetbuilder,代码行数:10,代码来源:PackageBuilder.cs

示例3: BuildPackage

        public void BuildPackage(string basePath, IList<string> includes, ManifestMetadata metadata, string outFolder, bool overwrite)
        {
            var package = new PackageBuilder();

            package.PopulateFiles(basePath, includes.Select(i => new ManifestFile { Source = i }));
            package.Populate(metadata);

            var filename = metadata.Id + "." + metadata.Version + ".nupkg";
            var output = Path.Combine(outFolder, filename);

            if (fileSystem.FileExists(output) && !overwrite)
                throw new CommandException("The package file already exists and --overwrite was not specified");

            log.InfoFormat("Saving {0} to {1}...", filename, outFolder);

            fileSystem.EnsureDirectoryExists(outFolder);

            using (var outStream = fileSystem.OpenFile(output, FileMode.Create))
                package.Save(outStream);
        }
开发者ID:rodrickyu,项目名称:Octopus-Tools,代码行数:20,代码来源:NuGetPackageBuilder.cs

示例4: ManifestMetadata

        IPackage IPackageFactory.CreateFromProject(string nupecFile, string csprojFile, string buildConfiguration, bool includeBinOutput)
        {
            var projectReader = _projectReaderFactory.Create(csprojFile);
            var binDir = projectReader.GetBinPath(buildConfiguration);
            var assemblyName = projectReader.GetAssemblyName();
            var assemblyPath = _fileSystem.CombinePaths(binDir, assemblyName);
            var assemblyReader = _assemblyReaderFactory.Create(assemblyPath);

            var manifest = new ManifestMetadata()
            {
                Id = assemblyReader.GetPackageId(),
                Title = assemblyReader.GetPackageTitle(),
                Owners = assemblyReader.GetCompany(),
                Authors = assemblyReader.GetCompany(),
                Description = assemblyReader.GetDescription(),
                Copyright = assemblyReader.GetCopyright(),
                Version = assemblyReader.GetFileVersion()
            };

            var files = new List<ManifestFile>();
            foreach (var dll in _fileSystem.FindFiles(binDir, "*.dll", false))
                files.Add(new ManifestFile() { Source = dll, Target = @"lib\net40" });

            var packageBuilder = new PackageBuilder();
            packageBuilder.Populate(manifest);
            packageBuilder.PopulateFiles(string.Empty, files);

            var projDir = _fileSystem.GetDirectory(csprojFile);
            var packagefile = _fileSystem.CombinePaths(projDir, "packages.config");

            var packagePath = _fileSystem.ChangeFileExtension(csprojFile, "nupkg");
            using (var stream = _fileSystem.OpenWrite(packagePath))
            {
                packageBuilder.Save(stream);
            }

            return new ZipPackage(packagePath);
        }
开发者ID:run00,项目名称:TeamCity,代码行数:38,代码来源:PackageFactory.cs

示例5: AddPackage

        private IPackage AddPackage(IPackageManager manager, string id, string version, string payloadAssemblyFilePath, params IPackage[] dependencies)
        {
            PackageBuilder builder = new PackageBuilder();

            ManifestMetadata metadata = new ManifestMetadata()
            {
                Authors = "dummy author 1,dummy author 2",
                Owners = "dummy owner 1,dummy owner 2",
                Title = "dummy title",
                Version = new SemanticVersion(version).ToString(),
                Id = id,
                Description = "dummy description",
                LicenseUrl = "http://my.license/readme.txt",
                ProjectUrl = "http://dummyurl/"
            };

            List<ManifestDependency> dependencyList = new List<ManifestDependency>();
            foreach (IPackage dependencyNode in dependencies)
            {
                dependencyList.Add(new ManifestDependency()
                {
                    Id = dependencyNode.Id,
                    Version = dependencyNode.Version.ToString(),
                });
            }

            List<ManifestDependencySet> dependencySetList = new List<ManifestDependencySet>()
            {
                new ManifestDependencySet()
                {
                    Dependencies = dependencyList
                }
            };
            metadata.DependencySets = dependencySetList;

            builder.Populate(metadata);

            PhysicalPackageFile file = new PhysicalPackageFile();
            file.SourcePath = payloadAssemblyFilePath;
            file.TargetPath = "analyzers/" + Path.GetFileName(payloadAssemblyFilePath);
            builder.Files.Add(file);

            using (MemoryStream stream = new MemoryStream())
            {
                builder.Save(stream);
                stream.Position = 0;

                ZipPackage pkg = new ZipPackage(stream);
                manager.InstallPackage(pkg, true, true);

                return pkg;
            }
        }
开发者ID:SonarSource-VisualStudio,项目名称:sonarqube-roslyn-sdk,代码行数:53,代码来源:RoslynGenTests.cs

示例6: BuildPackage

        private static void BuildPackage(string nuspecPath, bool signBinaries)
        {
            var repositoryPath = Path.GetDirectoryName(nuspecPath);
            var basePath = Path.Combine(repositoryPath, "files", Path.GetFileNameWithoutExtension(nuspecPath));
            Directory.CreateDirectory(basePath);
            
            var createdFiles = new List<string>();
            bool deleteDir = true;
            using (var fileStream = File.OpenRead(nuspecPath))
            {
                var manifest = Manifest.ReadFrom(fileStream);
                foreach (var file in manifest.Files)
                {
                    string outputPath = Path.Combine(basePath, file.Source);
                    if (File.Exists(outputPath))
                    {
                        deleteDir = false;
                        // A user created file exists. Continue to next file.
                        continue;
                    }
                    
                    createdFiles.Add(outputPath);
                    string outputDir = Path.GetDirectoryName(outputPath);
                    if (!Directory.Exists(outputDir))
                    {
                        Directory.CreateDirectory(outputDir);
                    }

                    if (file.Source.StartsWith(@"lib" + Path.DirectorySeparatorChar) && !file.Source.EndsWith("resources.dll"))
                    {
                        var name = Path.GetFileNameWithoutExtension(file.Source);
                        CreateAssembly(new PackageInfo(manifest.Metadata.Id + ":" + manifest.Metadata.Version),
                                       outputPath: outputPath);
                    }
                    else
                    {
                        File.WriteAllBytes(outputPath, new byte[0]);
                    }
                }

                var packageBuilder = new PackageBuilder();
                packageBuilder.Populate(manifest.Metadata);
                packageBuilder.PopulateFiles(basePath, manifest.Files);
                
                string nupkgDirectory = Path.GetFullPath("packages");
                Directory.CreateDirectory(nupkgDirectory);
                string nupkgPath = Path.Combine(nupkgDirectory, Path.GetFileNameWithoutExtension(nuspecPath)) + ".nupkg";
                using (var nupkgStream = File.Create(nupkgPath))
                {
                    packageBuilder.Save(nupkgStream);
                }
                
                
            }
            try
            {
                if (deleteDir)
                {
                    Directory.Delete(basePath, recursive: true);
                }
                else 
                {
                    // Delete files that we created.
                    createdFiles.ForEach(File.Delete);
                }
            }
            catch { }
        }
开发者ID:xero-github,项目名称:Nuget,代码行数:68,代码来源:Program.cs

示例7: WritePackage

        void WritePackage(PackageBuilder builder, ManifestMetadata metadata)
        {
            //Create the Nuget package
            if (!Directory.Exists(NugetRepository)) Directory.CreateDirectory(NugetRepository);

            var package = NugetRepository + metadata.Id + NugetSeparator + metadata.Version + ".nupkg";
            using (FileStream stream = File.Open(package, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read))
                {
                    builder.Populate(metadata);
                    builder.Save(stream);
                }
                Trace.TraceInformation("Package {0} created locally", package);
                
                var localRepo = PackageRepositoryFactory.Default.CreateRepository(new DirectoryInfo("./nuget-repository").FullName);
                var nuGetPackage = PackageHelper.ResolvePackage(localRepo, metadata.Id, new SemanticVersion(metadata.Version));
                var packageFile = new FileInfo(package);
                var size = packageFile.Length;
                var ps = new PackageServer(_repository, "None");
                ps.PushPackage(_credential, nuGetPackage, size, 50000, false);
               
                Trace.TraceInformation("Package {0} uploaded to {1}", package, _repository);
        }
开发者ID:Ullink,项目名称:NugetConverter,代码行数:22,代码来源:NuGetPackageCreationService.cs

示例8: CreateNugget

        private string CreateNugget()
        {
            var csproj = Path.GetFullPath(Path.Combine(ClientDirectory, "LIC.Malone.Client.Desktop.csproj"));
            var bin = Path.GetFullPath(Path.Combine(ClientDirectory, "bin", "Release"));
            var buildDirectoryInfo = Directory.CreateDirectory(BuildDirectory);

            Directory.SetCurrentDirectory(buildDirectoryInfo.FullName);

            // Clean out build directory.
            buildDirectoryInfo
                .GetFiles("*.nupkg")
                .ToList()
                .ForEach(p => p.Delete());

            // Rely on standard nuget process to build the project and create a starting package to copy metadata from.
            StartProcess("nuget.exe", string.Format("pack {0} -Build -Prop Configuration=Release", csproj));

            var nupkg = buildDirectoryInfo.GetFiles("*.nupkg").Single();
            var package = new ZipPackage(nupkg.FullName);

            // Copy all of the metadata *EXCEPT* for dependencies. Kill those.
            var manifest = new ManifestMetadata
            {
                Id = package.Id,
                Version = package.Version.ToString(),
                Authors = string.Join(", ", package.Authors),
                Copyright = package.Copyright,
                DependencySets = null,
                Description = package.Description,
                Title = package.Title,
                IconUrl = package.IconUrl.ToString(),
                ProjectUrl = package.ProjectUrl.ToString(),
                LicenseUrl = package.LicenseUrl.ToString()
            };

            const string target = @"lib\net45";

            // Include dependencies in the package.
            var files = new List<ManifestFile>
            {
                new ManifestFile { Source = "*.dll", Target = target },
                new ManifestFile { Source = "Malone.exe", Target = target },
                new ManifestFile { Source = "Malone.exe.config", Target = target },
            };

            var builder = new PackageBuilder();
            builder.Populate(manifest);
            builder.PopulateFiles(bin, files);

            var nugget = Path.Combine(buildDirectoryInfo.FullName, nupkg.Name);

            using (var stream = File.Open(nugget, FileMode.OpenOrCreate))
            {
                builder.Save(stream);
            }

            return nugget;
        }
开发者ID:Kazetsukai,项目名称:Malone,代码行数:58,代码来源:Releasifyer.cs

示例9: CreatePackage

        public IPackage CreatePackage(
            string packageId,
            string packageVersion,
            string contentFilePath,
            License requiresLicenseAccept,
            params IPackage[] dependencies)
        {
            PackageBuilder builder = new PackageBuilder();
            ManifestMetadata metadata = new ManifestMetadata()
            {
                Authors = "dummy author",
                Version = new SemanticVersion(packageVersion).ToString(),
                Id = packageId,
                Description = "dummy description",
                LicenseUrl = "http://choosealicense.com/",
                RequireLicenseAcceptance = (requiresLicenseAccept == License.Required)
            };

            List<ManifestDependency> dependencyList = new List<ManifestDependency>();
            foreach (IPackage dependencyNode in dependencies)
            {
                dependencyList.Add(new ManifestDependency()
                {
                    Id = dependencyNode.Id,
                    Version = dependencyNode.Version.ToString(),
                });
            }

            List<ManifestDependencySet> dependencySetList = new List<ManifestDependencySet>()
            {
                new ManifestDependencySet()
                {
                    Dependencies = dependencyList
                }
            };
            metadata.DependencySets = dependencySetList;

            builder.Populate(metadata);

            PhysicalPackageFile file = new PhysicalPackageFile();
            file.SourcePath = contentFilePath;
            file.TargetPath = Path.GetFileName(contentFilePath);
            builder.Files.Add(file);

            string fileName = packageId + "." + metadata.Version + ".nupkg";
            string destinationName = Path.Combine(this.manager.LocalRepository.Source, fileName);

            using (Stream fileStream = File.Open(destinationName, FileMode.OpenOrCreate))
            {
                builder.Save(fileStream);
            }

            // Retrieve and return the newly-created package
            IPackage package = this.fakeRemoteRepo.FindPackage(packageId, new SemanticVersion(packageVersion));
            Assert.IsNotNull(package, "Test setup error: failed to create and retrieve a test package");

            return package;
        }
开发者ID:AtwooTM,项目名称:sonarqube-roslyn-sdk,代码行数:58,代码来源:RemoteRepoBuilder.cs

示例10: BuildPackage

    private void BuildPackage(Manifest manifest)
    {
      var builder = new PackageBuilder();
      builder.Populate(manifest.Metadata);
      builder.PopulateFiles(_outputPath, manifest.Files);
      var file = Path.Combine(_outputPath, string.Format("{0}.{1}.nupkg", builder.Id, builder.Version));
      var localRepo = new LocalPackageRepository(_outputPath, NuspecDefinition.PackageSource);

      if (File.Exists(file))
      {
        File.Delete(file);
      }

      using (var buildFile = File.Open(file, FileMode.OpenOrCreate))
      {
        builder.Save(buildFile);
        buildFile.Flush();
        buildFile.Close();
      }
      var package = localRepo.GetPackage(builder.Id, builder.Version);

      if (NuspecDefinition.PublishPackage)
      {
        localRepo.PushPackage(package);
      }
    }
开发者ID:talisker77,项目名称:Package.Util,代码行数:26,代码来源:Creator.cs

示例11: Pack

        public void Pack(string nuspecPath, Func<string, string> nuspecPropertyProvider, bool packSymbols)
        {
            try
            {
                PackageBuilder builder = new PackageBuilder();

                using (var nuspecFile = File.Open(nuspecPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                {
                    string baseDirectoryPath = (string.IsNullOrEmpty(BaseDirectory)) ? Path.GetDirectoryName(nuspecPath) : BaseDirectory;
                    Manifest manifest = Manifest.ReadFrom(nuspecFile, nuspecPropertyProvider, false);
                    builder.Populate(manifest.Metadata);
                    builder.PopulateFiles(baseDirectoryPath, manifest.Files);

                    PathResolver.FilterPackageFiles(
                        builder.Files,
                        file => file.Path,
                        packSymbols ? SymbolPackageExcludes : LibPackageExcludes);
                }

                if (packSymbols)
                {
                    // Symbol packages are only valid if they contain both symbols and sources.
                    Dictionary<string, bool> pathHasMatches = LibPackageExcludes.ToDictionary(
                        path => path,
                        path => PathResolver.GetMatches(builder.Files, file => file.Path, new[] { path }).Any());

                    if (!pathHasMatches.Values.Any(i => i))
                    {
                        Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain symbol or source files. Not creating symbol package.");
                        return;
                    }
                    foreach (var pathPair in pathHasMatches.Where(pathMatchPair => !pathMatchPair.Value))
                    {
                        Log.LogMessage(LogImportance.Low, $"Nuspec {nuspecPath} does not contain any files matching {pathPair.Key}. Not creating symbol package.");
                        return;
                    }
                }

                // Overriding the Version from the Metadata if one gets passed in.
                if (!string.IsNullOrEmpty(PackageVersion))
                {
                    NuGetVersion overrideVersion;
                    if (NuGetVersion.TryParse(PackageVersion, out overrideVersion))
                    {
                        builder.Version = overrideVersion;
                    }
                    else
                    {
                        Log.LogError($"Failed to parse Package Version: '{PackageVersion}' is not a valid version.");
                        return;
                    }
                }

                string id = builder.Id, version = builder.Version.ToString();

                if (String.IsNullOrEmpty(id))
                {
                    Log.LogError($"Nuspec {nuspecPath} does not contain a valid Id");
                    return;
                }

                if (String.IsNullOrEmpty(version))
                {
                    Log.LogError($"Nuspec {nuspecPath} does not contain a valid version");
                    return;
                }

                string nupkgOutputDirectory = OutputDirectory;

                if (packSymbols && !string.IsNullOrEmpty(SymbolPackageOutputDirectory))
                {
                    nupkgOutputDirectory = SymbolPackageOutputDirectory;
                }

                string nupkgExtension = packSymbols ? ".symbols.nupkg" : ".nupkg";
                string nupkgPath = Path.Combine(nupkgOutputDirectory, $"{id}.{version}{nupkgExtension}");

                var directory = Path.GetDirectoryName(nupkgPath);
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                using (var fileStream = File.Create(nupkgPath))
                {
                    builder.Save(fileStream);
                }

                Log.LogMessage($"Created '{nupkgPath}'");
            }
            catch (Exception e)
            {
                string packageType = packSymbols ? "symbol" : "lib";
                Log.LogError($"Error when creating nuget {packageType} package from {nuspecPath}. {e}");
            }
        }
开发者ID:ChadNedzlek,项目名称:buildtools,代码行数:96,代码来源:NuGetPack.cs

示例12: CreatePackageBuilder

 private static PackageBuilder CreatePackageBuilder(string id, string version)
 {
     PackageBuilder builder = new PackageBuilder();
     ManifestMetadata metadata = CreateNuGetManifest(id, version);
     builder.Populate(metadata);
     return builder;
 }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:7,代码来源:AnalyzerInstallerTests.cs

示例13: CreateAndInstallPackageWithDummyContent

        /// <summary>
        /// Creates and installs a package with a single content file.
        /// Optionally sets the dependencies for the package
        /// </summary>
        private IPackage CreateAndInstallPackageWithDummyContent(LocalPackageRepository localRepo, string packageId, string packageVersion, string contentFileTargetPath, params IPackage[] dependsOn)
        {
            PackageBuilder builder = new PackageBuilder();
            ManifestMetadata metadata = CreateNuGetManifest(packageId, packageVersion);
            builder.Populate(metadata);

            if (dependsOn.Length > 0)
            {
                AddDependencySet(metadata, dependsOn);
            }

            AddDummyFile(builder, contentFileTargetPath);

            return CreateAndInstallPackage(localRepo, builder);
        }
开发者ID:BrightLight,项目名称:sonar-msbuild-runner,代码行数:19,代码来源:AnalyzerInstallerTests.cs

示例14: Execute

        public void Execute(string[] commandLineArguments)
        {
            options.Parse(commandLineArguments);

            if (string.IsNullOrWhiteSpace(id))
                throw new CommandException("An ID is required");

            if (includes.All(string.IsNullOrWhiteSpace))
                includes.Add("**");

            if (string.IsNullOrWhiteSpace(basePath))
                basePath = Path.GetFullPath(Environment.CurrentDirectory);

            if (string.IsNullOrWhiteSpace(outFolder))
                outFolder = Path.GetFullPath(Environment.CurrentDirectory);

            if (version == null)
            {
                var now = DateTime.Now;
                version = new SemanticVersion(now.Year, now.Month, now.Day, now.Hour*10000 + now.Minute*100 + now.Second);
            }
            else
            {
                // Make sure SpecialVersion has 20 characters maximum (Limit imposed by NuGet)
                // https://nuget.codeplex.com/workitem/3426

                const int nugetSpecialVersionMaxLength = 20;
                if (!string.IsNullOrWhiteSpace(version.SpecialVersion) && version.SpecialVersion.Length > nugetSpecialVersionMaxLength)
                {
                    log.WarnFormat("SpecialVersion '{0}' will be truncated to {1} characters (NuGet limit)",
                        version.SpecialVersion, nugetSpecialVersionMaxLength);

                    var specialVersion = version.SpecialVersion;
                    specialVersion = specialVersion.Substring(0, Math.Min(nugetSpecialVersionMaxLength, specialVersion.Length));

                    version = new SemanticVersion(version.Version, specialVersion);
                }
            }

            if (authors.All(string.IsNullOrWhiteSpace))
                authors.Add(Environment.UserName + "@" + Environment.UserDomainName);

            if (string.IsNullOrWhiteSpace(description))
                description = "A deployment package created from files on disk.";

            string allReleaseNotes = null;
            if (!string.IsNullOrWhiteSpace(releaseNotesFile))
            {
                if (!File.Exists(releaseNotesFile))
                    log.WarnFormat("The release notes file '{0}' could not be found", releaseNotesFile);
                else
                    allReleaseNotes = fileSystem.ReadFile(releaseNotesFile);
            }

            if (!string.IsNullOrWhiteSpace(releaseNotes))
            {
                if (allReleaseNotes != null)
                    allReleaseNotes += Environment.NewLine + releaseNotes;
                else
                    allReleaseNotes = releaseNotes;
            }

            var metadata = new ManifestMetadata
            {
                Id = id,
                Authors = string.Join(", ", authors),
                Description = description,
                Version = version.ToString(),
            };

            if (!string.IsNullOrWhiteSpace(allReleaseNotes))
                metadata.ReleaseNotes = allReleaseNotes;

            if (!string.IsNullOrWhiteSpace(title))
                metadata.Title = title;

            log.InfoFormat("Packing {0} version {1}...", id, version);

            var package = new PackageBuilder();

            package.PopulateFiles(basePath, includes.Select(i => new ManifestFile {Source = i}));
            package.Populate(metadata);

            var filename = metadata.Id + "." + metadata.Version + ".nupkg";
            var output = Path.Combine(outFolder, filename);

            if (fileSystem.FileExists(output) && !overwrite)
                throw new CommandException("The package file already exists and --overwrite was not specified");

            log.InfoFormat("Saving {0} to {1}...", filename, outFolder);

            fileSystem.EnsureDirectoryExists(outFolder);

            using (var outStream = fileSystem.OpenFile(output, FileMode.Create))
                package.Save(outStream);

            log.InfoFormat("Done.");
        }
开发者ID:cloudrifles,项目名称:Octopus-Tools,代码行数:98,代码来源:PackCommand.cs

示例15: Main

        public static void Main(string[] args)
        {
            string contentPath;
            string destinationPath;
            string packageId;
            int numberOfPackages;
            int randomFileSize;

            if (args.Length == 5)
            {
                contentPath = args[0];
                destinationPath = args[1];
                packageId = args[2];
                numberOfPackages = Int32.Parse(args[3]);
                randomFileSize = Int32.Parse(args[4]);
            }
            else
            {
                Console.WriteLine("Package content path:");
                contentPath = Console.ReadLine();
                Console.WriteLine("Package destination path:");
                destinationPath = Console.ReadLine();
                Console.WriteLine("Package id:");
                packageId = Console.ReadLine();
                Console.WriteLine("Number of packages:");
                numberOfPackages = Int32.Parse(Console.ReadLine());
                Console.WriteLine("Random file size (kb):");
                randomFileSize = Int32.Parse(Console.ReadLine());
            }

            var includes = new List<string>
            {
                "**"
            };

            for (var i = 0; i < numberOfPackages; i++)
            {
                var version = new SemanticVersion(1, i, 0, 0);
                var metadata = new ManifestMetadata
                {
                    Id = packageId,
                    Version = version.ToString(),
                    Authors = "Testing",
                    Description = "A test package"
                };

                var randomFile = Path.Combine(contentPath, "random.txt");
                GenerateRandomFile(randomFile, randomFileSize);

                var package = new PackageBuilder();

                package.PopulateFiles(contentPath, includes.Select(include =>
                    new ManifestFile { Source = include })
                );
                package.Populate(metadata);

                var filename = metadata.Id + "." + metadata.Version + ".nupkg";
                var output = Path.Combine(destinationPath, filename);

                using (var outStream = File.Open(output, FileMode.Create))
                    package.Save(outStream);
            }
        }
开发者ID:tothegills,项目名称:NuGetPackageGenerator,代码行数:63,代码来源:Program.cs


注:本文中的NuGet.PackageBuilder.Populate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。