コード例 #1
0
ファイル: MockPackageSpec.cs プロジェクト: kazuyabr/duality
        /// <summary>
        /// Creates a NuGet package from this mock package spec and copies it into the
        /// specified repository path.
        /// </summary>
        /// <param name="buildPath"></param>
        /// <param name="repositoryPath"></param>
        public void CreatePackage(string buildPath, string repositoryPath)
        {
            NuGet.PackageBuilder   builder  = new NuGet.PackageBuilder();
            NuGet.ManifestMetadata metadata = new NuGet.ManifestMetadata
            {
                Authors        = "AdamsLair",
                Version        = this.name.Version.ToString(),
                Id             = this.name.Id,
                Description    = string.Format("Mock Package: {0} {1}", this.name.Id, this.name.Version),
                Tags           = string.Join(" ", this.tags),
                DependencySets = new List <NuGet.ManifestDependencySet>
                {
                    new NuGet.ManifestDependencySet
                    {
                        TargetFramework = "net45",
                        Dependencies    = this.dependencies
                                          .Select(item => new NuGet.ManifestDependency {
                            Id = item.Id, Version = item.Version.ToString()
                        })
                                          .ToList()
                    }
                }
            };

            // Set up file contents metadata for the package
            List <NuGet.ManifestFile> fileMetadata = new List <NuGet.ManifestFile>();

            foreach (var pair in this.files)
            {
                fileMetadata.Add(new NuGet.ManifestFile {
                    Source = pair.Key, Target = pair.Value
                });
                this.CreateFile(buildPath, pair.Key);
            }

            // If we don't have files or dependencies, at least at one mock file so we
            // can create a package at all. This is useful for test cases where we're
            // not actually interested in package contents at all.
            if (this.files.Count == 0 && this.dependencies.Count == 0)
            {
                fileMetadata.Add(new NuGet.ManifestFile {
                    Source = "Empty.dll", Target = "lib"
                });
                this.CreateFile(buildPath, "Empty.dll");
            }

            builder.PopulateFiles(buildPath, fileMetadata);
            builder.Populate(metadata);

            string packageFileName = Path.Combine(
                repositoryPath,
                string.Format("{0}.{1}.nupkg", this.name.Id, this.name.Version));

            using (FileStream stream = File.Open(packageFileName, FileMode.Create))
            {
                builder.Save(stream);
            }
        }
コード例 #2
0
ファイル: PackageArchive.cs プロジェクト: dhootha/paradox
        private static string GetOutputPath(NuGet.PackageBuilder builder, string outputDirectory)
        {
            string version = builder.Version.ToString();

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

            outputFile += NuGet.Constants.PackageExtension;

            return(Path.Combine(outputDirectory, outputFile));
        }
コード例 #3
0
        protected override void ProcessRecordCore()
        {
            if (!SolutionManager.IsSolutionOpen)
            {
                ErrorHandler.ThrowSolutionNotOpenTerminatingError();
            }

            string projectName = ProjectName;

            // no project specified - choose default
            if (String.IsNullOrEmpty(projectName))
            {
                projectName = SolutionManager.DefaultProjectName;
            }

            // no default project? empty solution or no compatible projects found
            if (String.IsNullOrEmpty(projectName))
            {
                ErrorHandler.ThrowNoCompatibleProjectsTerminatingError();
            }

            var projectIns = SolutionManager.GetProject(projectName);

            if (projectIns == null)
            {
                ErrorHandler.WriteProjectNotFoundError(projectName, terminating: true);
            }

            string specFilePath = GetSpecFilePath(projectIns);

            var builder = new NuGet.PackageBuilder(specFilePath);

            string outputFilePath = GetTargetFilePath(projectIns, builder);

            // Remove .nuspec and .nupkg files from output package
            RemoveExludedFiles(builder);

            WriteLine(String.Format(CultureInfo.CurrentCulture, Resources.Cmdlet_CreatingPackage, outputFilePath));
            using (Stream stream = File.Create(outputFilePath)) {
                builder.Save(stream);
            }
            WriteLine(Resources.Cmdlet_PackageCreated);
        }
コード例 #4
0
        protected override void ProcessRecordCore()
        {
            if (!SolutionManager.IsSolutionOpen)
            {
                ErrorHandler.ThrowSolutionNotOpenTerminatingError();
            }

            string projectName = ProjectName;

            // no project specified - choose default
            if (String.IsNullOrEmpty(projectName))
            {
                projectName = SolutionManager.DefaultProjectName;
            }

            // no default project? empty solution or no compatible projects found
            if (String.IsNullOrEmpty(projectName))
            {
                ErrorHandler.ThrowNoCompatibleProjectsTerminatingError();
            }

            var projectIns = SolutionManager.GetProject(projectName);
            if (projectIns == null)
            {
                ErrorHandler.WriteProjectNotFoundError(projectName, terminating: true);
            }

            string specFilePath = GetSpecFilePath(projectIns);

            var builder = new NuGet.PackageBuilder(specFilePath);

            string outputFilePath = GetTargetFilePath(projectIns, builder);

            // Remove .nuspec and .nupkg files from output package 
            RemoveExludedFiles(builder);

            WriteLine(String.Format(CultureInfo.CurrentCulture, Resources.Cmdlet_CreatingPackage, outputFilePath));
            using (Stream stream = File.Create(outputFilePath))
            {
                builder.Save(stream);
            }
            WriteLine(Resources.Cmdlet_PackageCreated);
        }
コード例 #5
0
ファイル: PackageArchive.cs プロジェクト: Powerino73/paradox
        public static void Build(Package package, string outputDirectory = null)
        {
            if (package == null) throw new ArgumentNullException("package");

            var meta = new NuGet.ManifestMetadata();
            package.Meta.ToNugetManifest(meta);

            var builder = new NuGet.PackageBuilder();
            builder.Populate(meta);

            // TODO this is not working 
            var files = new List<NuGet.ManifestFile>()
                {
                    NewFile(@"Bin\**\*.exe", "Bin"),
                    NewFile(@"Bin\**\*.vsix", "Bin"),
                    NewFile(@"Bin\**\*.so", "Bin"),
                    NewFile(@"Bin\**\*.a", "Bin"),
                    NewFile(@"Bin\**\*.md", "Bin"),
                    NewFile(@"Bin\**\*.html", "Bin"),
                    NewFile(@"Bin\**\*.config", "Bin"),
                    NewFile(@"Bin\**\*.dll", "Bin"),
                    NewFile(@"Bin\**\*.xml", "Bin"),
                    NewFile(@"Bin\**\*.winmd", "Bin"),
                    NewFile(@"Targets\*.targets", "Targets"),
                };

            // Handle Assets
            var rootDir = package.RootDirectory;

            var newPackage = new Package { Meta = package.Meta };

            foreach (var profile in package.Profiles)
            {
                var target = "Assets/" + profile.Name;
                foreach (var assetFolder in profile.AssetFolders)
                {
                    // TODO: handle exclude in asset folders
                    //files.Add(NewFile(source, target, @"**\*.cs;**\*.hlsl;**\*.csproj;**\*.csproj.user;**\obj\**"));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.pdxsl", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.pdxfx", target));
                }

                var targetProfile = new PackageProfile(profile.Name);
                targetProfile.AssetFolders.Add(new AssetFolder(target));
                newPackage.Profiles.Add(targetProfile);
            }

            // Handle templates
            var targetFolder = new TemplateFolder("Templates");

            foreach (var templateFolder in package.TemplateFolders)
            {
                var source = templateFolder.Path.MakeRelative(rootDir) + "/**";
                UDirectory target = targetFolder.Path;
                if (templateFolder.Group != null)
                {
                    target = UPath.Combine(target, templateFolder.Group);
                }

                var excludeFiles = templateFolder.Exclude;
                files.Add(NewFile(source, target, excludeFiles));

                // Add template files
                foreach (var templateFile in templateFolder.Files)
                {
                    var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
                    if (templateFolder.Group != null)
                    {
                        newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
                    }

                    newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
                    targetFolder.Files.Add(newTemplateFile);
                }
            }

            // Create temp package for archive
            newPackage.TemplateFolders.Add(targetFolder);
            var newPackageFileName = "temp" + Guid.NewGuid() + ".pdxpkg";
            newPackage.FullPath = package.RootDirectory + "/" + newPackageFileName;
            var result = newPackage.Save();
            if (result.HasErrors)
            {
                throw new InvalidOperationException(result.ToText());
                // TODO throw error
            }
            files.Add(NewFile(newPackageFileName, package.Meta.Name + Package.PackageFileExtension));

            // Add files
            builder.PopulateFiles(package.RootDirectory, files);

            outputDirectory = outputDirectory ?? Environment.CurrentDirectory;

            // Save the nupkg
            var outputPath = GetOutputPath(builder,  outputDirectory);
            bool isExistingPackage = File.Exists(outputPath);
            if (isExistingPackage)
            {
                File.Delete(outputPath);
            }
            try
            {
                using (Stream stream = File.Create(outputPath))
                {
                    builder.Save(stream);
                }
            }
            catch
            {
                if (!isExistingPackage && File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                throw;
            }

            File.Delete(newPackage.FullPath);
        }
コード例 #6
0
ファイル: PackageArchive.cs プロジェクト: h78hy78yhoi8j/xenko
        public static void Build(Package package, string specialVersion = null, string outputDirectory = null)
        {
            if (package == null) throw new ArgumentNullException("package");

            var meta = new NuGet.ManifestMetadata();
            package.Meta.ToNugetManifest(meta);

            // Override version with task SpecialVersion (if specified by user)
            if (specialVersion != null)
            {
                meta.Version = new PackageVersion(package.Meta.Version.ToString().Split('-').First() + "-" + specialVersion).ToString();
            }

            var builder = new NuGet.PackageBuilder();
            builder.Populate(meta);

            var currentAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            var mainPlatformDirectory = Path.GetFileName(Path.GetDirectoryName(currentAssemblyLocation));

            // TODO this is not working 
            // We are excluding everything that is in a folder that starts with a dot (ie. .shadow, .vs)
            var files = new List<NuGet.ManifestFile>()
                {
                    NewFile(@"Bin\**\*.exe", "Bin", @"Bin\**\.*\**\*.exe"),
                    NewFile(@"Bin\**\*.vsix", "Bin", @"Bin\**\.*\**\*.vsix"),
                    NewFile(@"Bin\**\*.so", "Bin", @"Bin\**\.*\**\*.so"),
                    NewFile(@"Bin\**\*.a", "Bin", @"Bin\**\.*\**\*.a"),
                    NewFile(@"Bin\**\*.md", "Bin", @"Bin\**\.*\**\*.md"),
                    NewFile(@"Bin\**\*.html", "Bin", @"Bin\**\.*\**\*.html"),
                    NewFile(@"Bin\**\*.config", "Bin", @"Bin\**\.*\**\*.config"),
                    NewFile(@"Bin\**\*.dll", "Bin", @"Bin\**\.*\**\*.dll"),
                    NewFile(@"Bin\**\*.xml", "Bin", @"Bin\**\.*\**\*.xml"),
                    NewFile(@"Bin\**\*.usrdoc", "Bin", @"Bin\**\.*\**\*.usrdoc"),
                    NewFile(@"Bin\**\*.winmd", "Bin", @"Bin\**\.*\**\*.winmd"),
                    NewFile($@"Bin\{mainPlatformDirectory}\ios-tcprelay\*.py",$@"Bin\{mainPlatformDirectory}\ios-tcprelay"),
                    NewFile(@"Targets\*.targets", "Targets"),
                    NewFile($@"Bin\{mainPlatformDirectory}\SiliconStudio.*.pdb", $@"Bin\{mainPlatformDirectory}", @"Bin\**\SiliconStudio.Xenko.Importer*.pdb;Bin\**\SiliconStudio.Assets.Editor.pdb;Bin\**\SiliconStudio.Xenko.Assets.Presentation.pdb;Bin\**\SiliconStudio.Xenko.GameStudio*.pdb;Bin\**\SiliconStudio.Xenko.Assimp.Translation.pdb"),
                };

            // Handle Assets
            var rootDir = package.RootDirectory;

            var newPackage = new Package { Meta = package.Meta };

            foreach (var profile in package.Profiles)
            {
                var target = "Assets/" + profile.Name;
                foreach (var assetFolder in profile.AssetFolders)
                {
                    // TODO: handle exclude in asset folders
                    //files.Add(NewFile(source, target, @"**\*.cs;**\*.hlsl;**\*.csproj;**\*.csproj.user;**\obj\**"));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xksl", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfx", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfnt", target));
                }

                var targetProfile = new PackageProfile(profile.Name);
                targetProfile.AssetFolders.Add(new AssetFolder(target));
                newPackage.Profiles.Add(targetProfile);
            }

            // Handle templates
            var targetFolder = new TemplateFolder("Templates");

            foreach (var templateFolder in package.TemplateFolders)
            {
                var source = templateFolder.Path.MakeRelative(rootDir) + "/**";
                UDirectory target = targetFolder.Path;
                if (templateFolder.Group != null)
                {
                    target = UPath.Combine(target, templateFolder.Group);
                }

                var excludeFiles = templateFolder.Exclude;
                files.Add(NewFile(source, target, excludeFiles));

                // Add template files
                foreach (var templateFile in templateFolder.Files)
                {
                    var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
                    if (templateFolder.Group != null)
                    {
                        newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
                    }

                    newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
                    targetFolder.Files.Add(newTemplateFile);
                }
            }

            // Create temp package for archive
            newPackage.TemplateFolders.Add(targetFolder);
            var newPackageFileName = "temp" + Guid.NewGuid() + ".xkpkg";
            newPackage.FullPath = package.RootDirectory + "/" + newPackageFileName;
            var result = newPackage.Save();
            if (result.HasErrors)
            {
                throw new InvalidOperationException(result.ToText());
                // TODO throw error
            }
            files.Add(NewFile(newPackageFileName, package.Meta.Name + Package.PackageFileExtension));

            // Add files
            builder.PopulateFiles(package.RootDirectory, files);

            outputDirectory = outputDirectory ?? Environment.CurrentDirectory;

            // Save the nupkg
            var outputPath = GetOutputPath(builder,  outputDirectory);
            bool isExistingPackage = File.Exists(outputPath);
            if (isExistingPackage)
            {
                File.Delete(outputPath);
            }
            try
            {
                using (Stream stream = File.Create(outputPath))
                {
                    builder.Save(stream);
                }
            }
            catch
            {
                if (!isExistingPackage && File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                throw;
            }

            File.Delete(newPackage.FullPath);
        }
コード例 #7
0
ファイル: PackageArchive.cs プロジェクト: dhootha/paradox
        public static void Build(Package package, string outputDirectory = null)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var meta = new NuGet.ManifestMetadata();

            package.Meta.ToNugetManifest(meta);

            var builder = new NuGet.PackageBuilder();

            builder.Populate(meta);

            // TODO this is not working
            var files = new List <NuGet.ManifestFile>()
            {
                NewFile(@"Bin\**\*.exe", "Bin"),
                NewFile(@"Bin\**\*.vsix", "Bin"),
                NewFile(@"Bin\**\*.so", "Bin"),
                NewFile(@"Bin\**\*.a", "Bin"),
                NewFile(@"Bin\**\*.md", "Bin"),
                NewFile(@"Bin\**\*.html", "Bin"),
                NewFile(@"Bin\**\*.config", "Bin"),
                NewFile(@"Bin\**\*.dll", "Bin"),
                NewFile(@"Bin\**\*.xml", "Bin"),
                NewFile(@"Bin\**\*.winmd", "Bin"),
                NewFile(@"Targets\*.targets", "Targets"),
            };

            // Handle Assets
            var rootDir = package.RootDirectory;

            var newPackage = new Package {
                Meta = package.Meta
            };

            foreach (var profile in package.Profiles)
            {
                var target = "Assets/" + profile.Name;
                foreach (var assetFolder in profile.AssetFolders)
                {
                    // TODO: handle exclude in asset folders
                    //files.Add(NewFile(source, target, @"**\*.cs;**\*.hlsl;**\*.csproj;**\*.csproj.user;**\obj\**"));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.pdxsl", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.pdxfx", target));
                }

                var targetProfile = new PackageProfile(profile.Name);
                targetProfile.AssetFolders.Add(new AssetFolder(target));
                newPackage.Profiles.Add(targetProfile);
            }

            // Handle templates
            var targetFolder = new TemplateFolder("Templates");

            foreach (var templateFolder in package.TemplateFolders)
            {
                var        source = templateFolder.Path.MakeRelative(rootDir) + "/**";
                UDirectory target = targetFolder.Path;
                if (templateFolder.Group != null)
                {
                    target = UPath.Combine(target, templateFolder.Group);
                }

                var excludeFiles = templateFolder.Exclude;
                files.Add(NewFile(source, target, excludeFiles));

                // Add template files
                foreach (var templateFile in templateFolder.Files)
                {
                    var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
                    if (templateFolder.Group != null)
                    {
                        newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
                    }

                    newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
                    targetFolder.Files.Add(newTemplateFile);
                }
            }

            // Create temp package for archive
            newPackage.TemplateFolders.Add(targetFolder);
            var newPackageFileName = "temp" + Guid.NewGuid() + ".pdxpkg";

            newPackage.FullPath = package.RootDirectory + "/" + newPackageFileName;
            var result = newPackage.Save();

            if (result.HasErrors)
            {
                throw new InvalidOperationException(result.ToText());
                // TODO throw error
            }
            files.Add(NewFile(newPackageFileName, package.Meta.Name + Package.PackageFileExtension));

            // Add files
            builder.PopulateFiles(package.RootDirectory, files);

            outputDirectory = outputDirectory ?? Environment.CurrentDirectory;

            // Save the nupkg
            var  outputPath        = GetOutputPath(builder, outputDirectory);
            bool isExistingPackage = File.Exists(outputPath);

            if (isExistingPackage)
            {
                File.Delete(outputPath);
            }
            try
            {
                using (Stream stream = File.Create(outputPath))
                {
                    builder.Save(stream);
                }
            }
            catch
            {
                if (!isExistingPackage && File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                throw;
            }

            File.Delete(newPackage.FullPath);
        }
コード例 #8
0
ファイル: PackageArchive.cs プロジェクト: h78hy78yhoi8j/xenko
        public static void Build(Package package, string specialVersion = null, string outputDirectory = null)
        {
            if (package == null)
            {
                throw new ArgumentNullException("package");
            }

            var meta = new NuGet.ManifestMetadata();

            package.Meta.ToNugetManifest(meta);

            // Override version with task SpecialVersion (if specified by user)
            if (specialVersion != null)
            {
                meta.Version = new PackageVersion(package.Meta.Version.ToString().Split('-').First() + "-" + specialVersion).ToString();
            }

            var builder = new NuGet.PackageBuilder();

            builder.Populate(meta);

            var currentAssemblyLocation = Assembly.GetExecutingAssembly().Location;
            var mainPlatformDirectory   = Path.GetFileName(Path.GetDirectoryName(currentAssemblyLocation));

            // TODO this is not working
            // We are excluding everything that is in a folder that starts with a dot (ie. .shadow, .vs)
            var files = new List <NuGet.ManifestFile>()
            {
                NewFile(@"Bin\**\*.exe", "Bin", @"Bin\**\.*\**\*.exe"),
                NewFile(@"Bin\**\*.vsix", "Bin", @"Bin\**\.*\**\*.vsix"),
                NewFile(@"Bin\**\*.so", "Bin", @"Bin\**\.*\**\*.so"),
                NewFile(@"Bin\**\*.a", "Bin", @"Bin\**\.*\**\*.a"),
                NewFile(@"Bin\**\*.md", "Bin", @"Bin\**\.*\**\*.md"),
                NewFile(@"Bin\**\*.html", "Bin", @"Bin\**\.*\**\*.html"),
                NewFile(@"Bin\**\*.config", "Bin", @"Bin\**\.*\**\*.config"),
                NewFile(@"Bin\**\*.dll", "Bin", @"Bin\**\.*\**\*.dll"),
                NewFile(@"Bin\**\*.xml", "Bin", @"Bin\**\.*\**\*.xml"),
                NewFile(@"Bin\**\*.usrdoc", "Bin", @"Bin\**\.*\**\*.usrdoc"),
                NewFile(@"Bin\**\*.winmd", "Bin", @"Bin\**\.*\**\*.winmd"),
                NewFile($@"Bin\{mainPlatformDirectory}\ios-tcprelay\*.py", $@"Bin\{mainPlatformDirectory}\ios-tcprelay"),
                NewFile(@"Targets\*.targets", "Targets"),
                NewFile($@"Bin\{mainPlatformDirectory}\SiliconStudio.*.pdb", $@"Bin\{mainPlatformDirectory}", @"Bin\**\SiliconStudio.Xenko.Importer*.pdb;Bin\**\SiliconStudio.Assets.Editor.pdb;Bin\**\SiliconStudio.Xenko.Assets.Presentation.pdb;Bin\**\SiliconStudio.Xenko.GameStudio*.pdb;Bin\**\SiliconStudio.Xenko.Assimp.Translation.pdb"),
            };

            // Handle Assets
            var rootDir = package.RootDirectory;

            var newPackage = new Package {
                Meta = package.Meta
            };

            foreach (var profile in package.Profiles)
            {
                var target = "Assets/" + profile.Name;
                foreach (var assetFolder in profile.AssetFolders)
                {
                    // TODO: handle exclude in asset folders
                    //files.Add(NewFile(source, target, @"**\*.cs;**\*.hlsl;**\*.csproj;**\*.csproj.user;**\obj\**"));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xksl", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfx", target));
                    files.Add(NewFile(assetFolder.Path.MakeRelative(rootDir) + "/**/*.xkfnt", target));
                }

                var targetProfile = new PackageProfile(profile.Name);
                targetProfile.AssetFolders.Add(new AssetFolder(target));
                newPackage.Profiles.Add(targetProfile);
            }

            // Handle templates
            var targetFolder = new TemplateFolder("Templates");

            foreach (var templateFolder in package.TemplateFolders)
            {
                var        source = templateFolder.Path.MakeRelative(rootDir) + "/**";
                UDirectory target = targetFolder.Path;
                if (templateFolder.Group != null)
                {
                    target = UPath.Combine(target, templateFolder.Group);
                }

                var excludeFiles = templateFolder.Exclude;
                files.Add(NewFile(source, target, excludeFiles));

                // Add template files
                foreach (var templateFile in templateFolder.Files)
                {
                    var newTemplateFile = templateFile.MakeRelative(templateFolder.Path);
                    if (templateFolder.Group != null)
                    {
                        newTemplateFile = UPath.Combine(templateFolder.Group, newTemplateFile);
                    }

                    newTemplateFile = UPath.Combine(targetFolder.Path, newTemplateFile);
                    targetFolder.Files.Add(newTemplateFile);
                }
            }

            // Create temp package for archive
            newPackage.TemplateFolders.Add(targetFolder);
            var newPackageFileName = "temp" + Guid.NewGuid() + ".xkpkg";

            newPackage.FullPath = package.RootDirectory + "/" + newPackageFileName;
            var result = newPackage.Save();

            if (result.HasErrors)
            {
                throw new InvalidOperationException(result.ToText());
                // TODO throw error
            }
            files.Add(NewFile(newPackageFileName, package.Meta.Name + Package.PackageFileExtension));

            // Add files
            builder.PopulateFiles(package.RootDirectory, files);

            outputDirectory = outputDirectory ?? Environment.CurrentDirectory;

            // Save the nupkg
            var  outputPath        = GetOutputPath(builder, outputDirectory);
            bool isExistingPackage = File.Exists(outputPath);

            if (isExistingPackage)
            {
                File.Delete(outputPath);
            }
            try
            {
                using (Stream stream = File.Create(outputPath))
                {
                    builder.Save(stream);
                }
            }
            catch
            {
                if (!isExistingPackage && File.Exists(outputPath))
                {
                    File.Delete(outputPath);
                }
                throw;
            }

            File.Delete(newPackage.FullPath);
        }