NuGet.Commands.ProjectFactory.CreateBuilder C# (CSharp) Method

CreateBuilder() private method

private CreateBuilder ( string basePath ) : PackageBuilder
basePath string
return PackageBuilder
        public PackageBuilder CreateBuilder(string basePath)
        {
            BuildProject();

            Logger.Log(MessageLevel.Info, NuGetResources.PackagingFilesFromOutputPath, Path.GetDirectoryName(TargetPath));

            var builder = new PackageBuilder();

            try
            {
                // Populate the package builder with initial metadata from the assembly/exe
                AssemblyMetadataExtractor.ExtractMetadata(builder, TargetPath);
            }
            catch
            {
                Logger.Log(MessageLevel.Warning, NuGetResources.UnableToExtractAssemblyMetadata, Path.GetFileName(TargetPath));
                ExtractMetadataFromProject(builder);
            }

            // Set the properties that were resolved from the assembly/project so they can be 
            // resolved by name if the nuspec contains tokens
            _properties.Clear();
            _properties.Add("Id", builder.Id);
            _properties.Add("Version", builder.Version.ToString());

            if (!String.IsNullOrEmpty(builder.Title))
            {
                _properties.Add("Title", builder.Title);
            }

            if (!String.IsNullOrEmpty(builder.Description))
            {
                _properties.Add("Description", builder.Description);
            }

            string projectAuthor = builder.Authors.FirstOrDefault();
            if (!String.IsNullOrEmpty(projectAuthor))
            {
                _properties.Add("Author", projectAuthor);
            }

            // If the package contains a nuspec file then use it for metadata
            Manifest manifest = ProcessNuspec(builder, basePath);

            // Remove the extra author
            if (builder.Authors.Count > 1)
            {
                builder.Authors.Remove(projectAuthor);
            }

            // Add output files
            AddOutputFiles(builder);

            // if there is a .nuspec file, only add content files if the <files /> element is not empty.
            if (manifest == null || manifest.Files == null || manifest.Files.Count > 0)
            {
                // Add content files
                AddFiles(builder, ContentItemType, ContentFolder);
            }

            // Add sources if this is a symbol package
            if (IncludeSymbols)
            {
                AddFiles(builder, SourcesItemType, SourcesFolder);
            }

            ProcessDependencies(builder);

            // Set defaults if some required fields are missing
            if (String.IsNullOrEmpty(builder.Description))
            {
                builder.Description = "Description";
                Logger.Log(MessageLevel.Warning, NuGetResources.Warning_UnspecifiedField, "Description", "Description");
            }

            if (!builder.Authors.Any())
            {
                builder.Authors.Add(Environment.UserName);
                Logger.Log(MessageLevel.Warning, NuGetResources.Warning_UnspecifiedField, "Author", Environment.UserName);
            }

            return builder;
        }

Usage Example

Exemplo n.º 1
0
        private IPackage BuildFromProjectFile(string path)
        {
            var factory = new ProjectFactory(path, Properties)
            {
                IsTool = Tool,
                Logger = Console,
                Build = Build,
            };

            // Create a builder for the main package as well as the sources/symbols package
            PackageBuilder mainPackageBuilder = factory.CreateBuilder(BasePath);

            // Build the main package
            IPackage package = BuildPackage(mainPackageBuilder);

            // If we're excluding symbols then do nothing else
            if (!Symbols)
            {
                return package;
            }

            Console.WriteLine();
            Console.WriteLine(NuGetResources.PackageCommandAttemptingToBuildSymbolsPackage, Path.GetFileName(path));

            factory.IncludeSymbols = true;
            PackageBuilder symbolsBuilder = factory.CreateBuilder(BasePath);
            symbolsBuilder.Version = mainPackageBuilder.Version;

            // Get the file name for the sources package and build it
            string outputPath = GetOutputPath(symbolsBuilder, symbols: true);
            BuildPackage(symbolsBuilder, outputPath);

            // this is the real package, not the symbol package
            return package;
        }
All Usage Examples Of NuGet.Commands.ProjectFactory::CreateBuilder