Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use MSBuildLocator for tests #57613

Merged
merged 16 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<FakeSignVersion>0.9.2</FakeSignVersion>
<HumanizerCoreVersion>2.2.0</HumanizerCoreVersion>
<ICSharpCodeDecompilerVersion>6.1.0.5902</ICSharpCodeDecompilerVersion>
<MicrosoftBuildLocatorVersion>1.2.6</MicrosoftBuildLocatorVersion>
<MicrosoftBuildLocatorVersion>1.4.1</MicrosoftBuildLocatorVersion>
<!--
SourceBuild will requires that all dependencies also be source buildable. We are referencing a
version of MSBuild that is not SourceBuild compatible, which makes our build incompatible. Since we only
Expand Down Expand Up @@ -202,6 +202,17 @@
<RoslynBuildUtilVersion>0.9.8-beta</RoslynBuildUtilVersion>
<RoslynDependenciesOptimizationDataVersion>3.0.0-beta2-19053-01</RoslynDependenciesOptimizationDataVersion>
<RoslynDiagnosticsAnalyzersVersion>$(RoslynDiagnosticsNugetPackageVersion)</RoslynDiagnosticsAnalyzersVersion>
<!--
The package "Microsoft.CodeAnalysis.Analyzer.Testing" brings in an earlier version of these NuGet dependencies than
is expected by the NET SDK used in the Workspace.MSBuild UnitTests. In order to test against the same verion of NuGet
as our configured SDK, we must set the version to be the same.
-->
<NuGetCommonVersion>6.0.0-rc.258</NuGetCommonVersion>
<NuGetConfigurationVersion>$(NuGetCommonVersion)</NuGetConfigurationVersion>
<NuGetFrameworksVersion>$(NuGetCommonVersion)</NuGetFrameworksVersion>
<NuGetPackagingVersion>$(NuGetCommonVersion)</NuGetPackagingVersion>
<NuGetProtocolVersion>$(NuGetCommonVersion)</NuGetProtocolVersion>
<NuGetVersioningVersion>$(NuGetCommonVersion)</NuGetVersioningVersion>
<RoslynToolsVSIXExpInstallerVersion>1.1.0-beta3.21418.3</RoslynToolsVSIXExpInstallerVersion>
<RoslynMicrosoftVisualStudioExtensionManagerVersion>0.0.4</RoslynMicrosoftVisualStudioExtensionManagerVersion>
<SourceBrowserVersion>1.0.21</SourceBrowserVersion>
Expand Down
42 changes: 0 additions & 42 deletions src/Workspaces/MSBuildTest/Interop.cs

This file was deleted.

20 changes: 19 additions & 1 deletion src/Workspaces/MSBuildTest/MSBuildWorkspaceTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,26 @@ protected async Task<Solution> SolutionAsync(params IBuilder[] inputs)
}

protected static MSBuildWorkspace CreateMSBuildWorkspace(params (string key, string value)[] additionalProperties)
=> CreateMSBuildWorkspace(throwOnWorkspaceFailed: true, skipUnrecognizedProjects: false, additionalProperties: additionalProperties);

protected static MSBuildWorkspace CreateMSBuildWorkspace(
bool throwOnWorkspaceFailed = true,
bool skipUnrecognizedProjects = false,
(string key, string value)[] additionalProperties = null)
{
return MSBuildWorkspace.Create(CreateProperties(additionalProperties));
additionalProperties ??= Array.Empty<(string key, string value)>();
var workspace = MSBuildWorkspace.Create(CreateProperties(additionalProperties));
if (throwOnWorkspaceFailed)
{
workspace.WorkspaceFailed += (s, e) => throw new Exception($"Workspace failure {e.Diagnostic.Kind}:{e.Diagnostic.Message}");
}

if (skipUnrecognizedProjects)
{
workspace.SkipUnrecognizedProjects = true;
}

return workspace;
}

protected static MSBuildWorkspace CreateMSBuildWorkspace(HostServices hostServices, params (string key, string value)[] additionalProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<PropertyGroup>
<OutputType>Library</OutputType>
<RootNamespace>Microsoft.CodeAnalysis.MSBuild.UnitTests</RootNamespace>
<TargetFramework>net472</TargetFramework>
<TargetFrameworks>net6.0-windows;net472</TargetFrameworks>
</PropertyGroup>
<ItemGroup Label="Project References">
<ProjectReference Include="..\..\Compilers\Core\Portable\Microsoft.CodeAnalysis.csproj" />
Expand All @@ -26,13 +26,23 @@
<ProjectReference Include="..\VisualBasic\Portable\Microsoft.CodeAnalysis.VisualBasic.Workspaces.vbproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="$(MicrosoftVisualStudioSetupConfigurationInteropVersion)" />
<PackageReference Include="Microsoft.Build" Version="$(RefOnlyMicrosoftBuildVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Framework" Version="$(RefOnlyMicrosoftBuildFrameworkVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />
<PackageReference Include="Microsoft.Build.Locator" Version="$(MicrosoftBuildLocatorVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(RefOnlyMicrosoftBuildTasksCoreVersion)" ExcludeAssets="Runtime" PrivateAssets="All" />

<!--
The package "Microsoft.CodeAnalysis.Analyzer.Testing" brings in a lower version of these NuGet dependencies than is expected by the
NET SDK. In order to test against the same verion of NuGet as our configured SDK, we must set the version to be the same.
-->
<PackageReference Include="NuGet.Common" Version="$(NuGetCommonVersion)" />
<PackageReference Include="NuGet.Configuration" Version="$(NuGetConfigurationVersion)" />
<PackageReference Include="NuGet.Frameworks" Version="$(NuGetFrameworksVersion)" />
<PackageReference Include="NuGet.Packaging" Version="$(NuGetPackagingVersion)" />
<PackageReference Include="NuGet.Protocol" Version="$(NuGetProtocolVersion)" />
<PackageReference Include="NuGet.Versioning" Version="$(NuGetVersioningVersion)" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Xaml">
<Reference Include="System.Xaml" Condition="$(TargetFramework) == 'net472'">
<Private>false</Private>
</Reference>
</ItemGroup>
Expand All @@ -59,4 +69,10 @@
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<Target Name="_DoNotCopyMicrosoftBuildFramework" AfterTargets="ResolvePackageAssets">
<ItemGroup Condition="$(TargetFramework) == 'net472'">
<RuntimeCopyLocalItems Remove="@(RuntimeCopyLocalItems)" Condition="'%(RuntimeCopyLocalItems.NuGetPackageId)' == 'Microsoft.Build.Framework'" />
</ItemGroup>
</Target>
</Project>
Loading