/// <summary> /// Normalizes specified source path with respect to base file path. /// /// This is the first method that can be called for each reference /// </summary> /// <param name="path">The source path to normalize. May be absolute or relative.</param> /// <param name="baseFilePath">Path of the source file that contains the <paramref name="path"/> (may also be relative), or null if not available.</param> /// <returns>Normalized path, or null if <paramref name="path"/> can't be normalized. The resulting path doesn't need to exist.</returns> /// <remarks> /// "Normalize" is a short word for what the underlying bits are doing here. MS should make the internal FileUtilities /// public - its vast and has a lot of useful things. /// </remarks> public override string NormalizePath(string path, string baseFilePath) { var candidateType = GetResolutionTargetType(path); var normalizedPath = _sourceFileResolver.NormalizePath(path, baseFilePath); // return normalizedPath; if (candidateType != ResolutionTargetType.Cs) { return(normalizedPath); } var csFilePath = CsRewriter.GetRewriteFilePath(normalizedPath); return(csFilePath); }
/// <summary> /// Opens a <see cref="T:System.IO.Stream" /> that allows reading the content of the specified file. /// </summary> /// <param name="resolvedPath">Path returned by <see cref="M:Microsoft.CodeAnalysis.SourceReferenceResolver.ResolveReference(System.String,System.String)" />.</param> /// <returns></returns> public override Stream OpenRead(string resolvedPath) { var candidateType = GetResolutionTargetType(resolvedPath); if (candidateType != ResolutionTargetType.Cs) { return(_sourceFileResolver.OpenRead(resolvedPath)); } if (_rewrittenSources.ContainsKey(resolvedPath)) { return(GetStream(_rewrittenSources[resolvedPath])); } var csExtract = CsRewriter.ExtractCompilationDetailFromClassFile(resolvedPath); if (csExtract.Errors.Any()) { var errString = string.Join(",", csExtract.Errors); throw new InvalidOperationException($"Failed to get compilaitonTargets. {errString}"); } var cs = csExtract.CompilationTargets.First(); //foreach (var mra in csExtract.MetadataReferenceAssemblies) //{ // _dirtyRefs.Add(Assembly.LoadFile(mra.Display)); //} var sourceText = cs.GetText(); _rewrittenSources.Add(resolvedPath, sourceText); var diagFile = CsRewriter.GetRewriteFilePath(resolvedPath); WriteSourceText(sourceText, diagFile); return(GetStream(sourceText)); }