예제 #1
0
        private static async Task <HashSet <string> > GetWebsiteLocalAssembliesAsync(EnvDTE.Project envDTEProject)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            var assemblies = new HashSet <string>(PathComparer.Default);
            var references = GetAssemblyReferences(envDTEProject);

            foreach (AssemblyReference reference in references)
            {
                // For websites only include bin assemblies
                if (reference.ReferencedProject == null
                    &&
                    reference.ReferenceKind == AssemblyReferenceType.AssemblyReferenceBin
                    &&
                    File.Exists(reference.FullPath))
                {
                    assemblies.Add(reference.FullPath);
                }
            }

            // For website projects, we always add .refresh files that point to the corresponding binaries in packages. In the event of bin deployed assemblies that are also GACed,
            // the ReferenceKind is not AssemblyReferenceBin. Consequently, we work around this by looking for any additional assembly declarations specified via .refresh files.
            var envDTEProjectPath = await envDTEProject.GetFullPathAsync();

            CollectionsUtility.AddRange(assemblies, RefreshFileUtility.ResolveRefreshPaths(envDTEProjectPath));

            return(assemblies);
        }
예제 #2
0
        // Get the ProjectItems for a folder path
        public static async Task <EnvDTE.ProjectItems> GetProjectItemsAsync(EnvDTE.Project envDTEProject, string folderPath, bool createIfNotExists)
        {
            await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (string.IsNullOrEmpty(folderPath))
            {
                return(envDTEProject.ProjectItems);
            }

            // Traverse the path to get at the directory
            var pathParts = folderPath.Split(PathSeparatorChars, StringSplitOptions.RemoveEmptyEntries);

            // 'cursor' can contain a reference to either a Project instance or ProjectItem instance.
            // Both types have the ProjectItems property that we want to access.
            object cursor = envDTEProject;

            var fullPath = await envDTEProject.GetFullPathAsync();

            var folderRelativePath = string.Empty;

            foreach (var part in pathParts)
            {
                fullPath           = Path.Combine(fullPath, part);
                folderRelativePath = Path.Combine(folderRelativePath, part);

                cursor = await GetOrCreateFolderAsync(envDTEProject, cursor, fullPath, folderRelativePath, part, createIfNotExists);

                if (cursor == null)
                {
                    return(null);
                }
            }

            return(GetProjectItems(cursor));
        }