private void HandleMSBuildProject(
            object context,
            IProjectContextProvider contextProvider,
            HashSet <ProjectInfo> added,
            HashSet <string> seen
            )
        {
            var projContext = context as MSBuild.Project;

            if (projContext == null)
            {
                var projectFile = context as string;
                if (projectFile != null && projectFile.EndsWith(".pyproj", StringComparison.OrdinalIgnoreCase))
                {
                    projContext = new MSBuild.Project(projectFile);
                }
            }

            if (projContext != null)
            {
                if (!_projects.ContainsKey(projContext.FullPath))
                {
                    var projInfo = new MSBuildProjectInfo(projContext, projContext.FullPath, contextProvider);
                    _projects[projContext.FullPath] = projInfo;
                    added.Add(projInfo);
                }
                seen.Add(projContext.FullPath);
            }
        }
Beispiel #2
0
        Task <object> IProjectSystem.GetProjectModelAsync(string filePath)
        {
            var document = _workspace.GetDocument(filePath);

            var projectFilePath = document != null
                ? document.Project.FilePath
                : filePath;

            var projectFileInfo = GetProjectFileInfo(projectFilePath);

            if (projectFileInfo == null)
            {
                _logger.LogDebug($"Could not locate project for '{projectFilePath}'");
                return(Task.FromResult <object>(null));
            }

            var info = new MSBuildProjectInfo(projectFileInfo);

            return(Task.FromResult <object>(info));
        }
Beispiel #3
0
        public async Task TestProjectWithSignedReferencedProject()
        {
            using (ITestProject testProject = await TestAssets.Instance.GetTestProjectAsync("SolutionWithSignedProject"))
                using (OmniSharpTestHost host = CreateOmniSharpHost(Path.Combine(testProject.Directory)))
                {
                    MSBuildWorkspaceInfo workspaceInfo = await GetWorkspaceInfoAsync(host);

                    Assert.NotNull(workspaceInfo.Projects);
                    Assert.Equal(2, workspaceInfo.Projects.Count);

                    // For the test to validate that assemblies representing targets of loaded projects are being skipped,
                    // the assemblies must be present on disk.
                    foreach (MSBuildProjectInfo loadedProject in workspaceInfo.Projects)
                    {
                        Assert.True(File.Exists(loadedProject.TargetPath),
                                    $"Project target assembly is not found {loadedProject.TargetPath}. " +
                                    $"Make sure to build the whole repo using the build script before running the test.");
                    }

                    // The callee assembly must be signed to ensure that in case of a bug the assembly is loaded
                    // "The type 'Callee' exists in both ..." is present as a code check (which is validated below).
                    MSBuildProjectInfo signedProject = workspaceInfo.Projects.SingleOrDefault(p => p.AssemblyName.Equals("CalleeLib", StringComparison.OrdinalIgnoreCase));
                    Assert.NotNull(signedProject);
                    string token = BitConverter.ToString(AssemblyName.GetAssemblyName(signedProject.TargetPath).GetPublicKeyToken());
                    Assert.Equal("A5-D8-5A-5B-AA-39-A6-A6", token, ignoreCase: true);

                    QuickFixResponse quickFixResponse = await GetCodeChecksync(host, Path.Combine(testProject.Directory, "CallerLib\\Caller.cs"));

                    // Log result to easier debugging of the test should it fail during automated valdiation
                    foreach (QuickFix fix in quickFixResponse.QuickFixes)
                    {
                        host.Logger.LogInformation($"Unexpected QuickFix returned for {fix.FileName}: {fix.Text}");
                    }

                    Assert.Empty(quickFixResponse.QuickFixes);
                }
        }
        private void Provider_ProjectContextsChanged(object sender, EventArgs e)
        {
            var  contextProvider = (IProjectContextProvider)sender;
            bool discovered      = false;

            if (contextProvider != null)
            {
                // Run through and and get the new interpreters to add...
                HashSet <string>      seen    = new HashSet <string>();
                HashSet <ProjectInfo> added   = new HashSet <ProjectInfo>();
                HashSet <ProjectInfo> removed = new HashSet <ProjectInfo>();
                var contexts = contextProvider.Projects;
                lock (_projects) {
                    foreach (var context in contextProvider.Projects)
                    {
                        var projContext = context as MSBuild.Project;
                        if (projContext == null)
                        {
                            var projectFile = context as string;
                            if (projectFile != null && projectFile.EndsWith(".pyproj", StringComparison.OrdinalIgnoreCase))
                            {
                                projContext = new MSBuild.Project(projectFile);
                            }
                        }

                        if (projContext != null)
                        {
                            if (!_projects.ContainsKey(projContext.FullPath))
                            {
                                var projInfo = new MSBuildProjectInfo(projContext, projContext.FullPath, contextProvider);
                                _projects[projContext.FullPath] = projInfo;
                                added.Add(projInfo);
                            }
                            seen.Add(projContext.FullPath);
                        }

                        var inMemory = context as InMemoryProject;
                        if (inMemory != null)
                        {
                            if (!_projects.ContainsKey(inMemory.FullPath))
                            {
                                var projInfo = new InMemoryProjectInfo(inMemory, inMemory.FullPath, contextProvider);
                                _projects[inMemory.FullPath] = projInfo;
                                added.Add(projInfo);
                            }
                            seen.Add(inMemory.FullPath);
                        }
                    }

                    // Then remove any existing projects that are no longer there
                    var toRemove = _projects
                                   .Where(x => x.Value.ContextProvider == contextProvider && !seen.Contains(x.Key))
                                   .Select(x => x.Key)
                                   .ToArray();

                    foreach (var projInfo in toRemove)
                    {
                        var value = _projects[projInfo];
                        _projects.Remove(projInfo);
                        removed.Add(value);
                        value.Dispose();
                    }
                }

                // apply what we discovered without the projects lock...
                foreach (var projInfo in added)
                {
                    discovered |= DiscoverInterpreters(projInfo);
                }

                foreach (var projInfo in removed)
                {
                    projInfo.Dispose();
                    if (projInfo.Factories.Count > 0)
                    {
                        discovered = true;
                    }
                }
            }

            if (discovered)
            {
                OnInterpreterFactoriesChanged();
            }
        }
Beispiel #5
0
        private void HandleMSBuildProject(
            object context,
            IProjectContextProvider contextProvider,
            HashSet<ProjectInfo> added,
            HashSet<string> seen
            )
        {
            var projContext = context as MSBuild.Project;
            if (projContext == null) {
                var projectFile = context as string;
                if (projectFile != null && projectFile.EndsWith(".pyproj", StringComparison.OrdinalIgnoreCase)) {
                    projContext = new MSBuild.Project(projectFile);
                }
            }

            if (projContext != null) {
                if (!_projects.ContainsKey(projContext.FullPath)) {
                    var projInfo = new MSBuildProjectInfo(projContext, projContext.FullPath, contextProvider);
                    _projects[projContext.FullPath] = projInfo;
                    added.Add(projInfo);
                }
                seen.Add(projContext.FullPath);
            }
        }