From 3b8c88113ef8095996e4cfcc2a4bc843ecd53707 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 22 Mar 2021 19:07:34 -0700 Subject: [PATCH 1/3] Run the MSBuildWorkspace tests on .Net Core --- eng/Versions.props | 2 +- ...ildInstalled.LooseAssemblyVersionLoader.cs | 114 ++++ .../MSBuildTest/DotNetSdkMSBuildInstalled.cs | 51 ++ .../DotNetSdkMSBuildWorkspaceTests.cs | 67 +++ src/Workspaces/MSBuildTest/Interop.cs | 42 -- .../MSBuildTest/MSBuildInstalled.cs | 49 ++ .../MSBuildTest/MSBuildWorkspaceTests.cs | 558 ++++++------------ ...alysis.Workspaces.MSBuild.UnitTests.csproj | 6 +- src/Workspaces/MSBuildTest/NetCoreTests.cs | 16 +- .../VisualStudioMSBuildInstalled.cs | 206 +------ .../VisualStudioMSBuildWorkspaceTests.cs | 219 +++++++ 11 files changed, 711 insertions(+), 619 deletions(-) create mode 100644 src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs create mode 100644 src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs create mode 100644 src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs delete mode 100644 src/Workspaces/MSBuildTest/Interop.cs create mode 100644 src/Workspaces/MSBuildTest/MSBuildInstalled.cs create mode 100644 src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs diff --git a/eng/Versions.props b/eng/Versions.props index 994660e6747b3..43bd254a52068 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -57,7 +57,7 @@ 6.1.0.5902 $(MicrosoftBuildPackagesVersion) $(MicrosoftBuildPackagesVersion) - 1.2.6 + 1.4.1 $(MicrosoftBuildPackagesVersion) $(MicrosoftBuildPackagesVersion) 5.7.0 diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs new file mode 100644 index 0000000000000..229f37e04a82d --- /dev/null +++ b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.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; +using System.Collections.Generic; +using System.IO; +using System.Reflection; +#if NETCOREAPP +using System.Runtime.Loader; +#endif + +namespace Microsoft.CodeAnalysis.MSBuild.UnitTests +{ + internal partial class DotNetSdkMSBuildInstalled + { +#if NETCOREAPP + + private static class LooseVersionAssemblyLoader + { + private static readonly Dictionary s_pathsToAssemblies = new(StringComparer.OrdinalIgnoreCase); + private static readonly Dictionary s_namesToAssemblies = new(); + + private static readonly object s_guard = new(); + private static readonly string[] s_extensions = new[] { "ni.dll", "ni.exe", "dll", "exe" }; + + /// + /// Register an assembly loader that will load assemblies with higher version than what was requested. + /// + public static void Register(string searchPath) + { + AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext context, AssemblyName assemblyName) => + { + lock (s_guard) + { + if (s_namesToAssemblies.TryGetValue(assemblyName.FullName, out var cachedAssembly)) + { + return cachedAssembly; + } + + var assembly = TryResolveAssemblyFromPaths(context, assemblyName, searchPath); + + // Cache assembly + if (assembly != null) + { + var name = assembly.FullName; + if (name is null) + { + throw new Exception($"Could not get name for assembly '{assembly}'"); + } + + s_pathsToAssemblies[assembly.Location] = assembly; + s_namesToAssemblies[name] = assembly; + } + + return assembly; + } + }; + } + + private static Assembly? TryResolveAssemblyFromPaths(AssemblyLoadContext context, AssemblyName assemblyName, string searchPath) + { + foreach (var cultureSubfolder in string.IsNullOrEmpty(assemblyName.CultureName) + // If no culture is specified, attempt to load directly from + // the known dependency paths. + ? new[] { string.Empty } + // Search for satellite assemblies in culture subdirectories + // of the assembly search directories, but fall back to the + // bare search directory if that fails. + : new[] { assemblyName.CultureName, string.Empty }) + { + foreach (var extension in s_extensions) + { + var candidatePath = Path.Combine( + searchPath, cultureSubfolder, $"{assemblyName.Name}.{extension}"); + + var isAssemblyLoaded = s_pathsToAssemblies.ContainsKey(candidatePath) == true; + if (isAssemblyLoaded || !File.Exists(candidatePath)) + { + continue; + } + + var candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath); + if (candidateAssemblyName.Version < assemblyName.Version) + { + continue; + } + + try + { + var assembly = context.LoadFromAssemblyPath(candidatePath); + + return assembly; + } + catch + { + if (assemblyName.Name != null) + { + // We were unable to load the assembly from the file path. It is likely that + // a different version of the assembly has already been loaded into the context. + // Be forgiving and attempt to load assembly by name without specifying a version. + return context.LoadFromAssemblyName(new AssemblyName(assemblyName.Name)); + } + } + } + } + + return null; + } + } + +#endif + } +} diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs new file mode 100644 index 0000000000000..b623901d72f68 --- /dev/null +++ b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs @@ -0,0 +1,51 @@ +// 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; +using System.Linq; +using Microsoft.Build.Locator; +using Roslyn.Test.Utilities; + +namespace Microsoft.CodeAnalysis.MSBuild.UnitTests +{ + internal partial class DotNetSdkMSBuildInstalled : ExecutionCondition + { + private static readonly VisualStudioInstance? s_instance; + +#if NETCOREAPP + static DotNetSdkMSBuildInstalled() + { + s_instance = MSBuildLocator.QueryVisualStudioInstances() + .OrderByDescending(instances => instances.Version) + .FirstOrDefault(); + + if (s_instance != null && !MSBuildLocator.IsRegistered) + { + LooseVersionAssemblyLoader.Register(s_instance.MSBuildPath); + MSBuildLocator.RegisterInstance(s_instance); + } + } +#endif + + private readonly Version _minimumVersion; + + public DotNetSdkMSBuildInstalled() : this(new Version(2, 1)) + { + } + + internal DotNetSdkMSBuildInstalled(Version minimumVersion) + { + _minimumVersion = minimumVersion; + } + + public override bool ShouldSkip => s_instance is null || s_instance.Version < _minimumVersion; + + public override string SkipReason +#if NETCOREAPP + => $"Could not locate .NET SDK {_minimumVersion} or higher installed"; +#else + => $"Test runs on .NET Core"; +#endif + } +} diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs new file mode 100644 index 0000000000000..5778e0b6ae97c --- /dev/null +++ b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs @@ -0,0 +1,67 @@ +// 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 System.IO; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.UnitTests.TestFiles; +using Roslyn.Test.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.MSBuild.UnitTests +{ + public class DotNetSdkMSBuildWorkspaceTests : MSBuildWorkspaceTestBase + { + [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenProject_WithInvalidFilePath_Fails() + { + CreateFiles(GetSimpleCSharpSolutionFiles()); + var projectFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidProject.csproj"); + + using var workspace = CreateMSBuildWorkspace(); + + AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); + } + + [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenProject_WithInvalidProjectReference_SkipFalse_Fails() + { + CreateFiles(GetMultiProjectSolutionFiles() + .WithFile(@"VisualBasicProject\VisualBasicProject.vbproj", Resources.ProjectFiles.VisualBasic.InvalidProjectReference)); + var projectFilePath = GetSolutionFileName(@"VisualBasicProject\VisualBasicProject.vbproj"); + + using var workspace = CreateMSBuildWorkspace(); + workspace.SkipUnrecognizedProjects = false; + + AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); + } + + [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenSolution_WithInvalidProjectPath_SkipFalse_Fails() + { + // when not skipped we should get an exception for the invalid project + + CreateFiles(GetSimpleCSharpSolutionFiles() + .WithFile(@"TestSolution.sln", Resources.SolutionFiles.InvalidProjectPath)); + var solutionFilePath = GetSolutionFileName(@"TestSolution.sln"); + + using var workspace = CreateMSBuildWorkspace(); + workspace.SkipUnrecognizedProjects = false; + + AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); + } + + [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenSolution_WithInvalidSolutionFile_Fails() + { + CreateFiles(GetSimpleCSharpSolutionFiles()); + var solutionFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidSolution.sln"); + + using var workspace = CreateMSBuildWorkspace(); + + AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); + } + } +} diff --git a/src/Workspaces/MSBuildTest/Interop.cs b/src/Workspaces/MSBuildTest/Interop.cs deleted file mode 100644 index 6251771c56238..0000000000000 --- a/src/Workspaces/MSBuildTest/Interop.cs +++ /dev/null @@ -1,42 +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 System; -using System.Runtime.InteropServices; -using Microsoft.VisualStudio.Setup.Configuration; - -namespace Microsoft.CodeAnalysis.MSBuild.UnitTests -{ - internal static class Interop - { - private const int REGDG_E_CLASSNOTREG = unchecked((int)0x80040154); - - [DllImport("Microsoft.VisualStudio.Setup.Configuration.Native.dll", ExactSpelling = true, PreserveSig = true)] - private static extern int GetSetupConfiguration( - [MarshalAs(UnmanagedType.Interface), Out] out ISetupConfiguration configuration, - IntPtr reserved); - - public static ISetupConfiguration2 GetSetupConfiguration() - { - try - { - return new SetupConfiguration(); - } - catch (COMException ex) when (ex.ErrorCode == REGDG_E_CLASSNOTREG) - { - // We could not CoCreate the SetupConfiguration object. If that fails, try p/invoking. - var hresult = GetSetupConfiguration(out var configuration, IntPtr.Zero); - - if (hresult < 0) - { - throw new COMException($"Failed to get {nameof(ISetupConfiguration)}", hresult); - } - - return configuration as ISetupConfiguration2; - } - } - } -} diff --git a/src/Workspaces/MSBuildTest/MSBuildInstalled.cs b/src/Workspaces/MSBuildTest/MSBuildInstalled.cs new file mode 100644 index 0000000000000..224f195459d5e --- /dev/null +++ b/src/Workspaces/MSBuildTest/MSBuildInstalled.cs @@ -0,0 +1,49 @@ +// 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; +using Roslyn.Test.Utilities; + +namespace Microsoft.CodeAnalysis.MSBuild.UnitTests +{ + internal class MSBuildInstalled : ExecutionCondition + { + private readonly ExecutionCondition _msBuildInstalled; + + public MSBuildInstalled() + : this(minimumVsVersion: new Version(15, 0), minimumSdkVersion: new Version(2, 1)) + { + } + + protected MSBuildInstalled(Version minimumVsVersion, Version minimumSdkVersion) + { + _msBuildInstalled = +#if NETCOREAPP + new DotNetSdkMSBuildInstalled(minimumSdkVersion); +#else + new VisualStudioMSBuildInstalled(minimumVsVersion); +#endif + } + + public override bool ShouldSkip => _msBuildInstalled.ShouldSkip; + + public override string SkipReason => _msBuildInstalled.SkipReason; + } + + internal class MSBuild16_2OrHigherInstalled : MSBuildInstalled + { + public MSBuild16_2OrHigherInstalled() + : base(minimumVsVersion: new Version(16, 2), minimumSdkVersion: new Version(3, 1)) + { + } + } + + internal class MSBuild16_9OrHigherInstalled : MSBuildInstalled + { + public MSBuild16_9OrHigherInstalled() + : base(minimumVsVersion: new Version(16, 9), minimumSdkVersion: new Version(5, 0, 201)) + { + } + } +} diff --git a/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs index 0606f9146f182..bbfd93d6240df 100644 --- a/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs +++ b/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs @@ -34,7 +34,7 @@ namespace Microsoft.CodeAnalysis.MSBuild.UnitTests { public class MSBuildWorkspaceTests : MSBuildWorkspaceTestBase { - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestCreateMSBuildWorkspace() { using var workspace = CreateMSBuildWorkspace(); @@ -48,7 +48,7 @@ public void TestCreateMSBuildWorkspace() Assert.NotNull(workspace.Services.TextFactory); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_SingleProjectSolution() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -64,7 +64,7 @@ public async Task TestOpenSolution_SingleProjectSolution() Assert.StartsWith("public class CSharpClass", type.ToString(), StringComparison.Ordinal); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_MultiProjectSolution() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -89,7 +89,7 @@ public async Task TestOpenSolution_MultiProjectSolution() Assert.Equal(5, compReferences.Count); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/41456"), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/41456"), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(2824, "https://github.com/dotnet/roslyn/issues/2824")] public async Task Test_OpenProjectReferencingPortableProject() { @@ -112,7 +112,7 @@ public async Task Test_OpenProjectReferencingPortableProject() string.Join(Environment.NewLine, project.MetadataReferences.OfType().Select(r => r.FilePath))); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_SharedMetadataReferences() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -135,7 +135,7 @@ public async Task Test_SharedMetadataReferences() Assert.Same(p0mscorlib, p1mscorlib); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(546171, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546171")] public async Task Test_SharedMetadataReferencesWithAliases() { @@ -203,7 +203,7 @@ private static MetadataReference GetMetadataReferenceByAlias(Project project, st private static Metadata GetMetadata(MetadataReference metadataReference) => ((PortableExecutableReference)metadataReference).GetMetadata(); - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(552981, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/552981")] public async Task TestOpenSolution_DuplicateProjectGuids() { @@ -214,7 +214,7 @@ public async Task TestOpenSolution_DuplicateProjectGuids() var solution = await workspace.OpenSolutionAsync(solutionFilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(831379, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/831379")] public async Task GetCompilationWithCircularProjectReferences() { @@ -239,7 +239,7 @@ public async Task GetCompilationWithCircularProjectReferences() compilation2.References.OfType().Any(c => c.Compilation == compilation1)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOutputFilePaths() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -254,7 +254,7 @@ public async Task TestOutputFilePaths() Assert.Equal("VisualBasicProject.dll", Path.GetFileName(p2.OutputFilePath)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOutputInfo() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -269,7 +269,7 @@ public async Task TestCompilationOutputInfo() Assert.Equal("VisualBasicProject.dll", Path.GetFileName(p2.CompilationOutputInfo.AssemblyPath)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCrossLanguageReferencesUsesInMemoryGeneratedMetadata() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -291,7 +291,7 @@ public async Task TestCrossLanguageReferencesUsesInMemoryGeneratedMetadata() Assert.NotNull(pref); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCrossLanguageReferencesWithOutOfDateMetadataOnDiskUsesInMemoryGeneratedMetadata() { await PrepareCrossLanguageProjectWithEmittedMetadataAsync(); @@ -318,7 +318,7 @@ public async Task TestCrossLanguageReferencesWithOutOfDateMetadataOnDiskUsesInMe Assert.NotNull(pref); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestInternalsVisibleToSigned() { var solution = await SolutionAsync( @@ -346,7 +346,7 @@ class C1 Assert.Empty(diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestVersions() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -391,7 +391,7 @@ public async Task TestVersions() Assert.True(solution3.Version.GetTestAccessor().IsNewerThan(solution2.Version)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_LoadMetadataForReferencedProjects() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -410,7 +410,7 @@ public async Task TestOpenSolution_LoadMetadataForReferencedProjects() Assert.StartsWith("public class CSharpClass", type.ToString(), StringComparison.Ordinal); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(33047, "https://github.com/dotnet/roslyn/issues/33047")] public async Task TestOpenProject_CSharp_GlobalPropertyShouldUnsetParentConfigurationAndPlatformDefault() { @@ -428,7 +428,7 @@ public async Task TestOpenProject_CSharp_GlobalPropertyShouldUnsetParentConfigur Assert.Equal(expectedFileName, tree.FilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(33047, "https://github.com/dotnet/roslyn/issues/33047")] public async Task TestOpenProject_CSharp_GlobalPropertyShouldUnsetParentConfigurationAndPlatformTrue() { @@ -446,7 +446,7 @@ public async Task TestOpenProject_CSharp_GlobalPropertyShouldUnsetParentConfigur Assert.Equal(expectedFileName, tree.FilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_CSharp_WithoutPrefer32BitAndConsoleApplication() { @@ -460,7 +460,7 @@ public async Task TestOpenProject_CSharp_WithoutPrefer32BitAndConsoleApplication Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_CSharp_WithoutPrefer32BitAndLibrary() { @@ -475,7 +475,7 @@ public async Task TestOpenProject_CSharp_WithoutPrefer32BitAndLibrary() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_CSharp_WithPrefer32BitAndConsoleApplication() { @@ -489,7 +489,7 @@ public async Task TestOpenProject_CSharp_WithPrefer32BitAndConsoleApplication() Assert.Equal(Platform.AnyCpu32BitPreferred, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_CSharp_WithPrefer32BitAndLibrary() { @@ -504,7 +504,7 @@ public async Task TestOpenProject_CSharp_WithPrefer32BitAndLibrary() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_CSharp_WithPrefer32BitAndWinMDObj() { @@ -519,7 +519,7 @@ public async Task TestOpenProject_CSharp_WithPrefer32BitAndWinMDObj() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_CSharp_WithoutOutputPath() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -531,7 +531,7 @@ public async Task TestOpenProject_CSharp_WithoutOutputPath() Assert.NotEmpty(project.OutputFilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_CSharp_WithoutAssemblyName() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -543,7 +543,7 @@ public async Task TestOpenProject_CSharp_WithoutAssemblyName() Assert.NotEmpty(project.OutputFilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_CSharp_WithoutCSharpTargetsImported_DocumentsArePickedUp() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -556,7 +556,7 @@ public async Task TestOpenSolution_CSharp_WithoutCSharpTargetsImported_Documents Assert.NotEmpty(project.Documents); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_VisualBasic_WithoutVBTargetsImported_DocumentsArePickedUp() { CreateFiles(GetMultiProjectSolutionFiles() @@ -568,7 +568,7 @@ public async Task TestOpenProject_VisualBasic_WithoutVBTargetsImported_Documents Assert.NotEmpty(project.Documents); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_VisualBasic_WithoutPrefer32BitAndConsoleApplication() { @@ -582,7 +582,7 @@ public async Task TestOpenProject_VisualBasic_WithoutPrefer32BitAndConsoleApplic Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_VisualBasic_WithoutPrefer32BitAndLibrary() { @@ -597,7 +597,7 @@ public async Task TestOpenProject_VisualBasic_WithoutPrefer32BitAndLibrary() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndConsoleApplication() { @@ -611,7 +611,7 @@ public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndConsoleApplicati Assert.Equal(Platform.AnyCpu32BitPreferred, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndLibrary() { @@ -626,7 +626,7 @@ public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndLibrary() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(739043, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/739043")] public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndWinMDObj() { @@ -641,7 +641,7 @@ public async Task TestOpenProject_VisualBasic_WithPrefer32BitAndWinMDObj() Assert.Equal(Platform.AnyCpu, compilation.Options.Platform); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_VisualBasic_WithoutOutputPath() { CreateFiles(GetMultiProjectSolutionFiles() @@ -654,7 +654,7 @@ public async Task TestOpenProject_VisualBasic_WithoutOutputPath() Assert.NotEmpty(project.OutputFilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_VisualBasic_WithLanguageVersion15_3() { CreateFiles(GetMultiProjectSolutionFiles() @@ -666,7 +666,7 @@ public async Task TestOpenProject_VisualBasic_WithLanguageVersion15_3() Assert.Equal(VB.LanguageVersion.VisualBasic15_3, ((VB.VisualBasicParseOptions)project.ParseOptions).LanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_VisualBasic_WithLatestLanguageVersion() { CreateFiles(GetMultiProjectSolutionFiles() @@ -679,7 +679,7 @@ public async Task TestOpenProject_VisualBasic_WithLatestLanguageVersion() Assert.Equal(VB.LanguageVersion.Latest, ((VB.VisualBasicParseOptions)project.ParseOptions).SpecifiedLanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_VisualBasic_WithoutAssemblyName() { CreateFiles(GetMultiProjectSolutionFiles() @@ -693,7 +693,7 @@ public async Task TestOpenProject_VisualBasic_WithoutAssemblyName() Assert.NotEmpty(project.OutputFilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_Respect_ReferenceOutputassembly_Flag() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -706,38 +706,7 @@ public async Task Test_Respect_ReferenceOutputassembly_Flag() Assert.Empty(project.ProjectReferences); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public async Task TestOpenProject_WithXaml() - { - CreateFiles(GetSimpleCSharpSolutionFiles() - .WithFile(@"CSharpProject\CSharpProject.csproj", Resources.ProjectFiles.CSharp.WithXaml) - .WithFile(@"CSharpProject\App.xaml", Resources.SourceFiles.Xaml.App) - .WithFile(@"CSharpProject\App.xaml.cs", Resources.SourceFiles.CSharp.App) - .WithFile(@"CSharpProject\MainWindow.xaml", Resources.SourceFiles.Xaml.MainWindow) - .WithFile(@"CSharpProject\MainWindow.xaml.cs", Resources.SourceFiles.CSharp.MainWindow)); - var projectFilePath = GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"); - - // Ensure the Xaml compiler does not run in a separate appdomain. It appears that this won't work within xUnit. - using var workspace = CreateMSBuildWorkspace(("AlwaysCompileMarkupFilesInSeparateDomain", "false")); - var project = await workspace.OpenProjectAsync(projectFilePath); - var documents = project.Documents.ToList(); - - // AssemblyInfo.cs, App.xaml.cs, MainWindow.xaml.cs, App.g.cs, MainWindow.g.cs, + unusual AssemblyAttributes.cs - Assert.Equal(6, documents.Count); - - // both xaml code behind files are documents - Assert.Contains(documents, d => d.Name == "App.xaml.cs"); - Assert.Contains(documents, d => d.Name == "MainWindow.xaml.cs"); - - // prove no xaml files are documents - Assert.DoesNotContain(documents, d => d.Name.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase)); - - // prove that generated source files for xaml files are included in documents list - Assert.Contains(documents, d => d.Name == "App.g.cs"); - Assert.Contains(documents, d => d.Name == "MainWindow.g.cs"); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestMetadataReferenceHasBadHintPath() { // prove that even with bad hint path for metadata reference the workspace can succeed at finding the correct metadata reference. @@ -753,7 +722,7 @@ public async Task TestMetadataReferenceHasBadHintPath() Assert.NotNull(csharpLib); } - [ConditionalFact(typeof(VisualStudio16_9_Preview3OrHigherMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuild16_9OrHigherInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(531631, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531631")] public async Task TestOpenProject_AssemblyNameIsPath() { @@ -772,7 +741,7 @@ public async Task TestOpenProject_AssemblyNameIsPath() Assert.Equal(expectedOutputPath, Path.GetDirectoryName(project.OutputFilePath)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(531631, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/531631")] public async Task TestOpenProject_AssemblyNameIsPath2() { @@ -790,7 +759,7 @@ public async Task TestOpenProject_AssemblyNameIsPath2() Assert.Equal(expectedOutputPath, Path.GetDirectoryName(Path.GetFullPath(project.OutputFilePath))); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithDuplicateFile() { // Verify that we don't throw in this case @@ -806,7 +775,7 @@ public async Task TestOpenProject_WithDuplicateFile() Assert.Equal(2, documents.Count); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenProject_WithInvalidFileExtension() { // make sure the file does in fact exist, but with an unrecognized extension @@ -825,7 +794,7 @@ public void TestOpenProject_WithInvalidFileExtension() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenProject_ProjectFileExtensionAssociatedWithUnknownLanguage() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -845,7 +814,7 @@ public void TestOpenProject_ProjectFileExtensionAssociatedWithUnknownLanguage() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithAssociatedLanguageExtension1() { // make a CSharp solution with a project file having the incorrect extension 'vbproj', and then load it using the overload the lets us @@ -863,7 +832,7 @@ public async Task TestOpenProject_WithAssociatedLanguageExtension1() Assert.Empty(diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithAssociatedLanguageExtension2_IgnoreCase() { // make a CSharp solution with a project file having the incorrect extension 'anyproj', and then load it using the overload the lets us @@ -882,7 +851,7 @@ public async Task TestOpenProject_WithAssociatedLanguageExtension2_IgnoreCase() Assert.Empty(diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenSolution_WithNonExistentSolutionFile_Fails() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -895,20 +864,7 @@ public void TestOpenSolution_WithNonExistentSolutionFile_Fails() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidSolutionFile_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var solutionFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidSolution.sln"); - - AssertEx.Throws(() => - { - using var workspace = CreateMSBuildWorkspace(); - workspace.OpenSolutionAsync(solutionFilePath).Wait(); - }); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithTemporaryLockedFile_SucceedsWithoutFailureEvent() { // when skipped we should see a diagnostic for the invalid project @@ -943,7 +899,7 @@ public async Task TestOpenSolution_WithTemporaryLockedFile_SucceedsWithoutFailur Assert.Empty(ws.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithLockedFile_FailsWithFailureEvent() { // when skipped we should see a diagnostic for the invalid project @@ -970,7 +926,7 @@ public async Task TestOpenSolution_WithLockedFile_FailsWithFailureEvent() Assert.Equal(WorkspaceDiagnosticKind.Failure, workspace.Diagnostics.Single().Kind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithInvalidProjectPath_SkipTrue_SucceedsWithFailureEvent() { // when skipped we should see a diagnostic for the invalid project @@ -986,7 +942,7 @@ public async Task TestOpenSolution_WithInvalidProjectPath_SkipTrue_SucceedsWithF } [WorkItem(985906, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/985906")] - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task HandleSolutionProjectTypeSolutionFolder() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -998,22 +954,7 @@ public async Task HandleSolutionProjectTypeSolutionFolder() Assert.Empty(workspace.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidProjectPath_SkipFalse_Fails() - { - // when not skipped we should get an exception for the invalid project - - CreateFiles(GetSimpleCSharpSolutionFiles() - .WithFile(@"TestSolution.sln", Resources.SolutionFiles.InvalidProjectPath)); - var solutionFilePath = GetSolutionFileName(@"TestSolution.sln"); - - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - - AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithNonExistentProject_SkipTrue_SucceedsWithFailureEvent() { // when skipped we should see a diagnostic for the non-existent project @@ -1028,7 +969,7 @@ public async Task TestOpenSolution_WithNonExistentProject_SkipTrue_SucceedsWithF Assert.Single(workspace.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenSolution_WithNonExistentProject_SkipFalse_Fails() { // when skipped we should see an exception for the non-existent project @@ -1043,7 +984,7 @@ public void TestOpenSolution_WithNonExistentProject_SkipFalse_Fails() AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithUnrecognizedProjectFileExtension_Fails() { // proves that for solution open, project type guid and extension are both necessary @@ -1057,7 +998,7 @@ public async Task TestOpenSolution_WithUnrecognizedProjectFileExtension_Fails() Assert.Empty(solution.ProjectIds); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithUnrecognizedProjectTypeGuidButRecognizedExtension_Succeeds() { // proves that if project type guid is not recognized, a known project file extension is all we need. @@ -1070,7 +1011,7 @@ public async Task TestOpenSolution_WithUnrecognizedProjectTypeGuidButRecognizedE Assert.Single(solution.ProjectIds); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_WithUnrecognizedProjectTypeGuidAndUnrecognizedExtension_WithSkipTrue_SucceedsWithFailureEvent() { // proves that if both project type guid and file extension are unrecognized, then project is skipped. @@ -1087,7 +1028,7 @@ public async Task TestOpenSolution_WithUnrecognizedProjectTypeGuidAndUnrecognize Assert.Empty(solution.ProjectIds); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenSolution_WithUnrecognizedProjectTypeGuidAndUnrecognizedExtension_WithSkipFalse_Fails() { // proves that if both project type guid and file extension are unrecognized, then open project fails. @@ -1114,7 +1055,7 @@ public void TestOpenSolution_WithUnrecognizedProjectTypeGuidAndUnrecognizedExten private readonly IEnumerable _defaultAssembliesWithoutCSharp = MefHostServices.DefaultAssemblies.Where(a => !a.FullName.Contains("CSharp")); - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(3931, "https://github.com/dotnet/roslyn/issues/3931")] public void TestOpenSolution_WithMissingLanguageLibraries_WithSkipFalse_Throws() { @@ -1136,7 +1077,7 @@ public void TestOpenSolution_WithMissingLanguageLibraries_WithSkipFalse_Throws() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(3931, "https://github.com/dotnet/roslyn/issues/3931")] public async Task TestOpenSolution_WithMissingLanguageLibraries_WithSkipTrue_SucceedsWithDiagnostic() { @@ -1154,7 +1095,7 @@ public async Task TestOpenSolution_WithMissingLanguageLibraries_WithSkipTrue_Suc Assert.Equal(expected, workspace.Diagnostics.Single().Message); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(3931, "https://github.com/dotnet/roslyn/issues/3931")] public void TestOpenProject_WithMissingLanguageLibraries_Throws() { @@ -1174,20 +1115,7 @@ public void TestOpenProject_WithMissingLanguageLibraries_Throws() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidFilePath_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var projectFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidProject.csproj"); - - AssertEx.Throws(() => - { - using var workspace = CreateMSBuildWorkspace(); - workspace.OpenProjectAsync(projectFilePath).Wait(); - }); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenProject_WithNonExistentProjectFile_Fails() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -1200,7 +1128,7 @@ public void TestOpenProject_WithNonExistentProjectFile_Fails() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithInvalidProjectReference_SkipTrue_SucceedsWithEvent() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1217,22 +1145,7 @@ public async Task TestOpenProject_WithInvalidProjectReference_SkipTrue_SucceedsW Assert.NotEmpty(workspace.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidProjectReference_SkipFalse_Fails() - { - CreateFiles(GetMultiProjectSolutionFiles() - .WithFile(@"VisualBasicProject\VisualBasicProject.vbproj", Resources.ProjectFiles.VisualBasic.InvalidProjectReference)); - var projectFilePath = GetSolutionFileName(@"VisualBasicProject\VisualBasicProject.vbproj"); - - AssertEx.Throws(() => - { - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - workspace.OpenProjectAsync(projectFilePath).Wait(); - }); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithNonExistentProjectReference_SkipTrue_SucceedsWithEvent() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1249,7 +1162,7 @@ public async Task TestOpenProject_WithNonExistentProjectReference_SkipTrue_Succe Assert.NotEmpty(workspace.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenProject_WithNonExistentProjectReference_SkipFalse_Fails() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1264,7 +1177,7 @@ public void TestOpenProject_WithNonExistentProjectReference_SkipFalse_Fails() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_SkipTrue_SucceedsWithEvent() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1282,7 +1195,7 @@ public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_ Assert.NotEmpty(workspace.Diagnostics); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public void TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_SkipFalse_Fails() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1298,7 +1211,7 @@ public void TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_SkipFa }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_WithMetadata_SkipTrue_SucceedsByLoadingMetadata() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1321,7 +1234,7 @@ public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_ Assert.Contains(metaRefs, r => r is PortableExecutableReference reference && reference.Display.Contains("CSharpProject.dll")); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_WithMetadata_SkipFalse_SucceedsByLoadingMetadata() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1343,7 +1256,7 @@ public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_ Assert.Contains(project.MetadataReferences, r => r is PortableExecutableReference reference && reference.Display.Contains("CSharpProject.dll")); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_BadMsbuildProject_SkipTrue_SucceedsWithDanglingProjectReference() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1367,7 +1280,7 @@ public async Task TestOpenProject_WithUnrecognizedProjectReferenceFileExtension_ Assert.InRange(workspace.Diagnostics.Count, 2, 3); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithReferencedProject_LoadMetadata_ExistingMetadata_Succeeds() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1389,7 +1302,7 @@ public async Task TestOpenProject_WithReferencedProject_LoadMetadata_ExistingMet Assert.Contains(metaRefs, r => r is PortableExecutableReference reference && reference.Display.Contains("CSharpProject.dll")); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WithReferencedProject_LoadMetadata_NonExistentMetadata_LoadsProjectInstead() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -1409,7 +1322,7 @@ public async Task TestOpenProject_WithReferencedProject_LoadMetadata_NonExistent Assert.DoesNotContain(metaRefs, r => r.Properties.Aliases.Contains("CSharpProject")); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_UpdateExistingReferences() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1438,7 +1351,7 @@ public async Task TestOpenProject_UpdateExistingReferences() Assert.DoesNotContain(vbProject.MetadataReferences, r => r.Properties.Aliases.Contains("CSharpProject")); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(Framework35Installed))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(Framework35Installed))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(528984, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/528984")] public async Task TestOpenProject_AddVBDefaultReferences() @@ -1460,182 +1373,182 @@ public async Task TestOpenProject_AddVBDefaultReferences() var diagnostics = compilation.GetDiagnostics(); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_DebugType_Full() { CreateCSharpFilesWith("DebugType", "full"); await AssertCSParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_DebugType_None() { CreateCSharpFilesWith("DebugType", "none"); await AssertCSParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_DebugType_PDBOnly() { CreateCSharpFilesWith("DebugType", "pdbonly"); await AssertCSParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_DebugType_Portable() { CreateCSharpFilesWith("DebugType", "portable"); await AssertCSParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_DebugType_Embedded() { CreateCSharpFilesWith("DebugType", "embedded"); await AssertCSParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OutputKind_DynamicallyLinkedLibrary() { CreateCSharpFilesWith("OutputType", "Library"); await AssertCSCompilationOptionsAsync(OutputKind.DynamicallyLinkedLibrary, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OutputKind_ConsoleApplication() { CreateCSharpFilesWith("OutputType", "Exe"); await AssertCSCompilationOptionsAsync(OutputKind.ConsoleApplication, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OutputKind_WindowsApplication() { CreateCSharpFilesWith("OutputType", "WinExe"); await AssertCSCompilationOptionsAsync(OutputKind.WindowsApplication, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OutputKind_NetModule() { CreateCSharpFilesWith("OutputType", "Module"); await AssertCSCompilationOptionsAsync(OutputKind.NetModule, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OptimizationLevel_Release() { CreateCSharpFilesWith("Optimize", "True"); await AssertCSCompilationOptionsAsync(OptimizationLevel.Release, options => options.OptimizationLevel); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_OptimizationLevel_Debug() { CreateCSharpFilesWith("Optimize", "False"); await AssertCSCompilationOptionsAsync(OptimizationLevel.Debug, options => options.OptimizationLevel); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_MainFileName() { CreateCSharpFilesWith("StartupObject", "Foo"); await AssertCSCompilationOptionsAsync("Foo", options => options.MainTypeName); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_AssemblyOriginatorKeyFile_SignAssembly_Missing() { CreateCSharpFiles(); await AssertCSCompilationOptionsAsync(null, options => options.CryptoKeyFile); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_AssemblyOriginatorKeyFile_SignAssembly_False() { CreateCSharpFilesWith("SignAssembly", "false"); await AssertCSCompilationOptionsAsync(null, options => options.CryptoKeyFile); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_AssemblyOriginatorKeyFile_SignAssembly_True() { CreateCSharpFilesWith("SignAssembly", "true"); await AssertCSCompilationOptionsAsync("snKey.snk", options => Path.GetFileName(options.CryptoKeyFile)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_AssemblyOriginatorKeyFile_DelaySign_False() { CreateCSharpFilesWith("DelaySign", "false"); await AssertCSCompilationOptionsAsync(null, options => options.DelaySign); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_AssemblyOriginatorKeyFile_DelaySign_True() { CreateCSharpFilesWith("DelaySign", "true"); await AssertCSCompilationOptionsAsync(true, options => options.DelaySign); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_CheckOverflow_True() { CreateCSharpFilesWith("CheckForOverflowUnderflow", "true"); await AssertCSCompilationOptionsAsync(true, options => options.CheckOverflow); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_CSharp_CheckOverflow_False() { CreateCSharpFilesWith("CheckForOverflowUnderflow", "false"); await AssertCSCompilationOptionsAsync(false, options => options.CheckOverflow); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_CSharp_Compatibility_ECMA1() { CreateCSharpFilesWith("LangVersion", "ISO-1"); await AssertCSParseOptionsAsync(CS.LanguageVersion.CSharp1, options => options.LanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_CSharp_Compatibility_ECMA2() { CreateCSharpFilesWith("LangVersion", "ISO-2"); await AssertCSParseOptionsAsync(CS.LanguageVersion.CSharp2, options => options.LanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_CSharp_Compatibility_None() { CreateCSharpFilesWith("LangVersion", "3"); await AssertCSParseOptionsAsync(CS.LanguageVersion.CSharp3, options => options.LanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/38301"), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/38301"), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_CSharp_LanguageVersion_Default() { CreateCSharpFiles(); await AssertCSParseOptionsAsync(CS.LanguageVersion.Default.MapSpecifiedToEffectiveVersion(), options => options.LanguageVersion); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_CSharp_PreprocessorSymbols() { CreateCSharpFilesWith("DefineConstants", "DEBUG;TRACE;X;Y"); await AssertCSParseOptionsAsync("DEBUG,TRACE,X,Y", options => string.Join(",", options.PreprocessorSymbolNames)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestConfigurationDebug() { CreateCSharpFiles(); await AssertCSParseOptionsAsync("DEBUG,TRACE", options => string.Join(",", options.PreprocessorSymbolNames)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestConfigurationRelease() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -1650,42 +1563,42 @@ public async Task TestConfigurationRelease() Assert.Contains(options.PreprocessorSymbolNames, name => name == "TRACE"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_DebugType_Full() { CreateVBFilesWith("DebugType", "full"); await AssertVBParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_DebugType_None() { CreateVBFilesWith("DebugType", "none"); await AssertVBParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_DebugType_PDBOnly() { CreateVBFilesWith("DebugType", "pdbonly"); await AssertVBParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_DebugType_Portable() { CreateVBFilesWith("DebugType", "portable"); await AssertVBParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_DebugType_Embedded() { CreateVBFilesWith("DebugType", "embedded"); await AssertVBParseOptionsAsync(0, options => options.Errors.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_VBRuntime_Embed() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1693,49 +1606,49 @@ public async Task TestCompilationOptions_VisualBasic_VBRuntime_Embed() await AssertVBCompilationOptionsAsync(true, options => options.EmbedVbCoreRuntime); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OutputKind_DynamicallyLinkedLibrary() { CreateVBFilesWith("OutputType", "Library"); await AssertVBCompilationOptionsAsync(OutputKind.DynamicallyLinkedLibrary, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OutputKind_ConsoleApplication() { CreateVBFilesWith("OutputType", "Exe"); await AssertVBCompilationOptionsAsync(OutputKind.ConsoleApplication, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OutputKind_WindowsApplication() { CreateVBFilesWith("OutputType", "WinExe"); await AssertVBCompilationOptionsAsync(OutputKind.WindowsApplication, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OutputKind_NetModule() { CreateVBFilesWith("OutputType", "Module"); await AssertVBCompilationOptionsAsync(OutputKind.NetModule, options => options.OutputKind); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_RootNamespace() { CreateVBFilesWith("RootNamespace", "Foo.Bar"); await AssertVBCompilationOptionsAsync("Foo.Bar", options => options.RootNamespace); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionStrict_On() { CreateVBFilesWith("OptionStrict", "On"); await AssertVBCompilationOptionsAsync(VB.OptionStrict.On, options => options.OptionStrict); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionStrict_Off() { CreateVBFilesWith("OptionStrict", "Off"); @@ -1746,77 +1659,77 @@ public async Task TestCompilationOptions_VisualBasic_OptionStrict_Off() await AssertVBCompilationOptionsAsync(VB.OptionStrict.Custom, options => options.OptionStrict); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionStrict_Custom() { CreateVBFilesWith("OptionStrictType", "Custom"); await AssertVBCompilationOptionsAsync(VB.OptionStrict.Custom, options => options.OptionStrict); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionInfer_True() { CreateVBFilesWith("OptionInfer", "On"); await AssertVBCompilationOptionsAsync(true, options => options.OptionInfer); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionInfer_False() { CreateVBFilesWith("OptionInfer", "Off"); await AssertVBCompilationOptionsAsync(false, options => options.OptionInfer); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionExplicit_True() { CreateVBFilesWith("OptionExplicit", "On"); await AssertVBCompilationOptionsAsync(true, options => options.OptionExplicit); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionExplicit_False() { CreateVBFilesWith("OptionExplicit", "Off"); await AssertVBCompilationOptionsAsync(false, options => options.OptionExplicit); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionCompareText_True() { CreateVBFilesWith("OptionCompare", "Text"); await AssertVBCompilationOptionsAsync(true, options => options.OptionCompareText); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionCompareText_False() { CreateVBFilesWith("OptionCompare", "Binary"); await AssertVBCompilationOptionsAsync(false, options => options.OptionCompareText); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionRemoveIntegerOverflowChecks_True() { CreateVBFilesWith("RemoveIntegerChecks", "true"); await AssertVBCompilationOptionsAsync(false, options => options.CheckOverflow); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionRemoveIntegerOverflowChecks_False() { CreateVBFilesWith("RemoveIntegerChecks", "false"); await AssertVBCompilationOptionsAsync(true, options => options.CheckOverflow); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_OptionAssemblyOriginatorKeyFile_SignAssemblyFalse() { CreateVBFilesWith("SignAssembly", "false"); await AssertVBCompilationOptionsAsync(null, options => options.CryptoKeyFile); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestCompilationOptions_VisualBasic_GlobalImports() { CreateFiles(GetMultiProjectSolutionFiles()); @@ -1841,7 +1754,7 @@ public async Task TestCompilationOptions_VisualBasic_GlobalImports() actual: imports.Select(i => i.Name)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestParseOptions_VisualBasic_PreprocessorSymbols() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1874,7 +1787,7 @@ public async Task TestParseOptions_VisualBasic_PreprocessorSymbols() actual: defines); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_VisualBasic_ConditionalAttributeEmitted() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1898,7 +1811,7 @@ public async Task Test_VisualBasic_ConditionalAttributeEmitted() Assert.Contains(attrs, ad => ad.AttributeClass.Name == "MyAttribute"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_VisualBasic_ConditionalAttributeNotEmitted() { CreateFiles(GetMultiProjectSolutionFiles() @@ -1921,7 +1834,7 @@ public async Task Test_VisualBasic_ConditionalAttributeNotEmitted() Assert.DoesNotContain(attrs, ad => ad.AttributeClass.Name == "MyAttribute"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_CSharp_ConditionalAttributeEmitted() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -1945,7 +1858,7 @@ public async Task Test_CSharp_ConditionalAttributeEmitted() Assert.Contains(attrs, ad => ad.AttributeClass.Name == "MyAttr"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task Test_CSharp_ConditionalAttributeNotEmitted() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -1968,7 +1881,7 @@ public async Task Test_CSharp_ConditionalAttributeNotEmitted() Assert.DoesNotContain(attrs, ad => ad.AttributeClass.Name == "MyAttr"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_CSharp_WithLinkedDocument() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -1992,7 +1905,7 @@ public async Task TestOpenProject_CSharp_WithLinkedDocument() Assert.Equal(Resources.SourceFiles.CSharp.OtherStuff_Foo, text); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestAddDocumentAsync() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2033,7 +1946,7 @@ public async Task TestAddDocumentAsync() Assert.Single(documentB.Folders); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestUpdateDocumentAsync() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2067,7 +1980,7 @@ public async Task TestUpdateDocumentAsync() Assert.Equal(originalText.ToString(), text.ToString()); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestRemoveDocumentAsync() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2094,7 +2007,7 @@ public async Task TestRemoveDocumentAsync() Assert.Equal(originalText.ToString(), text.ToString()); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestApplyChanges_UpdateDocumentText() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2121,7 +2034,7 @@ public async Task TestApplyChanges_UpdateDocumentText() Assert.Equal(newText.ToString(), textOnDisk); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestApplyChanges_AddDocument() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2147,7 +2060,7 @@ public async Task TestApplyChanges_AddDocument() Assert.Equal(newText.ToString(), textOnDisk); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestApplyChanges_NotSupportedChangesFail() { var csharpProjPath = @"AnalyzerSolution\CSharpProject_AnalyzerReference.csproj"; @@ -2181,7 +2094,7 @@ public async Task TestApplyChanges_NotSupportedChangesFail() }); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestWorkspaceChangedEvent() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2211,7 +2124,7 @@ public async Task TestWorkspaceChangedEvent() AsyncEventTimeout)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestWorkspaceChangedWeakEvent() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -2247,7 +2160,7 @@ public async Task TestWorkspaceChangedWeakEvent() AsyncEventTimeout)); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(529276, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/529276"), WorkItem(12086, "DevDiv_Projects/Roslyn")] public async Task TestOpenProject_LoadMetadataForReferenceProjects_NoMetadata() { @@ -2272,7 +2185,7 @@ public async Task TestOpenProject_LoadMetadataForReferenceProjects_NoMetadata() Assert.Empty(errs); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(918072, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/918072")] public async Task TestAnalyzerReferenceLoadStandalone() { @@ -2297,7 +2210,7 @@ public async Task TestAnalyzerReferenceLoadStandalone() Assert.Equal(2, workspace.CurrentSolution.Projects.Count()); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestAdditionalFilesStandalone() { var projPaths = new[] { @"AnalyzerSolution\CSharpProject_AnalyzerReference.csproj", @"AnalyzerSolution\VisualBasicProject_AnalyzerReference.vbproj" }; @@ -2318,7 +2231,7 @@ public async Task TestAdditionalFilesStandalone() } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestLoadTextSync() { var files = GetAnalyzerReferenceSolutionFiles(); @@ -2339,7 +2252,7 @@ public async Task TestLoadTextSync() Assert.Contains("Window", atav.Text.ToString(), StringComparison.Ordinal); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestGetTextSynchronously() { var files = GetAnalyzerReferenceSolutionFiles(); @@ -2358,7 +2271,7 @@ public async Task TestGetTextSynchronously() Assert.Contains("Window", atext.ToString(), StringComparison.Ordinal); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(546171, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546171")] public async Task TestCSharpExternAlias() { @@ -2376,7 +2289,7 @@ public async Task TestCSharpExternAlias() comp.GetDiagnostics().Where(d => d.Severity > DiagnosticSeverity.Info).Verify(); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(530337, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530337")] public async Task TestProjectReferenceWithExternAlias() { @@ -2392,7 +2305,7 @@ public async Task TestProjectReferenceWithExternAlias() comp.GetDiagnostics().Where(d => d.Severity > DiagnosticSeverity.Info).Verify(); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestProjectReferenceWithReferenceOutputAssemblyFalse() { var files = GetProjectReferenceSolutionFiles(); @@ -2441,7 +2354,7 @@ private static string VisitProjectReferences(string projectFileText, ActionReplaceMe", "1254")), - ("class1.cs", "//\u201C")); - - CreateFiles(files); - - var projPath = GetSolutionFileName("Encoding.csproj"); - using var workspace = CreateMSBuildWorkspace(); - var project = await workspace.OpenProjectAsync(projPath); - var document = project.Documents.First(d => d.Name == "class1.cs"); - var text = await document.GetTextAsync(); - Assert.Equal(Encoding.GetEncoding(1254), text.Encoding); - - // The smart quote (“) in class1.cs shows up as "“" in codepage 1254. Do a sanity - // check here to make sure this file hasn't been corrupted in a way that would - // impact subsequent asserts. - Assert.Equal(5, "//\u00E2\u20AC\u0153".Length); - Assert.Equal("//\u00E2\u20AC\u0153".Length, text.Length); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(991528, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991528")] public async Task MSBuildProjectShouldHandleInvalidCodePageProperty() { @@ -2758,7 +2647,7 @@ public async Task MSBuildProjectShouldHandleInvalidCodePageProperty() Assert.Equal(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true), text.Encoding); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(991528, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991528")] public async Task MSBuildProjectShouldHandleInvalidCodePageProperty2() { @@ -2777,7 +2666,7 @@ public async Task MSBuildProjectShouldHandleInvalidCodePageProperty2() Assert.Equal(new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true), text.Encoding); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(991528, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991528")] public async Task MSBuildProjectShouldHandleDefaultCodePageProperty() { @@ -2797,7 +2686,7 @@ public async Task MSBuildProjectShouldHandleDefaultCodePageProperty() Assert.Equal("//\u201C", text.ToString()); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(981208, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/981208")] [WorkItem(28639, "https://github.com/dotnet/roslyn/issues/28639")] public void DisposeMSBuildWorkspaceAndServicesCollected() @@ -2827,7 +2716,7 @@ public void DisposeMSBuildWorkspaceAndServicesCollected() sol.AssertReleased(); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(1088127, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1088127")] public async Task MSBuildWorkspacePreservesEncoding() { @@ -2886,98 +2775,7 @@ class C { }"; Assert.Equal(encoding.EncodingName, reloadedText.Encoding.EncodingName); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public async Task TestAddRemoveMetadataReference_GAC() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - - var projFile = GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"); - var projFileText = File.ReadAllText(projFile); - Assert.False(projFileText.Contains(@"System.Xaml")); - - using var workspace = CreateMSBuildWorkspace(); - var solutionFilePath = GetSolutionFileName("TestSolution.sln"); - var solution = await workspace.OpenSolutionAsync(solutionFilePath); - var project = solution.Projects.First(); - - var mref = MetadataReference.CreateFromFile(typeof(System.Xaml.XamlObjectReader).Assembly.Location); - - // add reference to System.Xaml - workspace.TryApplyChanges(project.AddMetadataReference(mref).Solution); - projFileText = File.ReadAllText(projFile); - Assert.Contains(@" p.Language == LanguageNames.CSharp); - var vbProject = solution.Projects.First(p => p.Language == LanguageNames.VisualBasic); - - var numericsMetadata = csProject.MetadataReferences.Single(m => m.Display.Contains("System.Numerics")); - - // add reference to System.Xaml - workspace.TryApplyChanges(vbProject.AddMetadataReference(numericsMetadata).Solution); - var newVbProjFileText = File.ReadAllText(vbProjFile); - Assert.Contains(@"..\References\MyAssembly.dll", projFileText); - - // remove reference MyAssembly.dll - workspace.TryApplyChanges(workspace.CurrentSolution.GetProject(project.Id).RemoveMetadataReference(mref).Solution); - projFileText = File.ReadAllText(projFile); - Assert.DoesNotContain(@"..\References\MyAssembly.dll", projFileText); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestAddRemoveAnalyzerReference() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3006,7 +2804,7 @@ public async Task TestAddRemoveAnalyzerReference() Assert.DoesNotContain(@"", projFileText); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(1101040, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/1101040")] public async Task TestOpenProject_BadLink() { @@ -3051,7 +2849,7 @@ public async Task TestOpenProject_BadLink() Assert.Equal(3, docs.Count); } - [ConditionalFact(typeof(IsEnglishLocal), typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(IsEnglishLocal), typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_BadElement() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3068,7 +2866,7 @@ public async Task TestOpenProject_BadElement() Assert.Empty(proj.DocumentIds); } - [ConditionalFact(typeof(IsEnglishLocal), typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(IsEnglishLocal), typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_BadTaskImport() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3085,7 +2883,7 @@ public async Task TestOpenProject_BadTaskImport() Assert.Empty(proj.DocumentIds); } - [ConditionalFact(typeof(IsEnglishLocal), typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(IsEnglishLocal), typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenSolution_BadTaskImport() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3103,7 +2901,7 @@ public async Task TestOpenSolution_BadTaskImport() Assert.Empty(project.DocumentIds); } - [ConditionalFact(typeof(IsEnglishLocal), typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(IsEnglishLocal), typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_MsbuildError() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3118,7 +2916,7 @@ public async Task TestOpenProject_MsbuildError() Assert.StartsWith("Msbuild failed", diagnostic.Message); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_WildcardsWithLink() { CreateFiles(GetSimpleCSharpSolutionFiles() @@ -3133,7 +2931,7 @@ public async Task TestOpenProject_WildcardsWithLink() Assert.Contains(proj.Documents, d => d.Name == "AssemblyInfo.cs"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestOpenProject_CommandLineArgsHaveNoErrors() { CreateFiles(GetSimpleCSharpSolutionFiles()); @@ -3166,7 +2964,7 @@ public async Task TestOpenProject_CommandLineArgsHaveNoErrors() Assert.Empty(commandLineArgs.Errors); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(29122, "https://github.com/dotnet/roslyn/issues/29122")] public async Task TestOpenSolution_ProjectReferencesWithUnconventionalOutputPaths() { @@ -3203,7 +3001,7 @@ public async Task TestOpenSolution_ProjectReferencesWithUnconventionalOutputPath } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(29494, "https://github.com/dotnet/roslyn/issues/29494")] public async Task TestOpenProjectAsync_MalformedAdditionalFilePath() { @@ -3225,7 +3023,7 @@ public async Task TestOpenProjectAsync_MalformedAdditionalFilePath() Assert.Contains(project.AdditionalDocuments, doc => doc.Name == "TEST::"); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(31390, "https://github.com/dotnet/roslyn/issues/31390")] public async Task TestDuplicateProjectAndMetadataReferences() { @@ -3249,7 +3047,7 @@ public async Task TestDuplicateProjectAndMetadataReferences() Assert.Single(compilation.References.OfType()); } - [ConditionalFact(typeof(VisualStudio16_2OrHigherMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuild16_2OrHigherInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestEditorConfigDiscovery() { var files = GetSimpleCSharpSolutionFiles() @@ -3273,7 +3071,7 @@ public async Task TestEditorConfigDiscovery() Assert.Equal("root = true", text.ToString()); } - [ConditionalFact(typeof(VisualStudio16_2OrHigherMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuild16_2OrHigherInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestEditorConfigDiscoveryDisabled() { var files = GetSimpleCSharpSolutionFiles() @@ -3290,7 +3088,7 @@ public async Task TestEditorConfigDiscoveryDisabled() Assert.Empty(project.AnalyzerConfigDocuments); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestSolutionFilterSupport() { CreateFiles(GetMultiProjectSolutionFiles() @@ -3304,7 +3102,7 @@ public async Task TestSolutionFilterSupport() Assert.Equal(LanguageNames.CSharp, csharpProject.Language); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [ConditionalFact(typeof(MSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestInvalidSolutionFilterDoesNotLoad() { CreateFiles(GetMultiProjectSolutionFiles() diff --git a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj index 3d0c6e993c0ab..808dca423ea9e 100644 --- a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj +++ b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj @@ -4,7 +4,7 @@ Library Microsoft.CodeAnalysis.MSBuild.UnitTests - net472 + netcoreapp3.1;net472 @@ -26,12 +26,12 @@ - + - + false diff --git a/src/Workspaces/MSBuildTest/NetCoreTests.cs b/src/Workspaces/MSBuildTest/NetCoreTests.cs index 805a3018d0c8d..8e418ecac7af2 100644 --- a/src/Workspaces/MSBuildTest/NetCoreTests.cs +++ b/src/Workspaces/MSBuildTest/NetCoreTests.cs @@ -62,7 +62,7 @@ private void DotNetBuild(string solutionOrProjectFileName, string configuration RunDotNet(arguments); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProject_NetCoreApp2() @@ -88,7 +88,7 @@ public async Task TestOpenProject_NetCoreApp2() } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProjectTwice_NetCoreApp2AndLibrary() @@ -125,7 +125,7 @@ public async Task TestOpenProjectTwice_NetCoreApp2AndLibrary() Assert.Equal(libraryProject.FilePath, workspace.CurrentSolution.GetProject(projectRefId).FilePath); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProjectTwice_NetCoreApp2AndTwoLibraries() @@ -173,7 +173,7 @@ static void AssertSingleProjectReference(Project project, string projectRefFileP } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProject_NetCoreMultiTFM() @@ -217,7 +217,7 @@ public async Task TestOpenProject_NetCoreMultiTFM() } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProject_NetCoreMultiTFM_ExtensionWithConditionOnTFM() @@ -261,7 +261,7 @@ public async Task TestOpenProject_NetCoreMultiTFM_ExtensionWithConditionOnTFM() } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProject_NetCoreMultiTFM_ProjectReference() @@ -369,7 +369,7 @@ private static async Task AssertNetCoreMultiTFMProject(string projectFilePath) } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/41917")] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable), AlwaysSkip = "https://github.com/dotnet/roslyn/issues/41917")] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenSolution_NetCoreMultiTFMWithProjectReferenceToFSharp() @@ -429,7 +429,7 @@ public async Task TestOpenProject_ReferenceConfigurationSpecificMetadata() } } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] + [ConditionalFact(typeof(MSBuildInstalled), typeof(DotNetCoreSdk.IsAvailable))] [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [Trait(Traits.Feature, Traits.Features.NetCore)] public async Task TestOpenProject_OverrideTFM() diff --git a/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs b/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs index 5baa4e5914ad9..f5f50b6f75a58 100644 --- a/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs +++ b/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs @@ -2,213 +2,49 @@ // 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; -using System.Collections.Immutable; -using System.IO; using System.Linq; -using System.Reflection; -using System.Runtime.InteropServices; -using Microsoft.VisualStudio.Setup.Configuration; +using Microsoft.Build.Locator; using Roslyn.Test.Utilities; namespace Microsoft.CodeAnalysis.MSBuild.UnitTests { internal class VisualStudioMSBuildInstalled : ExecutionCondition { - private static bool s_isRegistered; - - private readonly Version _minimumVersion; - - public VisualStudioMSBuildInstalled() : this(new Version(15, 0)) - { + private static readonly VisualStudioInstance? s_instance; - } - protected VisualStudioMSBuildInstalled(Version minimumVersion) +#if !NETCOREAPP + static VisualStudioMSBuildInstalled() { - _minimumVersion = minimumVersion; - } + s_instance = MSBuildLocator.QueryVisualStudioInstances() + .OrderByDescending(instances => instances.Version) + .FirstOrDefault(); - public override bool ShouldSkip - { - get + if (s_instance != null && !MSBuildLocator.IsRegistered) { - if (VisualStudioMSBuildLocator.TryFindMSBuildToolsPath(out var versionAndPath)) - { - if (versionAndPath.version < _minimumVersion) - { - return true; - } - - if (!s_isRegistered) - { - RegisterMSBuildAssemblyResolution(versionAndPath.path); - - s_isRegistered = true; - } - - return false; - } - - return true; + MSBuildLocator.RegisterInstance(s_instance); } } +#endif - public override string SkipReason => $"Could not locate Visual Studio with MSBuild {_minimumVersion} or higher installed"; - - private static void RegisterMSBuildAssemblyResolution(string msbuildToolsPath) - { - if (s_isRegistered) - { - throw new InvalidOperationException("Attempted to register twice!"); - } - - var assemblyNames = new[] - { - "Microsoft.Build", - "Microsoft.Build.Framework", - "Microsoft.Build.Tasks.Core", - "Microsoft.Build.Utilities.Core" - }; - - var builder = ImmutableDictionary.CreateBuilder(StringComparer.OrdinalIgnoreCase); - - foreach (var assemblyName in assemblyNames) - { - var assemblyFilePath = Path.Combine(msbuildToolsPath, assemblyName + ".dll"); - var assembly = File.Exists(assemblyFilePath) - ? Assembly.LoadFrom(assemblyFilePath) - : null; - - if (assembly != null) - { - builder.Add(assemblyName, assembly); - } - } - - var assemblyMap = builder.ToImmutable(); - - AppDomain.CurrentDomain.AssemblyResolve += (_, e) => - { - var assemblyName = new AssemblyName(e.Name); - - if (assemblyMap.TryGetValue(assemblyName.Name, out var assembly)) - { - return assembly; - } - - return null; - }; - } - } - - internal class VisualStudio16_2OrHigherMSBuildInstalled : VisualStudioMSBuildInstalled - { - public VisualStudio16_2OrHigherMSBuildInstalled() : base(new Version(16, 2)) - { - } - } + private readonly Version _minimumVersion; - internal class VisualStudio16_9_Preview3OrHigherMSBuildInstalled : VisualStudioMSBuildInstalled - { - public VisualStudio16_9_Preview3OrHigherMSBuildInstalled() : base(new Version(16, 9, 30914, 41)) + public VisualStudioMSBuildInstalled() : this(new Version(15, 0)) { } - } - - internal static class VisualStudioMSBuildLocator - { - private static readonly Lazy<(Version version, string path)> s_versionAndPath = new(FindMSBuildToolsPathFromVisualStudioCore); - public static bool TryFindMSBuildToolsPath(out (Version version, string path) versionAndPath) + internal VisualStudioMSBuildInstalled(Version minimumVersion) { - versionAndPath = s_versionAndPath.Value; - return versionAndPath.path != null; + _minimumVersion = minimumVersion; } - private static (Version version, string path) FindMSBuildToolsPathFromVisualStudioCore() - { - // Only on Windows - if (Path.DirectorySeparatorChar != '\\') - { - return (null, null); - } + public override bool ShouldSkip => s_instance is null || s_instance.Version < _minimumVersion; - try - { - var configuration = Interop.GetSetupConfiguration(); - if (configuration == null) - { - return (null, null); - } - - var instanceEnum = configuration.EnumAllInstances(); - var instances = new ISetupInstance[1]; - - (Version version, string path) found = (null, null); - - while (true) - { - instanceEnum.Next(1, instances, out var fetched); - if (fetched <= 0) - { - break; - } - - var instance2 = (ISetupInstance2)instances[0]; - var state = instance2.GetState(); - if (state == InstanceState.Complete && - instance2.GetPackages().Any(package => package.GetId() == "Microsoft.VisualStudio.Component.Roslyn.Compiler")) - { - var instanceVersionString = instance2.GetInstallationVersion(); - - if (!Version.TryParse(instanceVersionString, out var instanceVersion)) - { - // We'll throw an exception here -- this means we have some build with a new style of version numbers, which is probably the high version we want to pick but - // we won't know it - throw new Exception($"Unable to parse version string '{instanceVersionString}'"); - } - - var toolsBasePath = Path.Combine(instance2.GetInstallationPath(), "MSBuild"); - string instanceMsBuildPath = null; - - // Visual Studio 2019 and later place MSBuild in a "Current" folder. - var toolsPath = Path.Combine(toolsBasePath, "Current", "Bin"); - if (Directory.Exists(toolsPath)) - { - instanceMsBuildPath = toolsPath; - } - else - { - // Check for 15.0 to support Visual Studio 2017. We have this in an else block because in 2019 there's also this folder for compat reasons - toolsPath = Path.Combine(toolsBasePath, "15.0", "Bin"); - if (Directory.Exists(toolsPath)) - { - instanceMsBuildPath = toolsPath; - } - } - - // We found some version; we will always use the highest possible version because we want to support the running of the most tests - // possible -- we can't load multiple versions sanely unless we tried multiple AppDomains - if (instanceMsBuildPath != null && (found.version == null || instanceVersion > found.version)) - { - found.version = instanceVersion; - found.path = instanceMsBuildPath; - } - } - } - - return found; - } - catch (COMException) - { - return (null, null); - } - catch (DllNotFoundException) - { - return (null, null); - } - } + public override string SkipReason +#if !NETCOREAPP + => $"Could not locate Visual Studio with MSBuild {_minimumVersion} or higher installed"; +#else + => $"Test runs on .NET Framework"; +#endif } } diff --git a/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs new file mode 100644 index 0000000000000..3741132d03a16 --- /dev/null +++ b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs @@ -0,0 +1,219 @@ +// 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 System; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.CodeAnalysis.Test.Utilities; +using Microsoft.CodeAnalysis.UnitTests; +using Microsoft.CodeAnalysis.UnitTests.TestFiles; +using Roslyn.Test.Utilities; +using Roslyn.Utilities; +using Xunit; + +namespace Microsoft.CodeAnalysis.MSBuild.UnitTests +{ + public class VisualStudioMSBuildWorkspaceTests : MSBuildWorkspaceTestBase + { + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + [WorkItem(991528, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991528")] + public async Task MSBuildProjectShouldHandleCodePageProperty() + { + var files = new FileSet( + ("Encoding.csproj", Resources.ProjectFiles.CSharp.Encoding.Replace("ReplaceMe", "1254")), + ("class1.cs", "//\u201C")); + + CreateFiles(files); + + var projPath = GetSolutionFileName("Encoding.csproj"); + using var workspace = CreateMSBuildWorkspace(); + var project = await workspace.OpenProjectAsync(projPath); + var document = project.Documents.First(d => d.Name == "class1.cs"); + var text = await document.GetTextAsync(); + Assert.Equal(Encoding.GetEncoding(1254), text.Encoding); + + // The smart quote (“) in class1.cs shows up as "“" in codepage 1254. Do a sanity + // check here to make sure this file hasn't been corrupted in a way that would + // impact subsequent asserts. + Assert.Equal(5, "//\u00E2\u20AC\u0153".Length); + Assert.Equal("//\u00E2\u20AC\u0153".Length, text.Length); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenProject_WithInvalidFilePath_Fails() + { + CreateFiles(GetSimpleCSharpSolutionFiles()); + var projectFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidProject.csproj"); + + using var workspace = CreateMSBuildWorkspace(); + + AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenProject_WithInvalidProjectReference_SkipFalse_Fails() + { + CreateFiles(GetMultiProjectSolutionFiles() + .WithFile(@"VisualBasicProject\VisualBasicProject.vbproj", Resources.ProjectFiles.VisualBasic.InvalidProjectReference)); + var projectFilePath = GetSolutionFileName(@"VisualBasicProject\VisualBasicProject.vbproj"); + + using var workspace = CreateMSBuildWorkspace(); + workspace.SkipUnrecognizedProjects = false; + + AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenSolution_WithInvalidProjectPath_SkipFalse_Fails() + { + // when not skipped we should get an exception for the invalid project + + CreateFiles(GetSimpleCSharpSolutionFiles() + .WithFile(@"TestSolution.sln", Resources.SolutionFiles.InvalidProjectPath)); + var solutionFilePath = GetSolutionFileName(@"TestSolution.sln"); + + using var workspace = CreateMSBuildWorkspace(); + workspace.SkipUnrecognizedProjects = false; + + AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public void TestOpenSolution_WithInvalidSolutionFile_Fails() + { + CreateFiles(GetSimpleCSharpSolutionFiles()); + var solutionFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidSolution.sln"); + + using var workspace = CreateMSBuildWorkspace(); + + AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public async Task TestAddRemoveMetadataReference_GAC() + { + CreateFiles(GetSimpleCSharpSolutionFiles()); + + var projFile = GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"); + var projFileText = File.ReadAllText(projFile); + Assert.False(projFileText.Contains(@"System.Xaml")); + + using var workspace = CreateMSBuildWorkspace(); + var solutionFilePath = GetSolutionFileName("TestSolution.sln"); + var solution = await workspace.OpenSolutionAsync(solutionFilePath); + var project = solution.Projects.First(); + + var mref = MetadataReference.CreateFromFile(typeof(System.Xaml.XamlObjectReader).Assembly.Location); + + // add reference to System.Xaml + workspace.TryApplyChanges(project.AddMetadataReference(mref).Solution); + projFileText = File.ReadAllText(projFile); + Assert.Contains(@"..\References\MyAssembly.dll", projFileText); + + // remove reference MyAssembly.dll + workspace.TryApplyChanges(workspace.CurrentSolution.GetProject(project.Id).RemoveMetadataReference(mref).Solution); + projFileText = File.ReadAllText(projFile); + Assert.DoesNotContain(@"..\References\MyAssembly.dll", projFileText); + } + + [ConditionalFact(typeof(VisualStudioMSBuildInstalled))] + [Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] + public async Task TestAddRemoveMetadataReference_ReferenceAssembly() + { + CreateFiles(GetMultiProjectSolutionFiles() + .WithFile(@"CSharpProject\CSharpProject.csproj", Resources.ProjectFiles.CSharp.WithSystemNumerics)); + + var csProjFile = GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"); + var csProjFileText = File.ReadAllText(csProjFile); + Assert.True(csProjFileText.Contains(@" p.Language == LanguageNames.CSharp); + var vbProject = solution.Projects.First(p => p.Language == LanguageNames.VisualBasic); + + var numericsMetadata = csProject.MetadataReferences.Single(m => m.Display.Contains("System.Numerics")); + + // add reference to System.Xaml + workspace.TryApplyChanges(vbProject.AddMetadataReference(numericsMetadata).Solution); + var newVbProjFileText = File.ReadAllText(vbProjFile); + Assert.Contains(@" d.Name == "App.xaml.cs"); + Assert.Contains(documents, d => d.Name == "MainWindow.xaml.cs"); + + // prove no xaml files are documents + Assert.DoesNotContain(documents, d => d.Name.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase)); + + // prove that generated source files for xaml files are included in documents list + Assert.Contains(documents, d => d.Name == "App.g.cs"); + Assert.Contains(documents, d => d.Name == "MainWindow.g.cs"); + } + } +} From 2ae18c13421cc83f6382c1c4a06f80dc15facad3 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 31 Mar 2021 17:56:09 -0700 Subject: [PATCH 2/3] Apply suggestion from code review. --- ...ildInstalled.LooseAssemblyVersionLoader.cs | 114 ------------------ .../MSBuildTest/DotNetSdkMSBuildInstalled.cs | 7 +- .../DotNetSdkMSBuildWorkspaceTests.cs | 67 ---------- .../MSBuildTest/MSBuildInstalled.cs | 9 ++ .../VisualStudioMSBuildInstalled.cs | 4 +- .../VisualStudioMSBuildWorkspaceTests.cs | 51 +------- 6 files changed, 13 insertions(+), 239 deletions(-) delete mode 100644 src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs delete mode 100644 src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs deleted file mode 100644 index 229f37e04a82d..0000000000000 --- a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.LooseAssemblyVersionLoader.cs +++ /dev/null @@ -1,114 +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. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Reflection; -#if NETCOREAPP -using System.Runtime.Loader; -#endif - -namespace Microsoft.CodeAnalysis.MSBuild.UnitTests -{ - internal partial class DotNetSdkMSBuildInstalled - { -#if NETCOREAPP - - private static class LooseVersionAssemblyLoader - { - private static readonly Dictionary s_pathsToAssemblies = new(StringComparer.OrdinalIgnoreCase); - private static readonly Dictionary s_namesToAssemblies = new(); - - private static readonly object s_guard = new(); - private static readonly string[] s_extensions = new[] { "ni.dll", "ni.exe", "dll", "exe" }; - - /// - /// Register an assembly loader that will load assemblies with higher version than what was requested. - /// - public static void Register(string searchPath) - { - AssemblyLoadContext.Default.Resolving += (AssemblyLoadContext context, AssemblyName assemblyName) => - { - lock (s_guard) - { - if (s_namesToAssemblies.TryGetValue(assemblyName.FullName, out var cachedAssembly)) - { - return cachedAssembly; - } - - var assembly = TryResolveAssemblyFromPaths(context, assemblyName, searchPath); - - // Cache assembly - if (assembly != null) - { - var name = assembly.FullName; - if (name is null) - { - throw new Exception($"Could not get name for assembly '{assembly}'"); - } - - s_pathsToAssemblies[assembly.Location] = assembly; - s_namesToAssemblies[name] = assembly; - } - - return assembly; - } - }; - } - - private static Assembly? TryResolveAssemblyFromPaths(AssemblyLoadContext context, AssemblyName assemblyName, string searchPath) - { - foreach (var cultureSubfolder in string.IsNullOrEmpty(assemblyName.CultureName) - // If no culture is specified, attempt to load directly from - // the known dependency paths. - ? new[] { string.Empty } - // Search for satellite assemblies in culture subdirectories - // of the assembly search directories, but fall back to the - // bare search directory if that fails. - : new[] { assemblyName.CultureName, string.Empty }) - { - foreach (var extension in s_extensions) - { - var candidatePath = Path.Combine( - searchPath, cultureSubfolder, $"{assemblyName.Name}.{extension}"); - - var isAssemblyLoaded = s_pathsToAssemblies.ContainsKey(candidatePath) == true; - if (isAssemblyLoaded || !File.Exists(candidatePath)) - { - continue; - } - - var candidateAssemblyName = AssemblyLoadContext.GetAssemblyName(candidatePath); - if (candidateAssemblyName.Version < assemblyName.Version) - { - continue; - } - - try - { - var assembly = context.LoadFromAssemblyPath(candidatePath); - - return assembly; - } - catch - { - if (assemblyName.Name != null) - { - // We were unable to load the assembly from the file path. It is likely that - // a different version of the assembly has already been loaded into the context. - // Be forgiving and attempt to load assembly by name without specifying a version. - return context.LoadFromAssemblyName(new AssemblyName(assemblyName.Name)); - } - } - } - } - - return null; - } - } - -#endif - } -} diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs index b623901d72f68..31d92339f03c2 100644 --- a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs +++ b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildInstalled.cs @@ -13,7 +13,6 @@ internal partial class DotNetSdkMSBuildInstalled : ExecutionCondition { private static readonly VisualStudioInstance? s_instance; -#if NETCOREAPP static DotNetSdkMSBuildInstalled() { s_instance = MSBuildLocator.QueryVisualStudioInstances() @@ -22,11 +21,9 @@ static DotNetSdkMSBuildInstalled() if (s_instance != null && !MSBuildLocator.IsRegistered) { - LooseVersionAssemblyLoader.Register(s_instance.MSBuildPath); MSBuildLocator.RegisterInstance(s_instance); } } -#endif private readonly Version _minimumVersion; @@ -43,9 +40,9 @@ internal DotNetSdkMSBuildInstalled(Version minimumVersion) public override string SkipReason #if NETCOREAPP - => $"Could not locate .NET SDK {_minimumVersion} or higher installed"; + => $"Could not locate .NET SDK {_minimumVersion} or higher installed."; #else - => $"Test runs on .NET Core"; + => $"Test runs on .NET Core only."; #endif } } diff --git a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs deleted file mode 100644 index 5778e0b6ae97c..0000000000000 --- a/src/Workspaces/MSBuildTest/DotNetSdkMSBuildWorkspaceTests.cs +++ /dev/null @@ -1,67 +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 System.IO; -using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.CodeAnalysis.UnitTests.TestFiles; -using Roslyn.Test.Utilities; -using Xunit; - -namespace Microsoft.CodeAnalysis.MSBuild.UnitTests -{ - public class DotNetSdkMSBuildWorkspaceTests : MSBuildWorkspaceTestBase - { - [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidFilePath_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var projectFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidProject.csproj"); - - using var workspace = CreateMSBuildWorkspace(); - - AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); - } - - [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidProjectReference_SkipFalse_Fails() - { - CreateFiles(GetMultiProjectSolutionFiles() - .WithFile(@"VisualBasicProject\VisualBasicProject.vbproj", Resources.ProjectFiles.VisualBasic.InvalidProjectReference)); - var projectFilePath = GetSolutionFileName(@"VisualBasicProject\VisualBasicProject.vbproj"); - - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - - AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); - } - - [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidProjectPath_SkipFalse_Fails() - { - // when not skipped we should get an exception for the invalid project - - CreateFiles(GetSimpleCSharpSolutionFiles() - .WithFile(@"TestSolution.sln", Resources.SolutionFiles.InvalidProjectPath)); - var solutionFilePath = GetSolutionFileName(@"TestSolution.sln"); - - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - - AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); - } - - [ConditionalFact(typeof(DotNetSdkMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidSolutionFile_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var solutionFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidSolution.sln"); - - using var workspace = CreateMSBuildWorkspace(); - - AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); - } - } -} diff --git a/src/Workspaces/MSBuildTest/MSBuildInstalled.cs b/src/Workspaces/MSBuildTest/MSBuildInstalled.cs index 224f195459d5e..fc7b66fddc858 100644 --- a/src/Workspaces/MSBuildTest/MSBuildInstalled.cs +++ b/src/Workspaces/MSBuildTest/MSBuildInstalled.cs @@ -7,6 +7,10 @@ namespace Microsoft.CodeAnalysis.MSBuild.UnitTests { + /// + /// These tests will run with either VS installed or with a .NET (Core) SDK installed. The + /// MSBuild used depends on the TargetFramework of the test project being executed. + /// internal class MSBuildInstalled : ExecutionCondition { private readonly ExecutionCondition _msBuildInstalled; @@ -16,6 +20,11 @@ public MSBuildInstalled() { } + /// + /// These tests will run with either the VS installed or with a .NET (Core) SDK installed. The + /// MSBuild used depends on the TargetFramework of the test project being executed. Include valid + /// minimum versions for both. + /// protected MSBuildInstalled(Version minimumVsVersion, Version minimumSdkVersion) { _msBuildInstalled = diff --git a/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs b/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs index f5f50b6f75a58..5bc7afdf9e039 100644 --- a/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs +++ b/src/Workspaces/MSBuildTest/VisualStudioMSBuildInstalled.cs @@ -13,7 +13,6 @@ internal class VisualStudioMSBuildInstalled : ExecutionCondition { private static readonly VisualStudioInstance? s_instance; -#if !NETCOREAPP static VisualStudioMSBuildInstalled() { s_instance = MSBuildLocator.QueryVisualStudioInstances() @@ -25,7 +24,6 @@ static VisualStudioMSBuildInstalled() MSBuildLocator.RegisterInstance(s_instance); } } -#endif private readonly Version _minimumVersion; @@ -44,7 +42,7 @@ public override string SkipReason #if !NETCOREAPP => $"Could not locate Visual Studio with MSBuild {_minimumVersion} or higher installed"; #else - => $"Test runs on .NET Framework"; + => $"Test runs on .NET Framework only."; #endif } } diff --git a/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs index 3741132d03a16..1225a529757c4 100644 --- a/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs +++ b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs @@ -20,6 +20,7 @@ namespace Microsoft.CodeAnalysis.MSBuild.UnitTests { public class VisualStudioMSBuildWorkspaceTests : MSBuildWorkspaceTestBase { + // On .NET Core this tests fails with "CodePape Not Found" [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] [WorkItem(991528, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/991528")] public async Task MSBuildProjectShouldHandleCodePageProperty() @@ -44,56 +45,6 @@ public async Task MSBuildProjectShouldHandleCodePageProperty() Assert.Equal("//\u00E2\u20AC\u0153".Length, text.Length); } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidFilePath_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var projectFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidProject.csproj"); - - using var workspace = CreateMSBuildWorkspace(); - - AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenProject_WithInvalidProjectReference_SkipFalse_Fails() - { - CreateFiles(GetMultiProjectSolutionFiles() - .WithFile(@"VisualBasicProject\VisualBasicProject.vbproj", Resources.ProjectFiles.VisualBasic.InvalidProjectReference)); - var projectFilePath = GetSolutionFileName(@"VisualBasicProject\VisualBasicProject.vbproj"); - - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - - AssertEx.Throws(() => workspace.OpenProjectAsync(projectFilePath).Wait()); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidProjectPath_SkipFalse_Fails() - { - // when not skipped we should get an exception for the invalid project - - CreateFiles(GetSimpleCSharpSolutionFiles() - .WithFile(@"TestSolution.sln", Resources.SolutionFiles.InvalidProjectPath)); - var solutionFilePath = GetSolutionFileName(@"TestSolution.sln"); - - using var workspace = CreateMSBuildWorkspace(); - workspace.SkipUnrecognizedProjects = false; - - AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); - } - - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] - public void TestOpenSolution_WithInvalidSolutionFile_Fails() - { - CreateFiles(GetSimpleCSharpSolutionFiles()); - var solutionFilePath = GetSolutionFileName(@"http://localhost/Invalid/InvalidSolution.sln"); - - using var workspace = CreateMSBuildWorkspace(); - - AssertEx.Throws(() => workspace.OpenSolutionAsync(solutionFilePath).Wait()); - } - [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)] public async Task TestAddRemoveMetadataReference_GAC() { From afcbf87b1293a98d684b78c9ae77a608c9f6ff7f Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 16 Jun 2021 18:21:14 -0700 Subject: [PATCH 3/3] Reference NuGet package from Workspace.MSBuild.UnitTests --- eng/Versions.props | 11 +++++++++++ ...t.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/eng/Versions.props b/eng/Versions.props index 819e961a864aa..b31580ed16a39 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -195,6 +195,17 @@ 6.6.0.161 4.10.1 2.6.81 + + 5.10.0 + 5.10.0 + 5.10.0 + 5.10.0 + 5.10.0 + 5.10.0 4.0.0-rc-2048 4.8.0 1.1.0-beta1-62506-02 diff --git a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj index 808dca423ea9e..4903d07eb35c8 100644 --- a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj +++ b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj @@ -29,6 +29,17 @@ + + + + + + + +