public FileSystemPath Resolve(string assemblyNameOrFile, IPsiSourceFile sourceFile)
        {
            var projectFile = sourceFile.ToProjectFile();

            if (projectFile == null)
            {
                return(null);
            }
            var path = new T4ResolvedPath(assemblyNameOrFile, sourceFile, projectFile);

            return(Resolve(path));
        }
        protected FileSystemPath ResolveAsAssemblyFile([NotNull] T4ResolvedPath pathWithMacros)
        {
            string name = pathWithMacros.ResolvedPath;
            string nameWithoutExtension = TryRemoveBinaryExtension(name);

            if (nameWithoutExtension == null)
            {
                return(null);
            }
            string fileName = name.Substring(0, name.Length - 4);

            return(ResolveAssemblyNameOrFile(pathWithMacros.ProjectFile, fileName));
        }
示例#3
0
        private bool TryAddReference([NotNull] T4ResolvedPath pathWithMacros)
        {
            var path = AssemblyReferenceResolver.ResolveWithoutCaching(pathWithMacros);

            if (path == null)
            {
                return(false);
            }
            if (MyAssemblyReferences.ContainsKey(path))
            {
                return(false);
            }
            if (MyProjectReferences.ContainsKey(path))
            {
                return(false);
            }
            return(TryAddProjectReference(path) || TryAddAssemblyReference(path));
        }
示例#4
0
        public override FileSystemPath TryResolve(T4ResolvedPath path)
        {
            var absolutePath = path.TryResolveAbsolutePath();

            if (absolutePath != null)
            {
                return(absolutePath);
            }
            // Maybe the assembly name is missing extension?
            var pathWithExtension = path.ProjectFile.ParentFolder?.Location.TryCombine(path.ResolvedPath + ".dll");

            if (pathWithExtension == null)
            {
                return(null);
            }
            if (pathWithExtension.ExistsFile)
            {
                return(pathWithExtension);
            }
            return(null);
        }
示例#5
0
        private VirtualFileSystemPath TryResolve([NotNull] T4ResolvedPath resolvedPath)
        {
            var asAbsolute = resolvedPath.TryResolveAbsolutePath();

            if (asAbsolute != null)
            {
                return(asAbsolute);
            }
            string resolved = Components.Value.CanBeNull?.Host?.ResolveAssemblyReference(resolvedPath.ResolvedPath);

            if (resolved == null)
            {
                return(null);
            }
            var path = VirtualFileSystemPath.Parse(resolved, InteractionContext.SolutionContext);

            if (path.IsAbsolute)
            {
                return(path);
            }
            return(null);
        }
示例#6
0
        private bool TryRemoveReference([NotNull] T4ResolvedPath pathWithMacros)
        {
            var path = AssemblyReferenceResolver.ResolveWithoutCaching(pathWithMacros);

            if (path == null)
            {
                return(false);
            }
            if (MyAssemblyReferences.TryGetValue(path, out var cookie))
            {
                MyAssemblyReferences.Remove(path);
                cookie.Dispose();
                return(true);
            }

            if (MyProjectReferences.ContainsKey(path))
            {
                MyProjectReferences.Remove(path);
                return(true);
            }

            return(false);
        }
        public void InitializeResolvedPath(
            IReadOnlyDictionary <string, string> resolveResults,
            IPsiSourceFile sourceFile,
            IProjectFile projectFile
            )
        {
            string expanded = Environment.ExpandEnvironmentVariables(RawPath ?? "");
            string result   = MacroRegex.Replace(expanded, match =>
            {
                var group    = match.Groups[1];
                string macro = group.Value;
                if (!group.Success)
                {
                    return(macro);
                }
                if (!resolveResults.TryGetValue(macro, out string value))
                {
                    return(macro);
                }
                return(value);
            });

            MyResolvedPath = new T4ResolvedPath(result, sourceFile, projectFile);
        }
示例#8
0
 public VirtualFileSystemPath ResolveWithoutCaching([NotNull] T4ResolvedPath path)
 {
     using var _ = Prepare(path.ProjectFile);
     return(TryResolve(path));
 }
示例#9
0
 public override VirtualFileSystemPath Resolve(T4ResolvedPath pathWithMacros) =>
 base.Resolve(pathWithMacros) ?? ResolveAsDte(pathWithMacros.ResolvedPath);
 protected FileSystemPath ResolveAsAssemblyName([NotNull] T4ResolvedPath pathWithMacros) =>
 ResolveAssemblyNameOrFile(pathWithMacros.ProjectFile, pathWithMacros.ResolvedPath);
 private FileSystemPath ResolveAsLightReference([NotNull] T4ResolvedPath pathWithMacros) =>
 LightWeightResolver.TryResolve(pathWithMacros);
 public virtual FileSystemPath ResolveWithoutCaching(T4ResolvedPath path) => Resolve(path);
 public FileSystemPath Resolve(T4ResolvedPath path) =>
 ResolveAsLightReference(path)
 ?? ResolveAsAssemblyName(path)
 ?? ResolveAsAssemblyFile(path);
 public virtual VirtualFileSystemPath TryResolve(T4ResolvedPath path) => null;