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); }
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); }
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); }