Skip to content

Commit 7e6f891

Browse files
Support "Central Package Management" with the MSTest.Sdk (#2581) (#2583)
1 parent 27547cd commit 7e6f891

File tree

6 files changed

+150
-36
lines changed

6 files changed

+150
-36
lines changed

src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@
2828

2929
<!-- Core -->
3030
<ItemGroup>
31-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
32-
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
33-
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
34-
<PackageReference Include="MSTest.Analyzers" Version="$(MSTestVersion)" Condition=" '$(EnableMSTestAnalyzers)' != 'false' " />
31+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" VersionOverride="$(MicrosoftNETTestSdkVersion)" />
32+
<PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" VersionOverride="$(MSTestVersion)" />
33+
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" VersionOverride="$(MSTestVersion)" />
34+
<PackageReference Include="MSTest.Analyzers" Version="$(MSTestVersion)" VersionOverride="$(MSTestVersion)" Condition=" '$(EnableMSTestAnalyzers)' != 'false' " />
3535
</ItemGroup>
3636

3737
<!-- Extensions -->
3838
<ItemGroup>
39-
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingExtensionsTrxReportVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsTrxReport)' == 'true' " />
40-
<PackageReference Include="Microsoft.Testing.Extensions.CrashDump" Version="$(MicrosoftTestingExtensionsCrashDumpVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCrashDump)' == 'true' " />
41-
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" Version="$(MicrosoftTestingExtensionsHangDumpVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsHangDump)' == 'true' " />
42-
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' " />
43-
<PackageReference Include="Microsoft.Testing.Extensions.HotReload" Version="$(MicrosoftTestingExtensionsHotReloadVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsHotReload)' == 'true' " />
44-
<PackageReference Include="Microsoft.Testing.Extensions.Retry" Version="$(MicrosoftTestingExtensionsRetryVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsRetry)' == 'true' " />
39+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingExtensionsTrxReportVersion)" VersionOverride="$(MicrosoftTestingExtensionsTrxReportVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsTrxReport)' == 'true' " />
40+
<PackageReference Include="Microsoft.Testing.Extensions.CrashDump" Version="$(MicrosoftTestingExtensionsCrashDumpVersion)" VersionOverride="$(MicrosoftTestingExtensionsCrashDumpVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCrashDump)' == 'true' " />
41+
<PackageReference Include="Microsoft.Testing.Extensions.HangDump" Version="$(MicrosoftTestingExtensionsHangDumpVersion)" VersionOverride="$(MicrosoftTestingExtensionsHangDumpVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsHangDump)' == 'true' " />
42+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" VersionOverride="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' " />
43+
<PackageReference Include="Microsoft.Testing.Extensions.HotReload" Version="$(MicrosoftTestingExtensionsHotReloadVersion)" VersionOverride="$(MicrosoftTestingExtensionsHotReloadVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsHotReload)' == 'true' " />
44+
<PackageReference Include="Microsoft.Testing.Extensions.Retry" Version="$(MicrosoftTestingExtensionsRetryVersion)" VersionOverride="$(MicrosoftTestingExtensionsRetryVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsRetry)' == 'true' " />
4545
</ItemGroup>
4646

4747
</Project>

src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets

+7-7
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
<Import Project="$(MSBuildThisFileDirectory)Common.targets"/>
55

66
<ItemGroup>
7-
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="$(MicrosoftTestingPlatformVersion)" />
8-
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
9-
<PackageReference Include="MSTest.Engine" Version="$(MSTestEngineVersion)" />
10-
<PackageReference Include="MSTest.SourceGeneration" Version="$(MSTestEngineVersion)" />
7+
<PackageReference Include="Microsoft.Testing.Platform.MSBuild" Version="$(MicrosoftTestingPlatformVersion)" VersionOverride="$(MicrosoftTestingPlatformVersion)" />
8+
<PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" VersionOverride="$(MSTestVersion)" />
9+
<PackageReference Include="MSTest.Engine" Version="$(MSTestEngineVersion)" VersionOverride="$(MSTestEngineVersion)" />
10+
<PackageReference Include="MSTest.SourceGeneration" Version="$(MSTestEngineVersion)" VersionOverride="$(MSTestEngineVersion)" />
1111
</ItemGroup>
1212

1313
<!-- Extensions -->
1414
<ItemGroup>
15-
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingExtensionsTrxReportVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsTrxReport)' == 'true' " />
16-
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' " />
15+
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="$(MicrosoftTestingExtensionsTrxReportVersion)" VersionOverride="$(MicrosoftTestingExtensionsTrxReportVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsTrxReport)' == 'true' " />
16+
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" VersionOverride="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' " />
1717
<!-- Support for -p:AotMsCodeCoverageInstrumentation="true" during dotnet publish for native aot -->
18-
<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' and $(PublishAot) == 'true' " />
18+
<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="$(MicrosoftTestingExtensionsCodeCoverageVersion)" VersionOverride="$(MicrosoftTestingExtensionsCodeCoverageVersion)" Condition=" '$(EnableMicrosoftTestingExtensionsCodeCoverage)' == 'true' and $(PublishAot) == 'true' " />
1919
</ItemGroup>
2020

2121
</Project>

src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33

44
<ItemGroup>
5-
<PackageReference Include="MSTest" Version="$(MSTestVersion)" />
5+
<PackageReference Include="MSTest" Version="$(MSTestVersion)" VersionOverride="$(MSTestVersion)" />
66
</ItemGroup>
77

88
</Project>

test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs

+98
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public async Task RunTests_With_VSTest(string multiTfm, BuildConfiguration build
3535
.PatchCodeWithReplace("$Extensions$", string.Empty),
3636
addPublicFeeds: true);
3737

38+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
39+
<Project>
40+
<PropertyGroup>
41+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
42+
</PropertyGroup>
43+
</Project>
44+
""");
45+
3846
var compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
3947
Assert.AreEqual(0, compilationResult.ExitCode);
4048

@@ -63,6 +71,14 @@ public async Task RunTests_With_MSTestRunner_DotnetTest(string multiTfm, BuildCo
6371
.PatchCodeWithReplace("$Extensions$", string.Empty),
6472
addPublicFeeds: true);
6573

74+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
75+
<Project>
76+
<PropertyGroup>
77+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
78+
</PropertyGroup>
79+
</Project>
80+
""");
81+
6682
var compilationResult = await DotnetCli.RunAsync($"test -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
6783
Assert.AreEqual(0, compilationResult.ExitCode);
6884

@@ -91,6 +107,47 @@ public async Task RunTests_With_MSTestRunner_Standalone(string multiTfm, BuildCo
91107
.PatchCodeWithReplace("$Extensions$", string.Empty),
92108
addPublicFeeds: true);
93109

110+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
111+
<Project>
112+
<PropertyGroup>
113+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
114+
</PropertyGroup>
115+
</Project>
116+
""");
117+
118+
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
119+
Assert.AreEqual(0, compilationResult.ExitCode);
120+
foreach (var tfm in multiTfm.Split(";"))
121+
{
122+
var testHost = TestHost.LocateFrom(generator.TargetAssetPath, AssetName, tfm, buildConfiguration: buildConfiguration);
123+
var testHostResult = await testHost.ExecuteAsync();
124+
testHostResult.AssertOutputContains("Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1");
125+
}
126+
}
127+
128+
[ArgumentsProvider(nameof(GetBuildMatrixMultiTfmFoldedBuildConfiguration))]
129+
public async Task RunTests_With_CentralPackageManagement_Standalone(string multiTfm, BuildConfiguration buildConfiguration)
130+
{
131+
using TestAsset generator = await TestAsset.GenerateAssetAsync(
132+
AssetName,
133+
SourceCode
134+
.PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)
135+
.PatchCodeWithReplace("$OutputType$", string.Empty)
136+
.PatchCodeWithReplace("$TargetFramework$", $"<TargetFrameworks>{multiTfm}</TargetFrameworks>")
137+
.PatchCodeWithReplace("$EnableMSTestRunner$", string.Empty)
138+
.PatchCodeWithReplace("$TestingPlatformDotnetTestSupport$", string.Empty)
139+
.PatchCodeWithReplace("$ExtraProperties$", string.Empty)
140+
.PatchCodeWithReplace("$Extensions$", string.Empty),
141+
addPublicFeeds: true);
142+
143+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
144+
<Project>
145+
<PropertyGroup>
146+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
147+
</PropertyGroup>
148+
</Project>
149+
""");
150+
94151
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
95152
Assert.AreEqual(0, compilationResult.ExitCode);
96153
foreach (var tfm in multiTfm.Split(";"))
@@ -160,6 +217,14 @@ public async Task RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Exte
160217
.PatchCodeWithReplace("$Extensions$", msbuildExtensionEnableFragment),
161218
addPublicFeeds: true);
162219

220+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
221+
<Project>
222+
<PropertyGroup>
223+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
224+
</PropertyGroup>
225+
</Project>
226+
""");
227+
163228
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
164229
Assert.AreEqual(0, compilationResult.ExitCode);
165230
foreach (var tfm in multiTfm.Split(";"))
@@ -188,6 +253,14 @@ public async Task RunTests_With_MSTestRunner_Standalone_EnableAll_Extensions(str
188253
.PatchCodeWithReplace("$Extensions$", "<TestingExtensionsProfile>AllMicrosoft</TestingExtensionsProfile>"),
189254
addPublicFeeds: true);
190255

256+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
257+
<Project>
258+
<PropertyGroup>
259+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
260+
</PropertyGroup>
261+
</Project>
262+
""");
263+
191264
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
192265
Assert.AreEqual(0, compilationResult.ExitCode);
193266
foreach (var tfm in multiTfm.Split(";"))
@@ -227,6 +300,14 @@ public async Task RunTests_With_MSTestRunner_Standalone_Enable_Default_Extension
227300
.PatchCodeWithReplace("$Extensions$", enableDefaultExtensions ? string.Empty : "<TestingExtensionsProfile>None</TestingExtensionsProfile>"),
228301
addPublicFeeds: true);
229302

303+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
304+
<Project>
305+
<PropertyGroup>
306+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
307+
</PropertyGroup>
308+
</Project>
309+
""");
310+
230311
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
231312
Assert.AreEqual(0, compilationResult.ExitCode);
232313
foreach (var tfm in multiTfm.Split(";"))
@@ -259,6 +340,14 @@ public async Task Invalid_TestingProfile_Name_Should_Fail(string multiTfm, Build
259340
.PatchCodeWithReplace("$Extensions$", "<TestingExtensionsProfile>WrongName</TestingExtensionsProfile>"),
260341
addPublicFeeds: true);
261342

343+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
344+
<Project>
345+
<PropertyGroup>
346+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
347+
</PropertyGroup>
348+
</Project>
349+
""");
350+
262351
var compilationResult = await DotnetCli.RunAsync($"build -c {buildConfiguration} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path, failIfReturnValueIsNotZero: false);
263352
Assert.AreEqual(1, compilationResult.ExitCode);
264353
compilationResult.AssertOutputContains("Invalid value for property TestingExtensionsProfile. Valid values are 'Default', 'AllMicrosoft' and 'None'.");
@@ -291,6 +380,14 @@ await RetryHelper.RetryAsync(
291380
.PatchCodeWithReplace("$Extensions$", string.Empty),
292381
addPublicFeeds: true);
293382

383+
File.WriteAllText(Path.Combine(generator.TargetAssetPath, "Directory.Packages.props"), """
384+
<Project>
385+
<PropertyGroup>
386+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
387+
</PropertyGroup>
388+
</Project>
389+
""");
390+
294391
var compilationResult = await DotnetCli.RunAsync($"publish -r {RID} {generator.TargetAssetPath}", _acceptanceFixture.NuGetGlobalPackagesFolder.Path);
295392
compilationResult.AssertOutputNotContains("warning");
296393
compilationResult.AssertOutputContains("Generating native code");
@@ -311,6 +408,7 @@ await RetryHelper.RetryAsync(
311408
$TestingPlatformDotnetTestSupport$
312409
$ExtraProperties$
313410
<PlatformTarget>x64</PlatformTarget>
411+
<NoWarn>$(NoWarn);NU1507</NoWarn>
314412
</PropertyGroup>
315413
316414
<!-- Extensions -->

test/IntegrationTests/MSTest.Acceptance.IntegrationTests/testsbaseline.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.Messages.V
7171
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.Invalid_TestingProfile_Name_Should_Fail(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Debug)
7272
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.Invalid_TestingProfile_Name_Should_Fail(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Release)
7373
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.NativeAot_Smoke_Test_On_Windows()
74+
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_CentralPackageManagement_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Debug)
75+
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_CentralPackageManagement_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Release)
7476
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_MSTestRunner_DotnetTest(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Debug)
7577
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_MSTestRunner_DotnetTest(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Release)
7678
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_MSTestRunner_Standalone(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Debug)
@@ -93,4 +95,4 @@ MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.R
9395
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_MSTestRunner_Standalone_Selectively_Enabled_Extensions(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration, string, string, string) (multitfm,Release,TrxReport)
9496
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_VSTest(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Debug)
9597
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.SdkTests.RunTests_With_VSTest(string, Microsoft.Testing.TestInfrastructure.BuildConfiguration) (multitfm,Release)
96-
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.ValueTaskTests.CanUseValueTaskForAllKnownLocations()
98+
MSTest.Acceptance.IntegrationTests.MSTest.Acceptance.IntegrationTests.ValueTaskTests.CanUseValueTaskForAllKnownLocations()

0 commit comments

Comments
 (0)