// // 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); } }
public void WhenAProjectContainsNet40BinariesItDoesntShipTheNet45Dependencies() { var outputPackage = Path.GetTempFileName() + ".nupkg"; var inputPackage = IntegrationTestHelper.GetPath("fixtures", "ThisShouldBeANet4Project.1.0.nupkg"); var rightPackage = "Caliburn.Micro.1.5.2.nupkg"; var rightPackagePath = IntegrationTestHelper.GetPath("fixtures", rightPackage); try { var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); File.Copy(rightPackagePath, Path.Combine(sourceDir, rightPackage), true); var package = new ReleasePackage(inputPackage); var outputFileName = package.CreateReleasePackage(outputPackage, sourceDir); var zipPackage = new ZipPackage(outputFileName); var dependency = zipPackage.GetLibFiles() .Where(f => f.Path.EndsWith("Caliburn.Micro.dll")) .FirstOrDefault(f => f.TargetFramework == new FrameworkName(".NETFramework,Version=v4.5")); Assert.Null(dependency); } 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); }
/// <summary> /// Validates the expected references to be added by the given package and the actual references being added matches. /// </summary> /// <param name="packageFullPath"></param> /// <param name="solutionPath"></param> public bool?Validate(string packageFullPath, VsProjectManager dteHelper) { ZipPackage zipPackage = new ZipPackage(packageFullPath); if (zipPackage.IsSatellitePackage()) { return(null); } string solutionPath = dteHelper.SolutionPath; HasSuceeded = true; Dictionary <string, string> referencesInProject = dteHelper.GetReferences(); string packageId = zipPackage.Id; List <IPackageFile> files = zipPackage.GetLibFiles().ToList(); if (files == null || files.Count == 0) { outputBuilder.AppendFormat(" No Lib files are present in the nupkg file.Skipping reference validation."); return(null); } //Get compatible items for the current project. //if no compatible items, then check if there are any files with directly under Lib 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 Lib folder matching the current project's target framework : {0}", dteHelper.GetProjectFramework()); return(null); } //Check that the compatible lib files are added as references. foreach (IPackageFile file in compatibleItems) { if (file.Path.EndsWith(".dll") || file.Path.EndsWith(".exe")) //exclude xml files { string referenceName = Path.GetFileNameWithoutExtension((file.Path)); if (!referencesInProject.Keys.Contains(referenceName, StringComparer.OrdinalIgnoreCase)) { HasSuceeded = false; errorBuilder.AppendFormat("The reference {0} is not added to project as part of installating package {1}.Check the Solution @ {2} for details", referenceName, packageId, solutionPath); errorBuilder.AppendLine(); } else { outputBuilder.AppendFormat("Reference Added properly for Lib : {0} !!", file.Path); outputBuilder.AppendLine(); } } } return(HasSuceeded); }
private void button2_Click(object sender, EventArgs e) { try { if (textBox2.Text.Trim() .Length > 0) { var nugetFramwork = NuGetFramework.ParseFrameworkName(NugetHelper.Instance.GetTargetFramwork(), new DefaultFrameworkNameProvider()); var nupkgPath = textBox2.Text.Trim(); var package = new ZipPackage(nupkgPath); //var content = package.GetContentFiles(); var files = package.GetLibFiles() .ToList(); var targetDlls = files.FindAll(x => x.EffectivePath.ToLower() .Contains(".dll") && x.TargetFramework.Identifier.ToLower() == nugetFramwork.Framework.ToLower()) .Take(1); foreach (var item in targetDlls) { if (item.EffectivePath.ToLower() .Contains(".dll")) { var rawAssembly = item.GetStream() .ReadAllBytes(); var ad = AppDomain.CreateDomain("newDomian"); // Loader lives in another AppDomain var loader = (Loader)ad.CreateInstanceAndUnwrap(typeof(Loader).Assembly.FullName, typeof(Loader).FullName); loader.LoadAssembly(rawAssembly); var dd = loader.ExecuteStaticMethod("RestSharp.Validation.Ensure", "NotEmpty", "admin", "admin"); var dd1 = loader.ExecuteStaticMethod("RestSharp.SimpleJson", "EscapeToJavascriptString", "admin\\teset\\asdf\\sdaf"); richTextBox1.Text = $"RestSharp.SimpleJson.EscapeToJavascriptString(\"admin\\\\teset\\\\asdf\\\\sdaf\") -- {dd1}"; ad.DomainUnload += OnAppDomainUnload; AppDomain.Unload(ad); } } } } catch (Exception exception) { MessageBox.Show(exception.Message); } }
public void UsesTheRightVersionOfADependencyWhenMultipleAreInPackages() { var outputPackage = Path.GetTempFileName() + ".nupkg"; string outputFile = null; var inputPackage = IntegrationTestHelper.GetPath("fixtures", "CaliburnMicroDemo.1.0.0.nupkg"); var wrongPackage = "Caliburn.Micro.1.4.1.nupkg"; var wrongPackagePath = IntegrationTestHelper.GetPath("fixtures", wrongPackage); var rightPackage = "Caliburn.Micro.1.5.2.nupkg"; var rightPackagePath = IntegrationTestHelper.GetPath("fixtures", rightPackage); try { var sourceDir = IntegrationTestHelper.GetPath("..", "packages"); (new DirectoryInfo(sourceDir)).Exists.ShouldBeTrue(); File.Copy(wrongPackagePath, Path.Combine(sourceDir, wrongPackage), true); File.Copy(rightPackagePath, Path.Combine(sourceDir, rightPackage), true); var package = new ReleasePackage(inputPackage); var outputFileName = package.CreateReleasePackage(outputPackage, sourceDir); var zipPackage = new ZipPackage(outputFileName); var fileName = "Caliburn.Micro.dll"; var dependency = zipPackage.GetLibFiles() .Where(f => f.Path.EndsWith(fileName)) .Single(f => f.TargetFramework == new FrameworkName(".NETFramework,Version=v4.0")); outputFile = new FileInfo(Path.Combine(sourceDir, fileName)).FullName; using (var of = File.Create(outputFile)) { dependency.GetStream().CopyTo(of); } var assemblyName = AssemblyName.GetAssemblyName(outputFile); Assert.Equal(1, assemblyName.Version.Major); Assert.Equal(5, assemblyName.Version.Minor); } finally { File.Delete(outputPackage); File.Delete(outputFile); } }
public IList <PackageIndexError> AddPackage(ZipPackage package, bool force = false) { if (package == null) { return(null); } // check if package exists in the index: // - if it does not, proceed and add it // - if it is, add to index only if new package has higher version var existingPackage = GetPackages(package.Id).FirstOrDefault(); if (existingPackage != null) { var existingPackageVersion = new SemanticVersion(existingPackage.Version); if (existingPackageVersion >= package.Version && !force) { Logger.WriteVerbose("More recent version {0} of package {1} {2} exists in the index. Skipping...", existingPackageVersion.ToString(), package.Id, package.Version); return(new List <PackageIndexError>()); } else { // Remove all old packages types. This is for the case if new package does not // contain some types (deprecated), in this case index would still keep them. Logger.WriteVerbose("Older version {0} of package {1} {2} exists in the index. Removing from index...", existingPackageVersion.ToString(), package.Id, package.Version); RemovePackage(package.Id); } } Logger.WriteInformation("Adding package {0} {1} to index.", package.Id, package.Version); var libFiles = package.GetLibFiles().Where(x => ".dll".Equals(Path.GetExtension(x.EffectivePath), StringComparison.OrdinalIgnoreCase)); var packageTargetFrameworks = package.GetSupportedFrameworks(); var packageTypes = new Dictionary <string, TypeModel>(StringComparer.OrdinalIgnoreCase); // get a list of all public types in all unique package assemblies foreach (IPackageFile dll in libFiles) { // if dll is a contracts dll it provides types accross all frameworks supported by package var dllTtargetFrameworks = packageTargetFrameworks; if (dll.TargetFramework != null && !dll.Path.ToLower().Contains(@"lib\contract")) { dllTtargetFrameworks = new[] { dll.TargetFramework }; } Logger.WriteVerbose("Processing assembly {0}.", dll.Path); var assemblyTypes = ProcessAssembly(package.Id, package.Version.ToString(), dllTtargetFrameworks, dll.GetStream()); if (assemblyTypes != null) { Logger.WriteVerbose("Found {0} public types.", assemblyTypes.Count()); MergeTypes(packageTypes, assemblyTypes); } } Logger.WriteVerbose("Storing package model to the index."); // add a pckage entry to index var result = Engine.AddEntry( new PackageModel { Name = package.Id, Version = package.Version.ToString() }); Logger.WriteVerbose("Storing type models to the index."); // add all types to index result.AddRange(Engine.AddEntries(packageTypes.Values, true)); Logger.WriteVerbose("Package indexing complete."); return(result); }