From 203c33ec06fed9f791095705648a0625023b8c9f Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Thu, 10 Feb 2022 16:22:21 -0800 Subject: [PATCH] Port AbstractUpdateProjectTest and derived to the new integration test project Closes #44301 --- .../CSharpUpdateProjectToAllowUnsafe.cs | 111 ----------------- .../AbstractUpgradeProjectTest.cs} | 22 ++-- .../CSharpUpdateProjectToAllowUnsafe.cs | 114 ++++++++++++++++++ .../CSharp/CSharpUpgradeProject.cs | 95 ++++++++------- .../InProcess/SolutionExplorerInProcess.cs | 43 ++++++- .../InProcess/SolutionExplorer_InProc.cs | 12 -- .../SolutionExplorer_OutOfProc.cs | 6 - 7 files changed, 210 insertions(+), 193 deletions(-) delete mode 100644 src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs rename src/VisualStudio/IntegrationTest/{IntegrationTests/AbstractUpdateProjectTest.cs => New.IntegrationTests/AbstractUpgradeProjectTest.cs} (67%) create mode 100644 src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs rename src/VisualStudio/IntegrationTest/{IntegrationTests => New.IntegrationTests}/CSharp/CSharpUpgradeProject.cs (51%) diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs b/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs deleted file mode 100644 index 7856319c5d6f9..0000000000000 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs +++ /dev/null @@ -1,111 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#nullable disable - -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.VisualStudio.IntegrationTest.Utilities; -using Roslyn.Test.Utilities; -using Xunit; -using Xunit.Abstractions; -using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils; - -namespace Roslyn.VisualStudio.IntegrationTests.CSharp -{ - [Collection(nameof(SharedIntegrationHostFixture))] - public class CSharpUpdateProjectToAllowUnsafe : AbstractUpdateProjectTest - { - public CSharpUpdateProjectToAllowUnsafe(VisualStudioInstanceFactory instanceFactory) - : base(instanceFactory) - { - } - - private void InvokeFix() - { - VisualStudio.Editor.SetText(@" -unsafe class C -{ -}"); - VisualStudio.Editor.Activate(); - - VisualStudio.Editor.PlaceCaret("C"); - VisualStudio.Editor.InvokeCodeActionList(); - VisualStudio.Editor.Verify.CodeAction("Allow unsafe code in this project", applyFix: true); - } - - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/44301"), Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)] - public void CPSProject_GeneralPropertyGroupUpdated() - { - var project = new ProjectUtils.Project(ProjectName); - - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp); - VisualStudio.SolutionExplorer.RestoreNuGetPackages(project); - - InvokeFix(); - VerifyPropertyOutsideConfiguration(GetProjectFileElement(project), "AllowUnsafeBlocks", "true"); - } - - [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)] - public void LegacyProject_AllConfigurationsUpdated() - { - var project = new ProjectUtils.Project(ProjectName); - - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp); - - InvokeFix(); - VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "AllowUnsafeBlocks", "true"); - } - - [WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")] - [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)] - public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated() - { - var project = new ProjectUtils.Project(ProjectName); - - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@" - - - - Debug - x64 - {{F4233BA4-A4CB-498B-BBC1-65A42206B1BA}} - Library - {ProjectName} - {ProjectName} - v4.6 - - - bin\x86\Debug\ - x86 - - - bin\x86\Release\ - x86 - true - - - bin\x64\Debug\ - x64 - false - - - bin\x64\Release\ - x64 - - - - -"); - - VisualStudio.SolutionExplorer.AddFile(project, "C.cs", open: true); - - InvokeFix(); - VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "AllowUnsafeBlocks", "true"); - } - } -} diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractUpdateProjectTest.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/AbstractUpgradeProjectTest.cs similarity index 67% rename from src/VisualStudio/IntegrationTest/IntegrationTests/AbstractUpdateProjectTest.cs rename to src/VisualStudio/IntegrationTest/New.IntegrationTests/AbstractUpgradeProjectTest.cs index d91c9891241ae..abd8a1dcc6177 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/AbstractUpdateProjectTest.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/AbstractUpgradeProjectTest.cs @@ -2,31 +2,23 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using System.Xml.Linq; -using Microsoft.VisualStudio.IntegrationTest.Utilities; using Xunit; -using Xunit.Abstractions; -using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils; namespace Roslyn.VisualStudio.IntegrationTests { - public abstract class AbstractUpdateProjectTest : AbstractIntegrationTest + public abstract class AbstractUpgradeProjectTest : AbstractIntegrationTest { - protected AbstractUpdateProjectTest(VisualStudioInstanceFactory instanceFactory) - : base(instanceFactory) - { - } - - protected XElement GetProjectFileElement(ProjectUtils.Project project) + protected async Task GetProjectFileElementAsync(string projectName, CancellationToken cancellationToken) { // Save the project file. - VisualStudio.SolutionExplorer.SaveAll(); + await TestServices.SolutionExplorer.SaveAllAsync(cancellationToken); - var projectFileContent = VisualStudio.SolutionExplorer.GetFileContents(project, Path.GetFileName(project.RelativePath)); + var projectFileContent = await TestServices.SolutionExplorer.GetFileContentsAsync(projectName, $"{ProjectName}.csproj", cancellationToken); return XElement.Parse(projectFileContent); } @@ -50,7 +42,7 @@ static bool IsConditionalPropertyGroup(XElement element) => element.Name.LocalName == "PropertyGroup" && element.Attributes().Any(a => a.Name.LocalName == "Condition"); } - private static string GetPropertyValue(XElement propertyGroup, string propertyName) + private static string? GetPropertyValue(XElement propertyGroup, string propertyName) => propertyGroup.Elements().SingleOrDefault(e => e.Name.LocalName == propertyName)?.Value; } } diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs new file mode 100644 index 0000000000000..c297804d640d5 --- /dev/null +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpdateProjectToAllowUnsafe.cs @@ -0,0 +1,114 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Threading; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.VisualStudio.IntegrationTest.Utilities; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Roslyn.VisualStudio.IntegrationTests.CSharp +{ + [Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)] + public class CSharpUpdateProjectToAllowUnsafe : AbstractUpgradeProjectTest + { + private async Task InvokeFixAsync(CancellationToken cancellationToken) + { + await TestServices.Editor.SetTextAsync(@" +unsafe class C +{ +}", cancellationToken); + await TestServices.Editor.ActivateAsync(cancellationToken); + + await TestServices.Editor.PlaceCaretAsync("C", charsOffset: 0, cancellationToken); + + // Suspend file change notification during code action application, since spurious file change notifications + // can cause silent failure to apply the code action if they occur within this block. + await using (var fileChangeRestorer = await TestServices.Shell.PauseFileChangesAsync(HangMitigatingCancellationToken)) + { + await TestServices.Editor.InvokeCodeActionListAsync(cancellationToken); + await TestServices.EditorVerifier.CodeActionAsync("Allow unsafe code in this project", applyFix: true, cancellationToken: cancellationToken); + } + } + + [IdeFact] + public async Task CPSProject_GeneralPropertyGroupUpdated() + { + var project = ProjectName; + + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddProjectAsync(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.RestoreNuGetPackagesAsync(project, HangMitigatingCancellationToken); + + await InvokeFixAsync(HangMitigatingCancellationToken); + VerifyPropertyOutsideConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "AllowUnsafeBlocks", "true"); + } + + [IdeFact] + public async Task LegacyProject_AllConfigurationsUpdated() + { + var project = ProjectName; + + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddProjectAsync(project, WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp, HangMitigatingCancellationToken); + + await InvokeFixAsync(HangMitigatingCancellationToken); + VerifyPropertyInEachConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "AllowUnsafeBlocks", "true"); + } + + [IdeFact] + [WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")] + public async Task LegacyProject_MultiplePlatforms_AllConfigurationsUpdated() + { + var project = ProjectName; + + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddCustomProjectAsync( + project, + ".csproj", + $@" + + + + Debug + x64 + {{F4233BA4-A4CB-498B-BBC1-65A42206B1BA}} + Library + {ProjectName} + {ProjectName} + v4.6 + + + bin\x86\Debug\ + x86 + + + bin\x86\Release\ + x86 + true + + + bin\x64\Debug\ + x64 + false + + + bin\x64\Release\ + x64 + + + + +", + HangMitigatingCancellationToken); + + await TestServices.SolutionExplorer.AddFileAsync(project, "C.cs", open: true, cancellationToken: HangMitigatingCancellationToken); + + await InvokeFixAsync(HangMitigatingCancellationToken); + VerifyPropertyInEachConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "AllowUnsafeBlocks", "true"); + } + } +} diff --git a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpgradeProject.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpgradeProject.cs similarity index 51% rename from src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpgradeProject.cs rename to src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpgradeProject.cs index c604b8acee107..0f336ef86fa7e 100644 --- a/src/VisualStudio/IntegrationTest/IntegrationTests/CSharp/CSharpUpgradeProject.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/CSharp/CSharpUpgradeProject.cs @@ -2,58 +2,60 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#nullable disable - +using System.Threading; +using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.VisualStudio.IntegrationTest.Utilities; using Roslyn.Test.Utilities; using Xunit; -using Xunit.Abstractions; -using ProjectUtils = Microsoft.VisualStudio.IntegrationTest.Utilities.Common.ProjectUtils; namespace Roslyn.VisualStudio.IntegrationTests.CSharp { - [Collection(nameof(SharedIntegrationHostFixture))] - public class CSharpUpgradeProject : AbstractUpdateProjectTest + [Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)] + public class CSharpUpgradeProject : AbstractUpgradeProjectTest { - public CSharpUpgradeProject(VisualStudioInstanceFactory instanceFactory) - : base(instanceFactory) + private async Task InvokeFixAsync(string version, CancellationToken cancellationToken) { - } - - private void InvokeFix(string version = "latest") - { - VisualStudio.Editor.SetText(@$" + await TestServices.Editor.SetTextAsync(@$" #error version:{version} -"); - VisualStudio.Editor.Activate(); +", cancellationToken); + await TestServices.Editor.ActivateAsync(cancellationToken); + + await TestServices.Editor.PlaceCaretAsync($"version:{version}", charsOffset: 0, cancellationToken); - VisualStudio.Editor.PlaceCaret($"version:{version}"); - VisualStudio.Editor.InvokeCodeActionList(); - VisualStudio.Editor.Verify.CodeAction($"Upgrade this project to C# language version '{version}'", applyFix: true); + // Suspend file change notification during code action application, since spurious file change notifications + // can cause silent failure to apply the code action if they occur within this block. + await using (var fileChangeRestorer = await TestServices.Shell.PauseFileChangesAsync(HangMitigatingCancellationToken)) + { + await TestServices.Editor.InvokeCodeActionListAsync(cancellationToken); + await TestServices.EditorVerifier.CodeActionAsync($"Upgrade this project to C# language version '{version}'", applyFix: true, cancellationToken: cancellationToken); + } } - [WpfFact(Skip = "https://github.com/dotnet/roslyn/issues/38301"), Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)] - public void CPSProject_GeneralPropertyGroupUpdated() + [IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/38301")] + public async Task CPSProject_GeneralPropertyGroupUpdated() { - var project = new ProjectUtils.Project(ProjectName); + var project = ProjectName; - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp); - VisualStudio.SolutionExplorer.RestoreNuGetPackages(project); + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddProjectAsync(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.RestoreNuGetPackagesAsync(project, HangMitigatingCancellationToken); - InvokeFix(); - VerifyPropertyOutsideConfiguration(GetProjectFileElement(project), "LangVersion", "latest"); + await InvokeFixAsync(version: "latest", HangMitigatingCancellationToken); + VerifyPropertyOutsideConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "LangVersion", "latest"); } - [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)] - public void LegacyProject_AllConfigurationsUpdated() + [IdeFact] + public async Task LegacyProject_AllConfigurationsUpdated() { - var project = new ProjectUtils.Project(ProjectName); + var project = ProjectName; - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@" + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddCustomProjectAsync( + project, + ".csproj", + $@" @@ -85,21 +87,25 @@ public void LegacyProject_AllConfigurationsUpdated() -"); - VisualStudio.SolutionExplorer.AddFile(project, "C.cs", open: true); +", + HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddFileAsync(project, "C.cs", open: true, cancellationToken: HangMitigatingCancellationToken); - InvokeFix(version: "7.3"); - VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "7.3"); + await InvokeFixAsync(version: "7.3", HangMitigatingCancellationToken); + VerifyPropertyInEachConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "LangVersion", "7.3"); } + [IdeFact] [WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")] - [WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)] - public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated() + public async Task LegacyProject_MultiplePlatforms_AllConfigurationsUpdated() { - var project = new ProjectUtils.Project(ProjectName); + var project = ProjectName; - VisualStudio.SolutionExplorer.CreateSolution(SolutionName); - VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@" + await TestServices.SolutionExplorer.CreateSolutionAsync(SolutionName, HangMitigatingCancellationToken); + await TestServices.SolutionExplorer.AddCustomProjectAsync( + project, + ".csproj", + $@" @@ -134,12 +140,13 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated() -"); +", + HangMitigatingCancellationToken); - VisualStudio.SolutionExplorer.AddFile(project, "C.cs", open: true); + await TestServices.SolutionExplorer.AddFileAsync(project, "C.cs", open: true, cancellationToken: HangMitigatingCancellationToken); - InvokeFix(version: "7.3"); - VerifyPropertyInEachConfiguration(GetProjectFileElement(project), "LangVersion", "7.3"); + await InvokeFixAsync(version: "7.3", HangMitigatingCancellationToken); + VerifyPropertyInEachConfiguration(await GetProjectFileElementAsync(project, HangMitigatingCancellationToken), "LangVersion", "7.3"); } } } diff --git a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/SolutionExplorerInProcess.cs b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/SolutionExplorerInProcess.cs index 38aaff963ecbf..dee04f7fdc0d3 100644 --- a/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/SolutionExplorerInProcess.cs +++ b/src/VisualStudio/IntegrationTest/New.IntegrationTests/InProcess/SolutionExplorerInProcess.cs @@ -13,6 +13,7 @@ using Microsoft.CodeAnalysis; using Microsoft.VisualStudio.Editor; using Microsoft.VisualStudio.IntegrationTest.Utilities; +using Microsoft.VisualStudio.OLE.Interop; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Text; @@ -151,6 +152,20 @@ public async Task AddProjectAsync(string projectName, string projectTemplate, st ErrorHandler.ThrowOnFailure(solution.AddNewProjectFromTemplate(projectTemplatePath, null, null, projectPath, projectName, null, out _)); } + public async Task AddCustomProjectAsync(string projectName, string projectFileExtension, string projectFileContent, CancellationToken cancellationToken) + { + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + + var projectPath = Path.Combine(await GetDirectoryNameAsync(cancellationToken), projectName); + Directory.CreateDirectory(projectPath); + + var projectFilePath = Path.Combine(projectPath, projectName + projectFileExtension); + File.WriteAllText(projectFilePath, projectFileContent); + + var solution = await GetRequiredGlobalServiceAsync(cancellationToken); + ErrorHandler.ThrowOnFailure(solution.AddExistingProject(projectFilePath, pParent: null, out _)); + } + public async Task RestoreNuGetPackagesAsync(CancellationToken cancellationToken) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); @@ -189,6 +204,14 @@ await Helper.RetryAsync( cancellationToken); } + public async Task SaveAllAsync(CancellationToken cancellationToken) + { + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + + var dispatcher = await GetRequiredGlobalServiceAsync(cancellationToken); + ErrorHandler.ThrowOnFailure(dispatcher.Exec(typeof(VSConstants.VSStd97CmdID).GUID, (uint)VSConstants.VSStd97CmdID.SaveSolution, (uint)OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT, IntPtr.Zero, IntPtr.Zero)); + } + public async Task OpenFileAsync(string projectName, string relativeFilePath, CancellationToken cancellationToken) { await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); @@ -340,6 +363,19 @@ public async Task GetFileContentsAsync(string projectName, string relati return File.ReadAllText(filePath); } + public async Task<(string solutionDirectory, string solutionFileFullPath, string userOptionsFile)> GetSolutionInfoAsync(CancellationToken cancellationToken) + { + await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); + + if (!await IsSolutionOpenAsync(cancellationToken)) + throw new InvalidOperationException("No solution is open."); + + var solution = await GetRequiredGlobalServiceAsync(cancellationToken); + ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out var solutionDirectory, out var solutionFileFullPath, out var userOptionsFile)); + + return (solutionDirectory, solutionFileFullPath, userOptionsFile); + } + private static string ConvertLanguageName(string languageName) { return languageName switch @@ -365,16 +401,13 @@ private async Task GetAbsolutePathForProjectRelativeFilePathAsync(string private async Task GetDirectoryNameAsync(CancellationToken cancellationToken) { - await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); - - var solution = await GetRequiredGlobalServiceAsync(cancellationToken); - ErrorHandler.ThrowOnFailure(solution.GetSolutionInfo(out _, out var solutionFileFullPath, out _)); + var (solutionDirectory, solutionFileFullPath, _) = await GetSolutionInfoAsync(cancellationToken); if (string.IsNullOrEmpty(solutionFileFullPath)) { throw new InvalidOperationException(); } - return Path.GetDirectoryName(solutionFileFullPath); + return solutionDirectory; } private async Task GetProjectTemplatePathAsync(string projectTemplate, string languageName, CancellationToken cancellationToken) diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs index 55cd499e9725d..8c62995cbdbe1 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/InProcess/SolutionExplorer_InProc.cs @@ -332,18 +332,6 @@ public void AddProject(string projectName, string projectTemplate, string langua _solution.AddFromTemplate(projectTemplatePath, projectPath, projectName, Exclusive: false); } - public void AddCustomProject(string projectName, string projectFileExtension, string projectFileContent) - { - var projectPath = Path.Combine(DirectoryName, projectName); - Directory.CreateDirectory(projectPath); - - var projectFilePath = Path.Combine(projectPath, projectName + projectFileExtension); - File.WriteAllText(projectFilePath, projectFileContent); - - Contract.ThrowIfNull(_solution); - _solution.AddFromFile(projectFilePath); - } - // TODO: Adjust language name based on whether we are using a web template private string GetProjectTemplatePath(string projectTemplate, string languageName) { diff --git a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/SolutionExplorer_OutOfProc.cs b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/SolutionExplorer_OutOfProc.cs index 7ed4ac8ef86fc..fb16e4f4fd34f 100644 --- a/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/SolutionExplorer_OutOfProc.cs +++ b/src/VisualStudio/IntegrationTest/TestUtilities/OutOfProcess/SolutionExplorer_OutOfProc.cs @@ -47,12 +47,6 @@ public void AddProject(ProjectUtils.Project projectName, string projectTemplate, _instance.Workspace.WaitForAsyncOperations(Helper.HangMitigatingTimeout, FeatureAttribute.Workspace); } - public void AddCustomProject(ProjectUtils.Project projectName, string projectFileExtension, string projectFileContent) - { - _inProc.AddCustomProject(projectName.Name, projectFileExtension, projectFileContent); - _instance.Workspace.WaitForAsyncOperations(Helper.HangMitigatingTimeout, FeatureAttribute.Workspace); - } - public void AddProjectReference(ProjectUtils.Project fromProjectName, ProjectUtils.ProjectReference toProjectName) { _inProc.AddProjectReference(fromProjectName.Name, toProjectName.Name);