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


C# NuGet.PackageBuilder类代码示例

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


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

示例1: Pack

        public static Response Pack(NuGetPackRequest request)
        {
            var console = new Console();
            PackageBuilder builder = new PackageBuilder();
            var command = new PackCommand
            {
                BasePath = PathTools.OptimizePath(request.BaseDirectory),
                OutputDirectory = PathTools.OptimizePath(request.OutputDirectory),
                Version = request.Version,
                Console = console,
                Verbosity = Verbosity.Detailed,
                Rules = new IPackageRule[0],
            };
            command.Arguments.Add(request.SpecPath);

            try
            {
                command.Execute();
            }
            catch (Exception e)
            {
                console.WriteError(e);
            }

            return new Response(console.Messages);
        }
开发者ID:penartur,项目名称:micro-build-server,代码行数:26,代码来源:NuGetter.cs

示例2: SavePackage

        public static void SavePackage(IPackageMetadata packageMetadata, IEnumerable<IPackageFile> files, string targetFilePath, bool useTempFile)
        {
            var builder = new PackageBuilder();
            // set metadata
            CopyMetadata(packageMetadata, builder);
            // add files
            builder.Files.AddRange(files);

            // create package in the temprary file first in case the operation fails which would
            // override existing file with a 0-byte file.
            string fileNameToUse = useTempFile ? Path.GetTempFileName() : targetFilePath;
            try {
                using (Stream stream = File.Create(fileNameToUse)) {
                    builder.Save(stream);
                }

                if (useTempFile) {
                    File.Copy(fileNameToUse, targetFilePath, true);
                }
            }
            finally {
                try {
                    if (useTempFile && File.Exists(fileNameToUse)) {
                        File.Delete(fileNameToUse);
                    }
                }
                catch {
                    // don't care if this fails
                }
            }
        }
开发者ID:jacksonh,项目名称:nuget,代码行数:31,代码来源:PackageHelper.cs

示例3: CreateNugetPackage

        protected virtual void CreateNugetPackage([Diagnostics.NotNull] string tempDirectory, [Diagnostics.NotNull] string fileName, [Diagnostics.NotNull] string sourceFileName)
        {
            var packageId = Path.GetFileNameWithoutExtension(fileName);

            var sb = new StringBuilder();
            sb.AppendLine("<?xml version=\"1.0\"?>");
            sb.AppendLine("<package xmlns=\"http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd\">");
            sb.AppendLine("    <metadata>");
            sb.AppendLine("        <id>" + packageId + "</id>");
            sb.AppendLine("        <title>" + packageId + "</title>");
            sb.AppendLine("        <version>1.0.0</version>");
            sb.AppendLine("        <authors>Sitecore Pathfinder</authors>");
            sb.AppendLine("        <requireLicenseAcceptance>false</requireLicenseAcceptance>");
            sb.AppendLine("        <description>Generated by Sitecore Pathfinder</description>");
            sb.AppendLine("    </metadata>");
            sb.AppendLine("    <files>");
            sb.AppendLine("        <file src=\"" + sourceFileName + "\" target=\"content\\sitecore.project\\exports.xml\" />");
            sb.AppendLine("    </files>");
            sb.AppendLine("</package>");

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString())))
            {
                var packageBuilder = new PackageBuilder(stream, tempDirectory);

                using (var nupkg = new FileStream(fileName, FileMode.Create))
                {
                    packageBuilder.Save(nupkg);
                }
            }
        }
开发者ID:dmositecore,项目名称:Sitecore.Pathfinder,代码行数:30,代码来源:WriteWebsiteExports.cs

示例4: 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

示例5: BuildPackage

        public bool BuildPackage(IEnumerable<ProjectContext> contexts, List<DiagnosticMessage> packDiagnostics)
        {

            Reporter.Output.WriteLine($"Producing nuget package \"{GetPackageName()}\" for {Project.Name}");

            PackageBuilder = CreatePackageBuilder(Project);

            // TODO: Report errors for required fields
            // id
            // author
            // description
            foreach (var context in contexts)
            {
                Reporter.Verbose.WriteLine($"Processing {context.TargetFramework.ToString().Yellow()}");
                ProcessContext(context);
                Reporter.Verbose.WriteLine("");
            }

            var packageOutputPath = Path.Combine(
                ArtifactPathsCalculator.PackageOutputPath,
                Configuration,
                GetPackageName() + NuGet.Constants.PackageExtension);

            if (GeneratePackage(packageOutputPath, packDiagnostics))
            {
                return true;
            }

            return false;
        }
开发者ID:xier2012,项目名称:cli,代码行数:30,代码来源:PackageGenerator.cs

示例6: BuildNuGetPackage

 public void BuildNuGetPackage(NuGetPackSpecification packConfiguration)
 {
     var packageBuilder = new PackageBuilder(packConfiguration.NuSpec, NullPropertyProvider.Instance, true);
     var packagePath = Path.Combine(packConfiguration.OutputDirectory, GetDefaultPackagePath(packageBuilder));
     var packageStream = File.Create(packagePath);
     packageBuilder.Save(packageStream);
 }
开发者ID:tleviathan,项目名称:Shovel,代码行数:7,代码来源:NuGetPackageBuilder.cs

示例7: BuildPackage

 public static IPackage BuildPackage(IPackageMetadata metadata, IEnumerable<IPackageFile> files)
 {
     var builder = new PackageBuilder();
     CopyMetadata(metadata, builder);
     builder.Files.AddRange(files);
     return builder.Build();
 }
开发者ID:NuGetPackageExplorer,项目名称:NuGetPackageExplorer,代码行数:7,代码来源:PackageHelper.cs

示例8: Create

        public static Manifest Create(PackageBuilder copy)
        {
            var metadata = new ManifestMetadata();
            metadata.Id = copy.Id?.Trim();
            metadata.Version = copy.Version;
            metadata.Title = copy.Title?.Trim();
            metadata.Authors = copy.Authors.Distinct();
            metadata.Owners = copy.Owners.Distinct();
            metadata.Tags = string.Join(",", copy.Tags).Trim();
            metadata.LicenseUrl = copy.LicenseUrl;
            metadata.ProjectUrl = copy.ProjectUrl;
            metadata.IconUrl = copy.IconUrl;
            metadata.RequireLicenseAcceptance = copy.RequireLicenseAcceptance;
            metadata.Description = copy.Description?.Trim();
            metadata.Copyright = copy.Copyright?.Trim();
            metadata.Summary = copy.Summary?.Trim();
            metadata.ReleaseNotes = copy.ReleaseNotes?.Trim();
            metadata.Language = copy.Language?.Trim();
            metadata.DependencySets = copy.DependencySets;
            metadata.FrameworkAssemblies = copy.FrameworkAssemblies;
            metadata.PackageAssemblyReferences = copy.PackageAssemblyReferences;
            metadata.MinClientVersionString = copy.MinClientVersion?.ToString();

            return new Manifest(metadata);
        }
开发者ID:yonglehou,项目名称:cli-1,代码行数:25,代码来源:Manifest.cs

示例9: CreateTestPackage

        /// <summary>
        /// Creates a test package. - Take from NuGet.Core.Tests
        /// </summary>
        /// <param name="packageId">The id of the created package.</param>
        /// <param name="version">The version of the created package.</param>
        /// <param name="path">The directory where the package is created.</param>
        /// <returns>The full path of the created package file.</returns>
        public static string CreateTestPackage(string packageId, string version, string path, Uri licenseUrl = null)
        {
            var packageBuilder = new PackageBuilder
            {
                Id = packageId,
                Version = new SemanticVersion(version)
            };
            packageBuilder.Description = string.Format(
                CultureInfo.InvariantCulture,
                "desc of {0} {1}",
                packageId, version);

            if (licenseUrl != null)
            {
                packageBuilder.LicenseUrl = licenseUrl;
            }

            packageBuilder.Files.Add(CreatePackageFile(@"content\test1.txt"));
            packageBuilder.Authors.Add("test author");

            var packageFileName = string.Format("{0}.{1}.nupkg", packageId, version);
            var packageFileFullPath = Path.Combine(path, packageFileName);
            using (var fileStream = File.Create(packageFileFullPath))
            {
                packageBuilder.Save(fileStream);
            }

            return packageFileFullPath;
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:36,代码来源:Util.cs

示例10: AddLibs

        public void AddLibs(PackageBuilder packageBuilder, string pattern, bool recursiveSearch)
        {
            // Look for .dll,.xml files in top directory
            var searchOption = SearchOption.TopDirectoryOnly;
            if (recursiveSearch)
            {
                //for .resources.dll, search all directories
                searchOption = SearchOption.AllDirectories;
            }
            // Add everything in the output folder to the lib path
            foreach (var path in Directory.EnumerateFiles(_outputPath, pattern, searchOption))
            {
                var targetPath = Path.Combine("lib", _targetFrameworkFolder, Path.GetFileName(path));
                if (!Path.GetDirectoryName(path).Equals(_outputPath))
                {
                    string folderName = PathUtility.GetDirectoryName(Path.GetDirectoryName(path));
                    targetPath = Path.Combine("lib", _targetFrameworkFolder, folderName, Path.GetFileName(path));
                }

                packageBuilder.Files.Add(new PhysicalPackageFile
                {
                    SourcePath = path,
                    TargetPath = targetPath
                });
            }
        }
开发者ID:rajeevkb,项目名称:dnx,代码行数:26,代码来源:BuildContext.cs

示例11: 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

示例12: ParametersOverrideModuleSpecFile

        public void ParametersOverrideModuleSpecFile()
        {
            // Arrange
            Mock<ExportModuleCommand> mockCmd = new Mock<ExportModuleCommand>() { CallBase = true };
            mockCmd.Object.Description = "Override";
            mockCmd.Object.PackageId = "Override";
            mockCmd.Object.Version = new SemanticVersion(2, 0, 0, 0);
            mockCmd.Object.Authors = new string[] { "Over", "Ride" };
            mockCmd.Object.Copyright = "Override";
            mockCmd.Object.IconUrl = "http://over.ride";
            mockCmd.Object.Language = "ovr-RIDE";
            mockCmd.Object.LicenseUrl = "http://over.ride";
            mockCmd.Object.Owners = new string[] { "Over", "Ride" };
            mockCmd.Object.ProjectUrl = "http://over.ride";
            mockCmd.Object.ReleaseNotes = "Override";
            mockCmd.Object.RequireLicenseAcceptance = SwitchParameter.Present;
            mockCmd.Object.Summary = "Override";
            mockCmd.Object.Tags = new string[] { "Over", "Ride" };
            mockCmd.Object.Title = "Override";

            PackageBuilder expected = new PackageBuilder()
            {
                Id = "Original",
                Description = "Original",
                Version = new SemanticVersion(1, 0, 0, 0)
            };

            Mock<IFileSystem> mockFs = new Mock<IFileSystem>();
            mockFs.Setup(fs => fs.FileExists("Original.nuspec")).Returns(true);
            mockFs.Setup(fs => fs.GetAllFiles()).Returns(new string[0]);
            mockFs.Setup(fs => fs.OpenFile(It.IsAny<string>())).Returns(Stream.Null);
            mockCmd.Setup(c => c.OpenManifest(@"D:\Foo", Stream.Null)).Returns(expected);
            IModuleMetadata module = new SimpleModuleMetadata("Original", new Version(1, 0, 0, 0))
            {
                ModuleBase = @"D:\Foo"
            };

            // Act
            PackageBuilder actual = mockCmd.Object.BuildManifest(module, mockFs.Object);

            // Assert
            Assert.Equal("Override", actual.Description);
            Assert.Equal("Override", actual.Id);
            Assert.Equal(new SemanticVersion(2, 0, 0, 0), actual.Version);
            Assert.Equal(new string[] { "Over", "Ride" }, actual.Authors.ToArray());
            Assert.Equal("Override", actual.Copyright);
            Assert.Equal("http://over.ride/", actual.IconUrl.ToString());
            Assert.Equal("ovr-RIDE", actual.Language);
            Assert.Equal("http://over.ride/", actual.LicenseUrl.ToString());
            Assert.Equal(new string[] { "Over", "Ride" }, actual.Owners.ToArray());
            Assert.Equal("http://over.ride/", actual.ProjectUrl.ToString());
            Assert.Equal("Override", actual.ReleaseNotes);
            Assert.True(actual.RequireLicenseAcceptance);
            Assert.Equal("Override", actual.Summary);
            Assert.Equal(new string[] { "Over", "Ride" }, actual.Tags.ToArray());
            Assert.Equal("Override", actual.Title);
        }
开发者ID:anurse,项目名称:PS-Get,代码行数:57,代码来源:ExportModuleCommandFacts.cs

示例13: 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

示例14: PopulateDependencies

        public static void PopulateDependencies(ProjectContext context, PackageBuilder packageBuilder)
        {
            var dependencies = new List<PackageDependency>();
            var project = context.RootProject;

            foreach (var dependency in project.Dependencies)
            {
                if (!dependency.HasFlag(LibraryDependencyTypeFlag.BecomesNupkgDependency))
                {
                    continue;
                }

                // TODO: Efficiency
                var dependencyDescription = context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency));

                // REVIEW: Can we get this far with unresolved dependencies
                if (dependencyDescription == null || !dependencyDescription.Resolved)
                {
                    continue;
                }

                if (dependencyDescription.Identity.Type == LibraryType.Project &&
                    ((ProjectDescription)dependencyDescription).Project.EmbedInteropTypes)
                {
                    continue;
                }

                if (dependency.Target == LibraryType.ReferenceAssembly)
                {
                    packageBuilder.FrameworkAssemblies.Add(new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework }));

                    Reporter.Verbose.WriteLine($"Adding framework assembly {dependency.Name.Yellow()}");
                }
                else
                {
                    VersionRange dependencyVersion = null;

                    if (dependency.VersionRange == null ||
                        dependency.VersionRange.IsFloating)
                    {
                        dependencyVersion = new VersionRange(dependencyDescription.Identity.Version);
                    }
                    else
                    {
                        dependencyVersion = dependency.VersionRange;
                    }

                    Reporter.Verbose.WriteLine($"Adding dependency {dependency.Name.Yellow()} {VersionUtility.RenderVersion(dependencyVersion).Yellow()}");

                    dependencies.Add(new PackageDependency(dependency.Name, dependencyVersion));
                }
            }

            packageBuilder.DependencySets.Add(new PackageDependencySet(context.TargetFramework, dependencies));
        }
开发者ID:niemyjski,项目名称:cli,代码行数:55,代码来源:Program.cs

示例15: AddLibs

 public void AddLibs(PackageBuilder packageBuilder, string pattern)
 {
     // Add everything in the output folder to the lib path
     foreach (var path in Directory.EnumerateFiles(_outputPath, pattern))
     {
         packageBuilder.Files.Add(new PhysicalPackageFile
         {
             SourcePath = path,
             TargetPath = Path.Combine("lib", _targetFrameworkFolder, Path.GetFileName(path))
         });
     }
 }
开发者ID:noahfalk,项目名称:dnx,代码行数:12,代码来源:BuildContext.cs


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