public override void RemovePackage(IPackage package) { // Delete the package file string packageFilePath = GetPackageFilePath(package); FileSystem.DeleteFileSafe(packageFilePath); // Delete the package directory if any FileSystem.DeleteDirectorySafe(PathResolver.GetPackageDirectory(package), recursive: false); // If this is the last package delete the package directory if (!FileSystem.GetFilesSafe(String.Empty).Any() && !FileSystem.GetDirectoriesSafe(String.Empty).Any()) { FileSystem.DeleteDirectorySafe(String.Empty, recursive: false); } }
private void RemoveFiles(IPackage package) { string packageDirectory = PathResolver.GetPackageDirectory(package); // Remove resource files FileSystem.DeleteFiles(package.GetFiles(), packageDirectory); // If this is a Satellite Package, then remove the files from the related runtime package folder too IPackage runtimePackage; if (PackageUtility.IsSatellitePackage(package, LocalRepository, targetFramework: null, runtimePackage: out runtimePackage)) { var satelliteFiles = package.GetSatelliteFiles(); var runtimePath = PathResolver.GetPackageDirectory(runtimePackage); FileSystem.DeleteFiles(satelliteFiles, runtimePath); } }
protected virtual void ExtractPackageFilesToProject(IPackage package) { // BUG 491: Installing a package with incompatible binaries still does a partial install. // Resolve assembly references first so that if this fails we never do anything to the project IEnumerable <IPackageAssemblyReference> assemblyReferences = Project.GetCompatibleItems(package.AssemblyReferences, NuGetResources.AssemblyReferences); IEnumerable <FrameworkAssemblyReference> frameworkReferences = Project.GetCompatibleItems(package.FrameworkAssemblies, NuGetResources.FrameworkAssemblies); try { // Add content files Project.AddFiles(package.GetContentFiles(), _fileTransformers); // Add the references to the reference path foreach (IPackageAssemblyReference assemblyReference in assemblyReferences) { // Get the physical path of the assembly reference string referencePath = Path.Combine(PathResolver.GetInstallPath(package), assemblyReference.Path); string relativeReferencePath = PathUtility.GetRelativePath(Project.Root, referencePath); if (Project.ReferenceExists(assemblyReference.Name)) { Project.RemoveReference(assemblyReference.Name); } using (Stream stream = assemblyReference.GetStream()) { Project.AddReference(relativeReferencePath, stream); } } // Add GAC/Framework references foreach (FrameworkAssemblyReference frameworkReference in frameworkReferences) { if (!Project.ReferenceExists(frameworkReference.AssemblyName)) { Project.AddFrameworkReference(frameworkReference.AssemblyName); } } } finally { // Add package to local repository in the finally so that the user can uninstall it // if any exception occurs. This is easier than rolling back since the user can just // manually uninstall things that may have failed. // If this fails then the user is out of luck. LocalRepository.AddPackage(package); } }
private void RemoveFiles(IPackage package) { string packageDirectory = PathResolver.GetPackageDirectory(package); // If this is a Satellite Package, then remove the files from the related runtime package folder too IPackage runtimePackage; if (PackageHelper.IsSatellitePackage(package, LocalRepository, targetFramework: null, runtimePackage: out runtimePackage)) { var satelliteFiles = package.GetSatelliteFiles(); var runtimePath = PathResolver.GetPackageDirectory(runtimePackage); FileSystem.DeleteFiles(satelliteFiles, runtimePath); } // Remove package files // IMPORTANT: This has to be done AFTER removing satellite files from runtime package, // because starting from 2.1, we read satellite files directly from package files, instead of .nupkg FileSystem.DeleteFiles(package.GetFiles(), packageDirectory); }
private void AddFiles(string basePath, string source, string destination, string exclude = null) { List <PhysicalPackageFile> searchFiles = PathResolver.ResolveSearchPattern(basePath, source, destination, this._includeEmptyDirectories).ToList <PhysicalPackageFile>(); if (this._includeEmptyDirectories) { searchFiles.RemoveAll(file => (file.TargetFramework == null) && (Path.GetFileName(file.TargetPath) == "_._")); } ExcludeFiles(searchFiles, basePath, exclude); if (PathResolver.IsWildcardSearch(source) || (PathResolver.IsDirectoryPath(source) || searchFiles.Any <PhysicalPackageFile>())) { this.Files.AddRange <IPackageFile>(searchFiles); } else { object[] args = new object[] { source }; throw new FileNotFoundException(string.Format(CultureInfo.CurrentCulture, NuGetResources.PackageAuthoring_FileNotFound, args)); } }
public override IPackage FindPackage(string packageId, SemanticVersion version) { var package = base.FindPackage(packageId, version); if (package != null) { return(package); } // if we didn't find the .nupkg file, search for .nuspec file if (version != null) { string packagePath = GetManifestFilePath(packageId, version); if (FileSystem.FileExists(packagePath)) { string packageDirectory = PathResolver.GetPackageDirectory(packageId, version); return(new UnzippedPackage(FileSystem, packageDirectory)); } } return(null); }
private void AddFiles(string basePath, string source, string destination) { PathSearchFilter searchFilter = PathResolver.ResolveSearchFilter(basePath, source); IEnumerable <string> searchFiles = Directory.EnumerateFiles(searchFilter.SearchDirectory, searchFilter.SearchPattern, searchFilter.SearchOption); if (!searchFilter.WildCardSearch && !searchFiles.Any()) { throw new FileNotFoundException(String.Format(CultureInfo.CurrentCulture, NuGetResources.PackageAuthoring_FileNotFound, source)); } foreach (var file in searchFiles) { var destinationPath = PathResolver.ResolvePackagePath(searchFilter, file, destination); Files.Add(new PhysicalPackageFile { SourcePath = file, TargetPath = destinationPath }); } }
private void AddFiles(string basePath, string source, string destination, string exclude = null) { List <PhysicalPackageFile> searchFiles = PathResolver.ResolveSearchPattern(basePath, source, destination, _includeEmptyDirectories).ToList(); if (_includeEmptyDirectories) { // we only allow empty directories which are legit framework folders. searchFiles.RemoveAll(file => file.TargetFramework == null && Path.GetFileName(file.TargetPath) == Constants.PackageEmptyFileName); } ExcludeFiles(searchFiles, basePath, exclude); if (!PathResolver.IsWildcardSearch(source) && !PathResolver.IsDirectoryPath(source) && !searchFiles.Any()) { throw new FileNotFoundException( String.Format(CultureInfo.CurrentCulture, NuGetResources.PackageAuthoring_FileNotFound, source)); } Files.AddRange(searchFiles); }
private void ExpandFiles(IPackage package) { var batchProcessor = FileSystem as IBatchProcessor <string>; try { var files = package.GetFiles().ToList(); if (batchProcessor != null) { // Notify the batch processor that the files are being added. This is to allow source controlled file systems // to manage previously uninstalled files. batchProcessor.BeginProcessing(files.Select(p => p.Path), PackageAction.Install); } string packageDirectory = PathResolver.GetPackageDirectory(package); // Add files FileSystem.AddFiles(files, packageDirectory); // If this is a Satellite Package, then copy the satellite files into the related runtime package folder too IPackage runtimePackage; if (PackageHelper.IsSatellitePackage(package, LocalRepository, targetFramework: null, runtimePackage: out runtimePackage)) { var satelliteFiles = package.GetSatelliteFiles(); var runtimePath = PathResolver.GetPackageDirectory(runtimePackage); FileSystem.AddFiles(satelliteFiles, runtimePath); } } finally { if (batchProcessor != null) { batchProcessor.EndProcessing(); } } }
public override void RemovePackage(IPackage package) { // IMPORTANT (bug #3114) Even though we delete the entire package's directory, // we still need to explicitly delete the .nuspec and .nupkg files in order to // undo pending TFS add operations, if any. string manifestFilePath = GetManifestFilePath(package.Id, package.Version); if (FileSystem.FileExists(manifestFilePath)) { // delete .nuspec file FileSystem.DeleteFileSafe(manifestFilePath); } string packageFilePath = GetPackageFilePath(package); if (FileSystem.FileExists(packageFilePath)) { // Delete the .nupkg file FileSystem.DeleteFileSafe(packageFilePath); } // Now delete the entire package's directory, just in case some files are left behind FileSystem.DeleteDirectorySafe(PathResolver.GetPackageDirectory(package), recursive: true); // If this is the last package delete the 'packages' directory if (!FileSystem.GetFilesSafe(String.Empty).Any() && !FileSystem.GetDirectoriesSafe(String.Empty).Any()) { FileSystem.DeleteDirectorySafe(String.Empty, recursive: false); } if (_packageReferenceFile != null) { _packageReferenceFile.DeleteEntry(package.Id, package.Version); } }
protected virtual string GetPackageFilePath(string id, SemanticVersion version) { return(Path.Combine(PathResolver.GetPackageDirectory(id, version), PathResolver.GetPackageFileName(id, version))); }
protected virtual string GetPackageFilePath(IPackage package) { return(Path.Combine(PathResolver.GetPackageDirectory(package), PathResolver.GetPackageFileName(package))); }
public PackageOperationEventArgs CreateOperation(IPackage package) { return(new PackageOperationEventArgs(package, Project, PathResolver.GetInstallPath(package))); }
private void RemovePackageReferenceFromProject(IPackage package) { if (IsNuGetAwareProject()) { RemovePackageReferenceFromNuGetAwareProject(package); return; } string packageFullName = package.GetFullName(); Logger.Log(MessageLevel.Info, NuGetResources.Log_BeginRemovePackageReference, packageFullName, Project.ProjectName); PackageOperationEventArgs args = CreateOperation(package); OnPackageReferenceRemoving(args); if (args.Cancel) { return; } // Get other packages IEnumerable <IPackage> otherPackages = from p in LocalRepository.GetPackages() where p.Id != package.Id select p; // Get other references var otherAssemblyReferences = from p in otherPackages let assemblyReferences = GetFilteredAssembliesToDelete(p) from assemblyReference in assemblyReferences ?? Enumerable.Empty <IPackageAssemblyReference>() // This can happen if package installed left the project in a bad state select assemblyReference; // Get content files from other packages // Exclude transform files since they are treated specially var otherContentFiles = from p in otherPackages from file in GetCompatibleInstalledItemsForPackage(p.Id, p.GetContentFiles(), NetPortableProfileTable.Default) where !IsTransformFile(file.Path) select file; // Get the files and references for this package, that aren't in use by any other packages so we don't have to do reference counting var assemblyReferencesToDelete = GetFilteredAssembliesToDelete(package) .Except(otherAssemblyReferences, PackageFileComparer.Default); var contentFilesToDelete = GetCompatibleInstalledItemsForPackage(package.Id, package.GetContentFiles(), NetPortableProfileTable.Default) .Except(otherContentFiles, PackageFileComparer.Default); var buildFilesToDelete = GetCompatibleInstalledItemsForPackage(package.Id, package.GetBuildFiles(), NetPortableProfileTable.Default); // Delete the content files Project.DeleteFiles(contentFilesToDelete, otherPackages, _fileTransformers); // Remove references foreach (IPackageAssemblyReference assemblyReference in assemblyReferencesToDelete) { Project.RemoveReference(assemblyReference.Name); } // remove the <Import> statement from projects for the .targets and .props files foreach (var importFile in buildFilesToDelete) { string fullImportFilePath = Path.Combine(PathResolver.GetInstallPath(package), importFile.Path); Project.RemoveImport(fullImportFilePath); } // Remove package to the repository LocalRepository.RemovePackage(package); Logger.Log(MessageLevel.Info, NuGetResources.Log_SuccessfullyRemovedPackageReference, packageFullName, Project.ProjectName); OnPackageReferenceRemoved(args); }
protected virtual void ExtractPackageFilesToProject(IPackage package) { // BUG 491: Installing a package with incompatible binaries still does a partial install. // Resolve assembly references and content files first so that if this fails we never do anything to the project List <IPackageAssemblyReference> assemblyReferences = Project.GetCompatibleItemsCore(package.AssemblyReferences).ToList(); List <FrameworkAssemblyReference> frameworkReferences = Project.GetCompatibleItemsCore(package.FrameworkAssemblies).ToList(); List <IPackageFile> contentFiles = Project.GetCompatibleItemsCore(package.GetContentFiles()).ToList(); List <IPackageFile> buildFiles = Project.GetCompatibleItemsCore(package.GetBuildFiles()).ToList(); // If the package doesn't have any compatible assembly references or content files, // throw, unless it's a meta package. if (assemblyReferences.Count == 0 && frameworkReferences.Count == 0 && contentFiles.Count == 0 && buildFiles.Count == 0 && (package.FrameworkAssemblies.Any() || package.AssemblyReferences.Any() || package.GetContentFiles().Any() || package.GetBuildFiles().Any())) { // for portable framework, we want to show the friendly short form (e.g. portable-win8+net45+wp8) instead of ".NETPortable, Profile=Profile104". FrameworkName targetFramework = Project.TargetFramework; string targetFrameworkString = targetFramework.IsPortableFramework() ? VersionUtility.GetShortFrameworkName(targetFramework) : targetFramework != null?targetFramework.ToString() : null; throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToFindCompatibleItems, package.GetFullName(), targetFrameworkString)); } // IMPORTANT: this filtering has to be done AFTER the 'if' statement above, // so that we don't throw the exception in case the <References> filters out all assemblies. FilterAssemblyReferences(assemblyReferences, package.PackageAssemblyReferences); try { // Log target framework info for debugging LogTargetFrameworkInfo(package, assemblyReferences, contentFiles, buildFiles); // Add content files Project.AddFiles(contentFiles, _fileTransformers); // Add the references to the reference path foreach (IPackageAssemblyReference assemblyReference in assemblyReferences) { if (assemblyReference.IsEmptyFolder()) { continue; } // Get the physical path of the assembly reference string referencePath = Path.Combine(PathResolver.GetInstallPath(package), assemblyReference.Path); string relativeReferencePath = PathUtility.GetRelativePath(Project.Root, referencePath); if (Project.ReferenceExists(assemblyReference.Name)) { Project.RemoveReference(assemblyReference.Name); } Project.AddReference(relativeReferencePath); } // Add GAC/Framework references foreach (FrameworkAssemblyReference frameworkReference in frameworkReferences) { if (!Project.ReferenceExists(frameworkReference.AssemblyName)) { Project.AddFrameworkReference(frameworkReference.AssemblyName); } } foreach (var importFile in buildFiles) { string fullImportFilePath = Path.Combine(PathResolver.GetInstallPath(package), importFile.Path); Project.AddImport( fullImportFilePath, importFile.Path.EndsWith(".props", StringComparison.OrdinalIgnoreCase) ? ProjectImportLocation.Top : ProjectImportLocation.Bottom); } } finally { if (_packageReferenceRepository != null) { // save the used project's framework if the repository supports it. _packageReferenceRepository.AddPackage(package.Id, package.Version, package.DevelopmentDependency, Project.TargetFramework); } else { // Add package to local repository in the finally so that the user can uninstall it // if any exception occurs. This is easier than rolling back since the user can just // manually uninstall things that may have failed. // If this fails then the user is out of luck. LocalRepository.AddPackage(package); } } }
private PackageOperationEventArgs CreateOperation(IPackage package) { return(new PackageOperationEventArgs(package, FileSystem, PathResolver.GetInstallPath(package))); }
protected virtual void ExtractPackageFilesToProject(IPackage package) { // BUG 491: Installing a package with incompatible binaries still does a partial install. // Resolve assembly references and content files first so that if this fails we never do anything to the project IList <IPackageAssemblyReference> assemblyReferences = Project.GetCompatibleItemsCore(package.AssemblyReferences).ToList(); IList <FrameworkAssemblyReference> frameworkReferences = Project.GetCompatibleItemsCore(package.FrameworkAssemblies).ToList(); IList <IPackageFile> contentFiles = Project.GetCompatibleItemsCore(package.GetContentFiles()).ToList(); // If the package doesn't have any compatible assembly references or content files, // throw, unless it's a meta package. if (assemblyReferences.Count == 0 && frameworkReferences.Count == 0 && contentFiles.Count == 0 && (package.FrameworkAssemblies.Any() || package.AssemblyReferences.Any() || package.GetContentFiles().Any())) { // for portable framework, we want to show the friendly short form (e.g. portable-win8+net45+wp8) instead of ".NETPortable, Profile=Profile104". string targetFrameworkString = VersionUtility.IsPortableFramework(Project.TargetFramework) ? VersionUtility.GetShortFrameworkName(Project.TargetFramework) : Project.TargetFramework.ToString(); throw new InvalidOperationException( String.Format(CultureInfo.CurrentCulture, NuGetResources.UnableToFindCompatibleItems, package.GetFullName(), targetFrameworkString)); } try { // Add content files Project.AddFiles(contentFiles, _fileTransformers); // Add the references to the reference path foreach (IPackageAssemblyReference assemblyReference in assemblyReferences) { if (assemblyReference.IsEmptyFolder()) { continue; } // Get the physical path of the assembly reference string referencePath = Path.Combine(PathResolver.GetInstallPath(package), assemblyReference.Path); string relativeReferencePath = PathUtility.GetRelativePath(Project.Root, referencePath); if (Project.ReferenceExists(assemblyReference.Name)) { Project.RemoveReference(assemblyReference.Name); } // The current implementation of all ProjectSystem does not use the Stream parameter at all. // We can't change the API now, so just pass in a null stream. Project.AddReference(relativeReferencePath, Stream.Null); } // Add GAC/Framework references foreach (FrameworkAssemblyReference frameworkReference in frameworkReferences) { if (!Project.ReferenceExists(frameworkReference.AssemblyName)) { Project.AddFrameworkReference(frameworkReference.AssemblyName); } } } finally { if (_packageReferenceRepository != null) { // save the used project's framework if the repository supports it. _packageReferenceRepository.AddPackage(package.Id, package.Version, Project.TargetFramework); } else { // Add package to local repository in the finally so that the user can uninstall it // if any exception occurs. This is easier than rolling back since the user can just // manually uninstall things that may have failed. // If this fails then the user is out of luck. LocalRepository.AddPackage(package); } } }