private bool ScanForProjects() { _logger.LogInformation(string.Format("Scanning '{0}' for DNX projects", _env.Path)); var anyProjects = false; // Single project in this folder var projectInThisFolder = Path.Combine(_env.Path, "project.json"); if (File.Exists(projectInThisFolder)) { if (_context.TryAddProject(projectInThisFolder)) { _logger.LogInformation(string.Format("Found project '{0}'.", projectInThisFolder)); anyProjects = true; } } else { IEnumerable<string> paths; #if DNX451 if (_options.Projects != "**/project.json") { var matcher = new Matcher(); matcher.AddIncludePatterns(_options.Projects.Split(';')); paths = matcher.GetResultsInFullPath(_env.Path); } else { paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json"); } #else // The matcher works on CoreCLR but Omnisharp still targets aspnetcore50 instead of // dnxcore50 paths = _directoryEnumerator.SafeEnumerateFiles(_env.Path, "project.json"); #endif foreach (var path in paths) { string projectFile = null; if (Path.GetFileName(path) == "project.json") { projectFile = path; } else { projectFile = Path.Combine(path, "project.json"); if (!File.Exists(projectFile)) { projectFile = null; } } if (string.IsNullOrEmpty(projectFile)) { continue; } if (!_context.TryAddProject(projectFile)) { continue; } _logger.LogInformation(string.Format("Found project '{0}'.", projectFile)); anyProjects = true; } } return anyProjects; }
internal static IEnumerable<PhysicalPackageFile> CollectAdditionalFiles(DirectoryInfoBase rootDirectory, IEnumerable<PackIncludeEntry> projectFileGlobs, string projectFilePath, IList<DiagnosticMessage> diagnostics) { foreach (var entry in projectFileGlobs) { // Evaluate the globs on the right var matcher = new Matcher(); matcher.AddIncludePatterns(entry.SourceGlobs); var results = matcher.Execute(rootDirectory); var files = results.Files.ToList(); // Check for illegal characters if (string.IsNullOrEmpty(entry.Target)) { diagnostics.Add(new DiagnosticMessage( DiagnosticMonikers.NU1003, $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. The target '{entry.Target}' is invalid, " + "targets must either be a file name or a directory suffixed with '/'. " + "The root directory of the package can be specified by using a single '/' character.", projectFilePath, DiagnosticMessageSeverity.Error, entry.Line, entry.Column)); continue; } if (entry.Target.Split('/').Any(s => s.Equals(".") || s.Equals(".."))) { diagnostics.Add(new DiagnosticMessage( DiagnosticMonikers.NU1004, $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " + $"The target '{entry.Target}' contains path-traversal characters ('.' or '..'). " + "These characters are not permitted in target paths.", projectFilePath, DiagnosticMessageSeverity.Error, entry.Line, entry.Column)); continue; } // Check the arity of the left if (entry.Target.EndsWith("/")) { var dir = entry.Target.Substring(0, entry.Target.Length - 1).Replace('/', Path.DirectorySeparatorChar); foreach (var file in files) { yield return new PhysicalPackageFile() { SourcePath = Path.Combine(rootDirectory.FullName, PathUtility.GetPathWithDirectorySeparator(file.Path)), TargetPath = Path.Combine(dir, PathUtility.GetPathWithDirectorySeparator(file.Stem)) }; } } else { // It's a file. If the glob matched multiple things, we're sad :( if (files.Count > 1) { // Arity mismatch! string sourceValue = entry.SourceGlobs.Length == 1 ? $"\"{entry.SourceGlobs[0]}\"" : ("[" + string.Join(",", entry.SourceGlobs.Select(v => $"\"{v}\"")) + "]"); diagnostics.Add(new DiagnosticMessage( DiagnosticMonikers.NU1005, $"Invalid '{ProjectFilesCollection.PackIncludePropertyName}' section. " + $"The target '{entry.Target}' refers to a single file, but the pattern {sourceValue} " + "produces multiple files. To mark the target as a directory, suffix it with '/'.", projectFilePath, DiagnosticMessageSeverity.Error, entry.Line, entry.Column)); } else { yield return new PhysicalPackageFile() { SourcePath = Path.Combine(rootDirectory.FullName, files[0].Path), TargetPath = PathUtility.GetPathWithDirectorySeparator(entry.Target) }; } } } }
private async Task SendProjectAsync(EnvDTE.Project project, string remotePath, string filterString, CancellationToken cancellationToken) { ProgressOutputWriter.WriteLine(Resources.Info_PreparingProjectForTransfer); var projectDir = Path.GetDirectoryName(project.FullName); var projectName = Path.GetFileNameWithoutExtension(project.FullName); string[] filterSplitter = { ";" }; Matcher matcher = new Matcher(StringComparison.InvariantCultureIgnoreCase); matcher.AddIncludePatterns(filterString.Split(filterSplitter, StringSplitOptions.RemoveEmptyEntries)); ProgressOutputWriter.WriteLine(Resources.Info_RemoteDestination.FormatInvariant(remotePath)); ProgressOutputWriter.WriteLine(Resources.Info_FileTransferFilter.FormatInvariant(filterString)); ProgressOutputWriter.WriteLine(Resources.Info_CompressingFiles); var compressedFilePath = FileSystem.CompressDirectory(projectDir, matcher, new Progress<string>((p) => { ProgressOutputWriter.WriteLine(Resources.Info_LocalFilePath.FormatInvariant(p)); string dest = p.MakeRelativePath(projectDir).ProjectRelativePathToRemoteProjectPath(remotePath, projectName); ProgressOutputWriter.WriteLine(Resources.Info_RemoteFilePath.FormatInvariant(dest)); }), CancellationToken.None); using (var fts = new DataTransferSession(Session, FileSystem)) { ProgressOutputWriter.WriteLine(Resources.Info_TransferringFiles); var remoteFile = await fts.SendFileAsync(compressedFilePath, true, null, cancellationToken); await Session.EvaluateAsync<string>($"rtvs:::save_to_project_folder({remoteFile.Id}, {projectName.ToRStringLiteral()}, '{remotePath.ToRPath()}')", REvaluationKind.Normal, cancellationToken); } ProgressOutputWriter.WriteLine(Resources.Info_TransferringFilesDone); }