// // ApplyReleases methods // List <string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release) { var pkg = new ZipPackage(Path.Combine(updateInfo.PackageDirectory, release.Filename)); var target = getDirectoryForRelease(release.Version); // NB: This might happen if we got killed partially through applying the release if (target.Exists) { Utility.DeleteDirectory(target.FullName).Wait(); } target.Create(); // Copy all of the files out of the lib/ dirs in the NuGet package // into our target App directory. // // NB: We sort this list in order to guarantee that if a Net20 // and a Net40 version of a DLL get shipped, we always end up // with the 4.0 version. log.Info("Writing files to app directory: {0}", target.FullName); pkg.GetLibFiles().Where(x => pathIsInFrameworkProfile(x, appFrameworkVersion)) .OrderBy(x => x.Path) .ForEach(x => CopyFileToLocation(target, x)); pkg.GetContentFiles().ForEach(x => CopyFileToLocation(target, x)); var newCurrentVersion = updateInfo.FutureReleaseEntry.Version; // Perform post-install; clean up the previous version by asking it // which shortcuts to install, and nuking them. Then, run the app's // post install and set up shortcuts. return(runPostInstallAndCleanup(newCurrentVersion, updateInfo.IsBootstrapping)); }
public void ContentFilesAreIncludedInCreatedPackage() { var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ProjectWithContent.1.0.0.0-beta.nupkg"); var outputPackage = Path.GetTempFileName() + ".nupkg"; var sourceDir = IntegrationTestHelper.GetPath("fixtures", "packages"); var fixture = new ReleasePackage(inputPackage); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); try { fixture.CreateReleasePackage(outputPackage, sourceDir); this.Log().Info("Resulting package is at {0}", outputPackage); var pkg = new ZipPackage(outputPackage); int refs = pkg.FrameworkAssemblies.Count(); this.Log().Info("Found {0} refs", refs); refs.ShouldEqual(0); this.Log().Info("Files in release package:"); var contentFiles = pkg.GetContentFiles(); Assert.Equal(2, contentFiles.Count()); var contentFilePaths = contentFiles.Select(f => f.EffectivePath); Assert.Contains("some-words.txt", contentFilePaths); Assert.Contains("dir\\item-in-subdirectory.txt", contentFilePaths); Assert.Equal(1, pkg.GetLibFiles().Count()); } finally { File.Delete(outputPackage); } }
async Task <string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release) { var pkg = new ZipPackage(Path.Combine(updateInfo.PackageDirectory, release.Filename)); var target = getDirectoryForRelease(release.Version); // NB: This might happen if we got killed partially through applying the release if (target.Exists) { this.Log().Warn("Found partially applied release folder, killing it: " + target.FullName); await Utility.DeleteDirectory(target.FullName); } target.Create(); // Copy all of the files out of the lib/ dirs in the NuGet package // into our target App directory. // // NB: We sort this list in order to guarantee that if a Net20 // and a Net40 version of a DLL get shipped, we always end up // with the 4.0 version. this.Log().Info("Writing files to app directory: {0}", target.FullName); var toWrite = pkg.GetLibFiles().Where(x => pathIsInFrameworkProfile(x, appFrameworkVersion)) .OrderBy(x => x.Path) .ToList(); // NB: Because of the above NB, we cannot use ForEachAsync here, we // have to copy these files in-order. Once we fix assembly resolution, // we can kill both of these NBs. await Task.Run(() => toWrite.ForEach(x => copyFileToLocation(target, x))); await pkg.GetContentFiles().ForEachAsync(x => copyFileToLocation(target, x)); return(target.FullName); }
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(); }
public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; ZipPackage zipPackage = new ZipPackage(packageFullPath); List <IPackageFile> files = zipPackage.GetContentFiles().ToList(); if (files == null || files.Count == 0) { outputBuilder.AppendFormat(" No content files are present in the nupkg file.Skipping content validation"); return(null); } //Get compatible items for the current project. //if no compatible items, then check if there are any files with directly under contents and get them. IEnumerable <IPackageFile> compatibleItems; VersionUtility.TryGetCompatibleItems(new FrameworkName(dteHelper.GetProjectFramework()), files, out compatibleItems); if (compatibleItems == null || compatibleItems.ToList().Count == 0) { VersionUtility.TryGetCompatibleItems(null, files, out compatibleItems); } if (compatibleItems == null || compatibleItems.ToList().Count == 0) { outputBuilder.AppendFormat(" The package doesnt have a content folder matching the current project's target framework : {0}", dteHelper.GetProjectFramework()); return(null); } //exclude the .transform files as they are treated separeately. List <IPackageFile> contentFiles = new List <IPackageFile>(); foreach (IPackageFile file in compatibleItems) { if (!file.Path.EndsWith(".transform")) { contentFiles.Add(file); } } if (contentFiles == null || contentFiles.Count == 0) { outputBuilder.AppendFormat(" No content files are present in the nupkg file.Skipping content validation"); return(null); } foreach (IPackageFile file in contentFiles) { string filePath = file.Path.Remove(0, @"Content\".Length); if (file.Path.EndsWith(".pp")) { filePath = filePath.Remove(filePath.Length - 3, 3); } filePath = Path.Combine(solutionPath, filePath); if (File.Exists(filePath)) { outputBuilder.AppendFormat("Content file : {0} added properly !!", file.Path); outputBuilder.AppendLine(); } else { HasSuceeded = false; errorBuilder.AppendFormat("Content file : {0} not added properly. Check the solution @ {1} for more details", file.Path, solutionPath); errorBuilder.AppendLine(); } } return(HasSuceeded); }