Example #1
0
        private IEnumerable <MetadataReference> CreateMetadataReferences()
        {
            var manager     = this.Services.GetService <VisualStudioMetadataReferenceManager>();
            var searchPaths = ReferencePathUtilities.GetReferencePaths();

            return(from fileName in new[] { "mscorlib.dll", "System.dll", "System.Core.dll" }
                   let fullPath = FileUtilities.ResolveRelativePath(fileName, basePath: null, baseDirectory: null, searchPaths: searchPaths, fileExists: File.Exists)
                                  where fullPath != null
                                  select manager.CreateMetadataReferenceSnapshot(fullPath, MetadataReferenceProperties.Assembly));
        }
 private static ImmutableArray <string> GetRuntimeDirectories()
 {
     return(ReferencePathUtilities.GetReferencePaths().Concat(
                new string[]
     {
         Environment.GetFolderPath(Environment.SpecialFolder.Windows),
         Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
         Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
         RuntimeEnvironment.GetRuntimeDirectory()
     }).Select(FileUtilities.NormalizeDirectoryPath).ToImmutableArray());
 }
            protected override DocumentationProvider CreateDocumentationProvider()
            {
                string xmlDocumentPath;

                if (ReferencePathUtilities.TryFindXmlDocumentationFile(FilePath, out xmlDocumentPath))
                {
                    return(new VisualStudioDocumentationProvider(xmlDocumentPath, _provider.XmlMemberIndexService));
                }
                else
                {
                    return(DocumentationProvider.Default);
                }
            }
Example #4
0
        public bool Serializable(Solution solution, string assemblyFilePath)
        {
            if (assemblyFilePath == null || !File.Exists(assemblyFilePath) || !ReferencePathUtilities.PartOfFrameworkOrReferencePaths(assemblyFilePath))
            {
                return(false);
            }

            // if solution is not from a disk, just create one.
            if (solution.FilePath == null || !File.Exists(solution.FilePath))
            {
                return(false);
            }

            return(true);
        }
        private CacheEntry <MetadataShadowCopy> CreateMetadataShadowCopy(string originalPath, MetadataImageKind kind)
        {
            int attempts = 10;

            while (true)
            {
                try
                {
                    if (ShadowCopyDirectory == null)
                    {
                        ShadowCopyDirectory = CreateUniqueDirectory(_baseDirectory);
                    }

                    // Create directory for the assembly.
                    // If the assembly has any modules they have to be copied to the same directory
                    // and have the same names as specified in metadata.
                    string assemblyDir    = CreateUniqueDirectory(ShadowCopyDirectory);
                    string shadowCopyPath = Path.Combine(assemblyDir, Path.GetFileName(originalPath));

                    ShadowCopy documentationFileCopy = null;
                    string     xmlOriginalPath;
                    if (ReferencePathUtilities.TryFindXmlDocumentationFile(originalPath, out xmlOriginalPath))
                    {
                        // TODO (tomat): how do doc comments work for multi-module assembly?
                        var xmlCopyPath = Path.ChangeExtension(shadowCopyPath, ".xml");
                        var xmlStream   = CopyFile(xmlOriginalPath, xmlCopyPath, fileMayNotExist: true);
                        if (xmlStream != null)
                        {
                            documentationFileCopy = new ShadowCopy(xmlStream, xmlOriginalPath, xmlCopyPath);
                        }
                    }

                    var manifestModuleCopyStream = CopyFile(originalPath, shadowCopyPath);
                    var manifestModuleCopy       = new ShadowCopy(manifestModuleCopyStream, originalPath, shadowCopyPath);

                    Metadata privateMetadata;
                    if (kind == MetadataImageKind.Assembly)
                    {
                        privateMetadata = CreateAssemblyMetadata(manifestModuleCopyStream, originalPath, shadowCopyPath);
                    }
                    else
                    {
                        privateMetadata = CreateModuleMetadata(manifestModuleCopyStream);
                    }

                    var publicMetadata = privateMetadata.Copy();
                    return(new CacheEntry <MetadataShadowCopy>(new MetadataShadowCopy(manifestModuleCopy, documentationFileCopy, publicMetadata), privateMetadata));
                }
                catch (DirectoryNotFoundException)
                {
                    // the shadow copy directory has been deleted - try to copy all files again
                    if (!Directory.Exists(ShadowCopyDirectory))
                    {
                        ShadowCopyDirectory = null;
                        if (attempts-- > 0)
                        {
                            continue;
                        }
                    }

                    throw;
                }
            }
        }