public async Task LoadOnDemandProjectAndItsReference() { var configData = new Dictionary <string, string> { [$"MsBuild:{nameof(MSBuildOptions.LoadProjectsOnDemand)}"] = "true" }.ToConfiguration(); using (var testProject = await TestAssets.Instance.GetTestProjectAsync("TwoProjectsWithSolution")) using (var host = CreateMSBuildTestHost(testProject.Directory, configurationData: configData)) { MSBuildWorkspaceInfo workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); // Expect empty workspace initially since no documents have been requested yet Assert.Null(workspaceInfo.SolutionPath); Assert.NotNull(workspaceInfo.Projects); Assert.Equal(0, workspaceInfo.Projects.Count); // Requesting app document should load both projects MembersAsTreeService membersAsTreeService = host.GetRequestHandler <MembersAsTreeService>(OmniSharpEndpoints.MembersTree); var request = new MembersTreeRequest { FileName = Path.Combine(testProject.Directory, "App", "Program.cs") }; FileMemberTree response = await membersAsTreeService.Handle(request); workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); Assert.NotNull(request); Assert.Null(workspaceInfo.SolutionPath); Assert.NotNull(workspaceInfo.Projects); Assert.Equal(2, workspaceInfo.Projects.Count); Assert.Equal("App.csproj", Path.GetFileName(workspaceInfo.Projects[0].Path)); Assert.Equal("Lib.csproj", Path.GetFileName(workspaceInfo.Projects[1].Path)); } }
Task <object> IProjectSystem.GetWorkspaceModelAsync(WorkspaceInformationRequest request) { var info = new MSBuildWorkspaceInfo( _solutionFileOrRootPath, _projects, excludeSourceFiles: request?.ExcludeSourceFiles ?? false); return(Task.FromResult <object>(info)); }
public async Task LoadOnDemandProjectsOneByOne() { var configData = new Dictionary <string, string> { [$"MsBuild:{nameof(MSBuildOptions.LoadProjectsOnDemand)}"] = "true" }; using (var testProject = await TestAssets.Instance.GetTestProjectAsync("TwoProjectsWithSolution")) using (var host = CreateMSBuildTestHost(testProject.Directory, configurationData: configData.ToConfiguration())) { MSBuildWorkspaceInfo workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); // Expect empty workspace initially since no documents have been requested yet Assert.Null(workspaceInfo.SolutionPath); Assert.NotNull(workspaceInfo.Projects); Assert.Equal(0, workspaceInfo.Projects.Count); // Requesting library document should load only that project GetCodeActionsService codeActionHandler = host.GetRequestHandler <GetCodeActionsService>(OmniSharpEndpoints.V2.GetCodeActions); GetCodeActionsResponse codeActionResponse = await codeActionHandler.Handle( new GetCodeActionsRequest { FileName = Path.Combine(testProject.Directory, "Lib", "Class1.cs") }); workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); Assert.NotNull(codeActionResponse); Assert.Null(workspaceInfo.SolutionPath); Assert.NotNull(workspaceInfo.Projects); Assert.Equal(1, workspaceInfo.Projects.Count); Assert.Equal("Lib.csproj", Path.GetFileName(workspaceInfo.Projects[0].Path)); // Requesting app document should load that project as well QuickFixResponse codeCheckResponse = await host.RequestCodeCheckAsync(Path.Combine(testProject.Directory, "App", "Program.cs")); workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); Assert.NotNull(codeCheckResponse); Assert.Null(workspaceInfo.SolutionPath); Assert.NotNull(workspaceInfo.Projects); Assert.Equal(2, workspaceInfo.Projects.Count); Assert.Equal("App.csproj", Path.GetFileName(workspaceInfo.Projects[0].Path)); Assert.Equal("Lib.csproj", Path.GetFileName(workspaceInfo.Projects[1].Path)); } }
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); } }