private void AddPackage(IPackageManager manager, string id, string version) { string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext, "source"); string dummyTextFile = TestUtils.CreateTextFile(Guid.NewGuid().ToString(), testDir, "content"); PackageBuilder builder = new PackageBuilder(); builder.Id = id; builder.Version = new SemanticVersion(version); builder.Description = "dummy description"; builder.Authors.Add("dummy author"); PhysicalPackageFile file = new PhysicalPackageFile(); file.SourcePath = dummyTextFile; file.TargetPath = "dummy.txt"; builder.Files.Add(file); MemoryStream stream = new MemoryStream(); builder.Save(stream); stream.Position = 0; ZipPackage pkg = new ZipPackage(stream); manager.InstallPackage(pkg, true, true); }
public void SetPackageBuilder(PackageBuilder builder) { SuspendLayout(); packageBuilder = builder; metadataSaveVersion = MetadataSpecified && File.Exists(metadataPath) ? 0 : -1; TypeDescriptor.AddProvider(descriptionProvider, packageBuilder); metadataProperties.SelectedObject = packageBuilder; metadataProperties.ExpandAllGridItems(); var entryPointPath = Path.GetFileNameWithoutExtension(metadataPath) + Constants.BonsaiExtension; var entryPointLayoutPath = entryPointPath + Constants.LayoutExtension; foreach (var file in packageBuilder.Files) { if (file.EffectivePath == entryPointPath) { entryPoint = file as PhysicalPackageFile; } if (file.EffectivePath == entryPointLayoutPath) { entryPointLayout = file as PhysicalPackageFile; } AddPackageFile(file); } contentView.ExpandAll(); ResumeLayout(); }
private Stream BuildPackageToStream(ManifestMetadata metadata, Stream outputStream) { string testDir = TestUtils.EnsureTestDirectoryExists(this.TestContext, "source"); string dummyTextFile = TestUtils.CreateTextFile(Guid.NewGuid().ToString(), testDir, "content"); PackageBuilder packageBuilder = new PackageBuilder(); PhysicalPackageFile file = new PhysicalPackageFile(); file.SourcePath = dummyTextFile; file.TargetPath = "dummy.txt"; packageBuilder.Files.Add(file); packageBuilder.Populate(metadata); packageBuilder.Save(outputStream); // Assert correct function of the above code when versions are specifically "Release" or "Prerelease" if (String.Equals(metadata.Version, ReleaseVersion, StringComparison.CurrentCulture)) { Assert.IsTrue(packageBuilder.IsReleaseVersion()); } else if (String.Equals(metadata.Version, PreReleaseVersion, StringComparison.CurrentCulture)) { Assert.IsFalse(packageBuilder.IsReleaseVersion()); } return(outputStream); }
protected override bool GeneratePackage(string nupkg, List <DiagnosticMessage> packDiagnostics) { var compilerOptions = Project.GetCompilerOptions( Project.GetTargetFramework(targetFramework: null).FrameworkName, Configuration); if (compilerOptions.CompileInclude == null) { foreach (var path in Project.Files.SourceFiles) { var srcFile = new PhysicalPackageFile { SourcePath = path, TargetPath = Path.Combine("src", Common.PathUtility.GetRelativePath(Project.ProjectDirectory, path)) }; PackageBuilder.Files.Add(srcFile); } } else { var includeFiles = IncludeFilesResolver.GetIncludeFiles(compilerOptions.CompileInclude, "/", diagnostics: null); foreach (var entry in includeFiles) { var srcFile = new PhysicalPackageFile { SourcePath = entry.SourcePath, TargetPath = Path.Combine("src", entry.TargetPath) }; PackageBuilder.Files.Add(srcFile); } } return(base.GeneratePackage(nupkg, packDiagnostics)); }
public void AddFile(string fileName) { var file = new PhysicalPackageFile(); file.TargetPath = fileName; FilesList.Add(file); }
private void IncludeFilesRecursively(string path, string pathToIgnore, ref HashSet <PhysicalPackageFile> includedFiles) { var directories = _fs.Directory.GetDirectories(path).ToList(); foreach (var directory in directories) { IncludeFilesRecursively(directory, pathToIgnore, ref includedFiles); } var files = _fs.Directory.GetFiles(path); foreach (var file in files) { _log.DebugFormat("Including {0}", file); var physicalPackageFile = new PhysicalPackageFile { SourcePath = file, TargetPath = _fs.Path.GetFullPath(file).Substring(pathToIgnore.Length), }; if (!includedFiles.Contains(physicalPackageFile)) { includedFiles.Add(physicalPackageFile); } } }
private void AddFileToBuilder(PackageBuilder builder, PhysicalPackageFile packageFile) { if (!builder.Files.Any(p => packageFile.Path.Equals(p.Path, StringComparison.OrdinalIgnoreCase))) { builder.Files.Add(packageFile); } }
private IPackage AddPackage(IPackageManager manager, string id, string version, string payloadAssemblyFilePath, params IPackage[] dependencies) { PackageBuilder builder = new PackageBuilder(); ManifestMetadata metadata = new ManifestMetadata() { Authors = "dummy author 1,dummy author 2", Owners = "dummy owner 1,dummy owner 2", Title = "dummy title", Version = new SemanticVersion(version).ToString(), Id = id, Description = "dummy description", LicenseUrl = "http://my.license/readme.txt", ProjectUrl = "http://dummyurl/" }; List <ManifestDependency> dependencyList = new List <ManifestDependency>(); foreach (IPackage dependencyNode in dependencies) { dependencyList.Add(new ManifestDependency() { Id = dependencyNode.Id, Version = dependencyNode.Version.ToString(), }); } List <ManifestDependencySet> dependencySetList = new List <ManifestDependencySet>() { new ManifestDependencySet() { Dependencies = dependencyList } }; metadata.DependencySets = dependencySetList; builder.Populate(metadata); PhysicalPackageFile file = new PhysicalPackageFile { SourcePath = payloadAssemblyFilePath, TargetPath = "analyzers/" + Path.GetFileName(payloadAssemblyFilePath) }; builder.Files.Add(file); using (MemoryStream stream = new MemoryStream()) { builder.Save(stream); stream.Position = 0; ZipPackage pkg = new ZipPackage(stream); manager.InstallPackage(pkg, true, true); return(pkg); } }
private void AddFiles(PackageBuilder builder, string itemType, string targetFolder) { // Skip files that are added by dependency packages string packagesConfig = GetPackagesConfig(); IPackageRepository repository = GetPackagesRepository(); var contentFilesInDependencies = new List <IPackageFile>(); if (packagesConfig != null && repository != null) { var references = new PackageReferenceFile(packagesConfig).GetPackageReferences(); contentFilesInDependencies = references.Select(reference => repository.FindPackage(reference.Id, reference.Version)) .Where(a => a != null) .SelectMany(a => a.GetContentFiles()) .ToList(); } // Get the content files from the project foreach (var item in _project.GetItems(itemType)) { string fullPath = item.GetMetadataValue("FullPath"); if (_excludeFiles.Contains(Path.GetFileName(fullPath))) { continue; } string targetFilePath = GetTargetPath(item); if (!File.Exists(fullPath)) { Logger.Log(MessageLevel.Warning, NuGetResources.Warning_FileDoesNotExist, targetFilePath); continue; } // Check that file is added by dependency string targetPath = Path.Combine(targetFolder, targetFilePath); IPackageFile targetFile = contentFilesInDependencies.Find(a => a.Path.Equals(targetPath, StringComparison.OrdinalIgnoreCase)); if (targetFile != null) { // Compare contents as well var isEqual = ContentEquals(targetFile, fullPath); if (isEqual) { Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsNotChanged, targetFilePath); continue; } Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsChanged, targetFilePath); } var packageFile = new PhysicalPackageFile { SourcePath = fullPath, TargetPath = targetPath }; AddFileToBuilder(builder, packageFile); } }
public PackageFile AddFile(string filePath, bool isTempFile) { if (!File.Exists(filePath)) { throw new ArgumentException("File does not exist.", "filePath"); } string newFileName = System.IO.Path.GetFileName(filePath); if (ContainsFolder(newFileName)) { PackageViewModel.UIServices.Show(Resources.FileNameConflictWithExistingDirectory, MessageLevel.Error); return(null); } bool showingRemovedFile = false; if (ContainsFile(newFileName)) { bool confirmed = PackageViewModel.UIServices.Confirm( Resources.ConfirmToReplaceExsitingFile_Title, String.Format(CultureInfo.CurrentCulture, Resources.ConfirmToReplaceExsitingFile, newFileName), isWarning: true); if (confirmed) { var part = this[newFileName] as PackageFile; showingRemovedFile = PackageViewModel.IsShowingFileContent(part); // remove the existing file before adding the new one RemoveChildByName(newFileName); } else { return(null); } } string newTargetPath = this.Path + "\\" + newFileName; var physicalFile = new PhysicalPackageFile { SourcePath = filePath, TargetPath = newTargetPath }; var newFile = new PackageFile(physicalFile, newFileName, this); Children.Add(newFile); newFile.IsSelected = true; IsExpanded = true; PackageViewModel.NotifyChanges(); if (showingRemovedFile) { PackageViewModel.ShowFileContent(newFile); } return(newFile); }
public void IsAssemblyReferenceReturnsFalseIfFileDoesNotStartWithLib() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"content\foo.dll" }; IEnumerable<string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsFalseIfFileExtensionIsNotAReferenceItem() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\foo.txt" }; IEnumerable<string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsFalseIfFileExtensionIsNotAReferenceItem() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\foo.txt" }; IEnumerable <string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsFalseIfFileDoesNotStartWithLib() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"content\foo.dll" }; IEnumerable <string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsTrueForWinMDFileInLib() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.Core.WINMD" }; IEnumerable <string> references = null; // Act and Assert Assert.True(ZipPackage.IsAssemblyReference(file, references)); }
protected override bool GeneratePackage(string nupkg, List <DiagnosticMessage> packDiagnostics) { foreach (var path in Project.Files.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", Common.PathUtility.GetRelativePath(Project.ProjectDirectory, path)); PackageBuilder.Files.Add(srcFile); } return(base.GeneratePackage(nupkg, packDiagnostics)); }
private static void BuildPackages() { var directory = new DirectoryInfo(BuildDirectory); XmlSerializer serializer = new XmlSerializer(typeof(game)); var fs = File.Open(directory.GetFiles().First().FullName, FileMode.Open); var game = (game)serializer.Deserialize(fs); fs.Close(); var builder = new NuGet.PackageBuilder() { Id = game.id, Description = game.description, ProjectUrl = new Uri(game.gameurl), Version = new SemanticVersion(game.version), Title = game.name, IconUrl = new Uri(game.iconurl), }; foreach (var author in game.authors.Split(',')) { builder.Authors.Add(author); } foreach (var tag in game.tags.Split(' ')) { builder.Tags.Add(tag); } // files and maybe release notes var allFiles = directory .GetFiles("*.*", SearchOption.AllDirectories) .Where(x => x.Extension.ToLower() != ".nupkg" && x.Extension.ToLower() != ".o8g"); foreach (var file in allFiles) { var path = file.FullName; var relPath = path.Replace(directory.FullName, "\\def"); var pf = new PhysicalPackageFile() { SourcePath = path, TargetPath = relPath }; builder.Files.Add(pf); } var feedPath = Path.Combine(directory.FullName, game.name + '-' + game.version + ".nupkg"); var olPath = Path.Combine(directory.FullName, game.name + '-' + game.version + ".o8g"); var filestream = File.Open(feedPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); builder.Save(filestream); filestream.Flush(true); filestream.Close(); filestream = File.Open(olPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); builder.Save(filestream); filestream.Flush(true); filestream.Close(); }
public void IsAssemblyReferenceReturnsFalseIfFileIsAResourceAssembly() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.resources.dll" }; IEnumerable <string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void FileInList_AddedToPackage() { var metaData = new PackageMetadata(); var file = new PhysicalPackageFile(); _files.Add(file); var packageBuilt = _pc.BuildPackage(_files, metaData); Assert.That(packageBuilt.Files[0], Is.EqualTo(file)); }
static void RenamePackageFile(PhysicalPackageFile file, string fileName) { var extension = Path.GetExtension(file.SourcePath); if (extension == Constants.LayoutExtension) { extension = Constants.BonsaiExtension + extension; } var basePath = Path.GetDirectoryName(file.TargetPath); file.TargetPath = Path.Combine(basePath, fileName + extension); }
private bool GeneratePackage(bool success, List <DiagnosticMessage> allDiagnostics, PackageBuilder packageBuilder, PackageBuilder symbolPackageBuilder, string nupkg, string symbolsNupkg) { var packDiagnostics = new List <DiagnosticMessage>(); foreach (var sharedFile in _currentProject.Files.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = String.Format(@"shared\{0}", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = _currentProject.ProjectDirectory; if (_currentProject.Files.PackInclude != null && _currentProject.Files.PackInclude.Any()) { AddPackageFiles(_currentProject.ProjectDirectory, _currentProject.Files.PackInclude, packageBuilder, packDiagnostics); } success &= !packDiagnostics.HasErrors(); allDiagnostics.AddRange(packDiagnostics); foreach (var path in _currentProject.Files.SourceFiles) { var srcFile = new PhysicalPackageFile(); srcFile.SourcePath = path; srcFile.TargetPath = Path.Combine("src", PathUtility.GetRelativePath(root, path)); symbolPackageBuilder.Files.Add(srcFile); } // Write the packages as long as we're still in a success state. if (success) { using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(nupkg)); } if (symbolPackageBuilder.Files.Any()) { using (var fs = File.Create(symbolsNupkg)) { symbolPackageBuilder.Save(fs); _buildOptions.Reports.Quiet.WriteLine("{0} -> {1}", _currentProject.Name, Path.GetFullPath(symbolsNupkg)); } } } WriteDiagnostics(packDiagnostics); return(success); }
// Use SharpCompress to get a list of files, and write to disk if not already there. If the files are corrupt, // we don't care. Delete them and try again. Significantly faster. private static bool New_NuGet_OptimizedZipPackage_EnsurePackageFiles(OptimizedZipPackage __instance, ref Dictionary <string, PhysicalPackageFile> ____files, ref string ____expandedFolderPath, IFileSystem ____expandedFileSystem) { if (____files != null) { return(false); } ____files = new Dictionary <string, PhysicalPackageFile>(); ____expandedFolderPath = __instance.Id + "." + __instance.Version; using (var stream = __instance.GetStream()) { using (var zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, true)) { foreach (var zipArchiveEntry in zipArchive.Entries) { var path = zipArchiveEntry.FullName; if (path.EndsWith(".nuspec") || path.EndsWith(".psmdcp") || path == "_rels/.rels" || path == "[Content_Types].xml") { continue; } var localPath = Path.Combine(____expandedFolderPath, path); if (!____expandedFileSystem.FileExists(localPath)) { using (var entryStream = zipArchiveEntry.Open()) { try { using (var file = ____expandedFileSystem.CreateFile(localPath)) entryStream.CopyTo(file); } catch (Exception) { } } } var physicalPackageFile = new PhysicalPackageFile { SourcePath = ____expandedFileSystem.GetFullPath(localPath), TargetPath = path }; ____files[path] = physicalPackageFile; } } } return(false); }
public void IsAssemblyReferenceReturnsFalseIfFileIsNotListedInReferences() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.Core.dll" }; IEnumerable <string> references = new[] { "NuGet.VisualStudio.dll", "NuGet.CommandLine.dll" }; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
private void WatchPhysicalFile(PhysicalPackageFile physicalFile) { string folderPath = System.IO.Path.GetDirectoryName(physicalFile.SourcePath); string fileName = System.IO.Path.GetFileName(physicalFile.SourcePath); _watcher = new FileSystemWatcher(folderPath, fileName) { IncludeSubdirectories = false, EnableRaisingEvents = true }; _watcher.Changed += OnFileChanged; _watcher.Deleted += OnFileDeleted; _watcher.Renamed += OnFileDeleted; }
protected virtual bool GeneratePackage(string nupkg, List <DiagnosticMessage> packDiagnostics) { foreach (var sharedFile in Project.Files.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = Path.Combine("shared", Path.GetFileName(sharedFile)); PackageBuilder.Files.Add(file); } if (Project.PackOptions.PackInclude != null) { var files = IncludeFilesResolver.GetIncludeFiles( Project.PackOptions.PackInclude, "/", diagnostics: packDiagnostics); PackageBuilder.Files.AddRange(GetPackageFiles(files, packDiagnostics)); } else if (Project.Files.PackInclude != null && Project.Files.PackInclude.Any()) { AddPackageFiles(Project.Files.PackInclude, packDiagnostics); } // Write the packages as long as we're still in a success state. if (!packDiagnostics.Any(d => d.Severity == DiagnosticMessageSeverity.Error)) { Reporter.Verbose.WriteLine($"Adding package files"); foreach (var file in PackageBuilder.Files.OfType <PhysicalPackageFile>()) { if (file.SourcePath != null && File.Exists(file.SourcePath)) { Reporter.Verbose.WriteLine($"Adding {file.Path.Yellow()}"); } } Directory.CreateDirectory(Path.GetDirectoryName(nupkg)); using (var fs = File.Create(nupkg)) { PackageBuilder.Save(fs); Reporter.Output.WriteLine($"{Project.Name} -> {Path.GetFullPath(nupkg)}"); } return(true); } return(false); }
private void AddFileToBuilder(PackageBuilder builder, PhysicalPackageFile packageFile) { if (!builder.Files.Any(p => packageFile.Path == p.Path)) { WriteDetail(NuGetResources.AddFileToPackage, packageFile.SourcePath, packageFile.TargetPath); builder.Files.Add(packageFile); } else { _logger.Log( MessageLevel.Warning, NuGetResources.FileNotAddedToPackage, packageFile.SourcePath, packageFile.TargetPath); } }
private void AddFileToBuilder(PackageBuilder builder, PhysicalPackageFile packageFile) { if (!builder.Files.Any(p => packageFile.Path.Equals(p.Path, StringComparison.OrdinalIgnoreCase))) { WriteDetail(LocalizedResourceManager.GetString("AddFileToPackage"), packageFile.SourcePath, packageFile.TargetPath); builder.Files.Add(packageFile); } else { _logger.Log( MessageLevel.Warning, LocalizedResourceManager.GetString("FileNotAddedToPackage"), packageFile.SourcePath, packageFile.TargetPath); } }
public void ExportGame() { if (!SerializeXmlAssets()) { return; } var builder = new PackageBuilder() { Id = Game.Id.ToString(), Description = Game.Description, ProjectUrl = new Uri(Game.GameUrl), Version = new NuGetVersion(Game.Version), Title = Game.Name, IconUrl = new Uri(Game.IconUrl), }; foreach (var a in Game.Authors) { builder.Authors.Add(a); } foreach (var t in Game.Tags) { builder.Authors.Add(t); } var baseRefPath = "\\def"; foreach (var asset in ViewModelLocator.AssetsTabViewModel.Assets.Where(x => x.IsLinked)) { var refpath = baseRefPath + "\\" + asset.RelativePath; var pf = new PhysicalPackageFile() { SourcePath = asset.SafeFilePath, TargetPath = refpath }; builder.Files.Add(pf); } var feedPath = Path.Combine(WorkingDirectory.FullName, Game.Name + '-' + Game.Version + ".nupkg"); var filestream = File.Open(feedPath, FileMode.Create, FileAccess.ReadWrite, FileShare.None); builder.Save(filestream); filestream.Flush(true); filestream.Close(); Process.Start(WorkingDirectory.FullName); }
public void AddFile(PackageFile file, bool makeCopy = false) { if (file == null) { throw new ArgumentNullException("file"); } if (Contains(file)) { return; } PackagePart newFile; if (makeCopy) { string fileCopyPath; using (Stream originalFileStream = file.GetStream()) { fileCopyPath = FileHelper.CreateTempFile(file.Name, originalFileStream); } string newTargetPath = this.Path + "\\" + file.Name; var physicalFile = new PhysicalPackageFile { SourcePath = fileCopyPath, TargetPath = newTargetPath }; newFile = new PackageFile(physicalFile, file.Name, this); } else { // detach from current parent if (file.Parent != null) { file.Parent.Detach(file); } newFile = file; } Attach(newFile); newFile.IsSelected = true; IsExpanded = true; PackageViewModel.NotifyChanges(); }
private static bool GeneratePackage(Project project, PackageBuilder packageBuilder, string nupkg, List <DiagnosticMessage> packDiagnostics) { foreach (var sharedFile in project.Files.SharedFiles) { var file = new PhysicalPackageFile(); file.SourcePath = sharedFile; file.TargetPath = Path.Combine("shared", Path.GetFileName(sharedFile)); packageBuilder.Files.Add(file); } var root = project.ProjectDirectory; if (project.Files.PackInclude != null && project.Files.PackInclude.Any()) { AddPackageFiles(project, project.Files.PackInclude, packageBuilder, packDiagnostics); } // Write the packages as long as we're still in a success state. if (!packDiagnostics.Any(d => d.Severity == DiagnosticMessageSeverity.Error)) { Reporter.Verbose.WriteLine($"Adding package files"); foreach (var file in packageBuilder.Files.OfType <PhysicalPackageFile>()) { if (file.SourcePath != null && File.Exists(file.SourcePath)) { Reporter.Verbose.WriteLine($"Adding {file.Path.Yellow()}"); } } Directory.CreateDirectory(Path.GetDirectoryName(nupkg)); using (var fs = File.Create(nupkg)) { packageBuilder.Save(fs); Reporter.Output.WriteLine($"{project.Name} -> {Path.GetFullPath(nupkg)}"); } return(true); } return(false); }
public void ProjectFactoryCanCompareContentsOfReadOnlyFile() { var us = Assembly.GetExecutingAssembly(); var sourcePath = us.Location; var targetFile = new PhysicalPackageFile { SourcePath = sourcePath }; var fullPath = sourcePath + "readOnly"; File.Copy(sourcePath, fullPath); File.SetAttributes(fullPath, FileAttributes.ReadOnly); try { var actual = ProjectFactory.ContentEquals(targetFile, fullPath); Assert.Equal(true, actual); } finally { File.SetAttributes(fullPath, FileAttributes.Normal); File.Delete(fullPath); } }
private void AddPackage(IPackageManager manager, string id, string version, string payloadAssemblyFilePath) { PackageBuilder builder = new PackageBuilder(); builder.Id = id; builder.Version = new SemanticVersion(version); builder.Description = "dummy description"; builder.Authors.Add("dummy author"); PhysicalPackageFile file = new PhysicalPackageFile(); file.SourcePath = payloadAssemblyFilePath; file.TargetPath = "analyzers/" + Path.GetFileName(payloadAssemblyFilePath); builder.Files.Add(file); using (MemoryStream stream = new MemoryStream()) { builder.Save(stream); stream.Position = 0; ZipPackage pkg = new ZipPackage(stream); manager.InstallPackage(pkg, true, true); } }
private void AddOutputFiles(PackageBuilder builder) { // Get the target framework of the project FrameworkName targetFramework = TargetFramework; // Get the target file path string targetPath = TargetPath; // List of extensions to allow in the output path var allowedOutputExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { ".dll", ".exe", ".xml", ".winmd" }; if (IncludeSymbols) { // Include pdbs for symbol packages allowedOutputExtensions.Add(".pdb"); } string projectOutputDirectory = Path.GetDirectoryName(targetPath); string targetFileName = Path.GetFileNameWithoutExtension(targetPath); // By default we add all files in the project's output directory foreach (var file in GetFiles(projectOutputDirectory, targetFileName, allowedOutputExtensions)) { { string extension = Path.GetExtension(file); // Only look at files we care about if (!allowedOutputExtensions.Contains(extension)) { continue; } string targetFolder; if (IsTool) { targetFolder = ToolsFolder; } else { if (targetFramework == null) { targetFolder = ReferenceFolder; } else { targetFolder = Path.Combine(ReferenceFolder, VersionUtility.GetShortFrameworkName(targetFramework)); } } var packageFile = new PhysicalPackageFile { SourcePath = file, TargetPath = Path.Combine(targetFolder, Path.GetFileName(file)) }; AddFileToBuilder(builder, packageFile); } } }
private void AddFiles(PackageBuilder builder, string itemType, string targetFolder) { // Skip files that are added by dependency packages string packagesConfig = GetPackagesConfig(); IPackageRepository repository = GetPackagesRepository(); var contentFilesInDependencies = new List<IPackageFile>(); if (packagesConfig != null && repository != null) { var references = new PackageReferenceFile(packagesConfig).GetPackageReferences(); contentFilesInDependencies = references.Select(reference => repository.FindPackage(reference.Id, reference.Version)) .Where(a => a != null) .SelectMany(a => a.GetContentFiles()) .ToList(); } // Get the content files from the project foreach (var item in _project.GetItems(itemType)) { string fullPath = item.GetMetadataValue("FullPath"); if (_excludeFiles.Contains(Path.GetFileName(fullPath))) { continue; } string targetFilePath = GetTargetPath(item); if (!File.Exists(fullPath)) { Logger.Log(MessageLevel.Warning, NuGetResources.Warning_FileDoesNotExist, targetFilePath); continue; } // Check that file is added by dependency string targetPath = Path.Combine(targetFolder, targetFilePath); IPackageFile targetFile = contentFilesInDependencies.Find(a => a.Path.Equals(targetPath, StringComparison.OrdinalIgnoreCase)); if (targetFile != null) { // Compare contents as well var isEqual = ContentEquals(targetFile, fullPath); if (isEqual) { Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsNotChanged, targetFilePath); continue; } Logger.Log(MessageLevel.Info, NuGetResources.PackageCommandFileFromDependencyIsChanged, targetFilePath); } var packageFile = new PhysicalPackageFile { SourcePath = fullPath, TargetPath = targetPath }; AddFileToBuilder(builder, packageFile); } }
public void IsAssemblyReferenceReturnsTrueForWinMDFileInLib() { // Arrange var file = new PhysicalPackageFile { TargetPath = PathFixUtility.FixPath(@"lib\NuGet.Core.WINMD") }; IEnumerable<string> references = null; // Act and Assert Assert.True(ZipPackage.IsAssemblyReference(file, references)); }
private void AddFiles(PackageBuilder builder, string itemType, string targetFolder) { // Skip files that are added by dependency packages var references = PackageReferenceFile.CreateFromProject(_project.FullPath).GetPackageReferences(); IPackageRepository repository = GetPackagesRepository(); string projectName = Path.GetFileNameWithoutExtension(_project.FullPath); var contentFilesInDependencies = new List<IPackageFile>(); if (references.Any() && repository != null) { contentFilesInDependencies = references.Select(reference => repository.FindPackage(reference.Id, reference.Version)) .Where(a => a != null) .SelectMany(a => a.GetContentFiles()) .ToList(); } // Get the content files from the project foreach (var item in _project.GetItems(itemType)) { string fullPath = item.GetMetadataValue("FullPath"); if (_excludeFiles.Contains(Path.GetFileName(fullPath))) { continue; } string targetFilePath = GetTargetPath(item); if (!File.Exists(fullPath)) { Logger.Log(MessageLevel.Warning, LocalizedResourceManager.GetString("Warning_FileDoesNotExist"), targetFilePath); continue; } // Skip target file paths containing msbuild variables since we do not offer a way to install files with variable paths. // These are show up in shared files found in universal apps. if (targetFilePath.IndexOf("$(MSBuild", StringComparison.OrdinalIgnoreCase) > -1) { Logger.Log(MessageLevel.Warning, LocalizedResourceManager.GetString("Warning_UnresolvedFilePath"), targetFilePath); continue; } // if IncludeReferencedProjects is true and we are adding source files, // add projectName as part of the target to avoid file conflicts. string targetPath = IncludeReferencedProjects && itemType == SourcesItemType ? Path.Combine(targetFolder, projectName, targetFilePath) : Path.Combine(targetFolder, targetFilePath); // Check that file is added by dependency IPackageFile targetFile = contentFilesInDependencies.Find(a => a.Path.Equals(targetPath, StringComparison.OrdinalIgnoreCase)); if (targetFile != null) { // Compare contents as well var isEqual = ContentEquals(targetFile, fullPath); if (isEqual) { Logger.Log(MessageLevel.Info, LocalizedResourceManager.GetString("PackageCommandFileFromDependencyIsNotChanged"), targetFilePath); continue; } Logger.Log(MessageLevel.Info, LocalizedResourceManager.GetString("PackageCommandFileFromDependencyIsChanged"), targetFilePath); } var packageFile = new PhysicalPackageFile { SourcePath = fullPath, TargetPath = targetPath }; AddFileToBuilder(builder, packageFile); } }
public void IsAssemblyReferenceReturnsTrueIfFileIsListedInReferences() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.Core.dll" }; IEnumerable<string> references = new[] { "NuGet.VisualStudio.dll", "NuGet.CommandLine.dll", "NuGet.Core.dll", }; // Act and Assert Assert.True(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsFalseIfFileIsAResourceAssembly() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.resources.dll" }; IEnumerable<string> references = null; // Act and Assert Assert.False(ZipPackage.IsAssemblyReference(file, references)); }
public void IsAssemblyReferenceReturnsTrueIfFileIsAReferenceItemInLib() { // Arrange var file = new PhysicalPackageFile { TargetPath = @"lib\NuGet.Core.dll" }; IEnumerable<string> references = null; // Act and Assert Assert.True(ZipPackage.IsAssemblyReference(file, references)); }