MSTest.Extensions.Hosting
4.5.1-alpha.26507.8
Prefix Reserved
dotnet add package MSTest.Extensions.Hosting --version 4.5.1-alpha.26507.8
NuGet\Install-Package MSTest.Extensions.Hosting -Version 4.5.1-alpha.26507.8
<PackageReference Include="MSTest.Extensions.Hosting" Version="4.5.1-alpha.26507.8" />
<PackageVersion Include="MSTest.Extensions.Hosting" Version="4.5.1-alpha.26507.8" />
<PackageReference Include="MSTest.Extensions.Hosting" />
paket add MSTest.Extensions.Hosting --version 4.5.1-alpha.26507.8
#r "nuget: MSTest.Extensions.Hosting, 4.5.1-alpha.26507.8"
#:package MSTest.Extensions.Hosting@4.5.1-alpha.26507.8
#addin nuget:?package=MSTest.Extensions.Hosting&version=4.5.1-alpha.26507.8&prerelease
#tool nuget:?package=MSTest.Extensions.Hosting&version=4.5.1-alpha.26507.8&prerelease
MSTest.Extensions.Hosting
MSTest.Extensions.Hosting lets an application-owned Microsoft.Extensions.Hosting container create MSTest test classes.
This package remains prerelease, including in MSTest RTM builds, while its Microsoft.Testing.Extensions.Hosting dependency is alpha.
Register the integration while building the same host that runs Microsoft Testing Platform:
HostApplicationBuilder builder = Host.CreateApplicationBuilder();
builder.Services.AddSingleton<MyApplicationService>();
builder.Services.AddMSTestTestClassInjection();
Test classes can then request registered services in a public constructor:
[TestClass]
public sealed class MyTests(MyApplicationService service, TestContext testContext)
{
[TestMethod]
public void UsesApplicationService()
=> Assert.IsNotNull(service);
}
The integration is explicit and affects only MSTest test-class construction. It creates one IServiceScope for every test invocation, including each data row and retry attempt. TestInitialize, the test method, and TestCleanup share the same test-class instance and scope. Static ClassInitialize and ClassCleanup run outside invocation scopes.
The application host remains caller-owned. MSTest never disposes the host or its root service provider. After TestCleanup, the integration disposes the test-class instance and then its invocation scope.
NativeAOT, browser WebAssembly, AOT compilation, and MSTest source generation are not supported by this first reflection-based integration. Calling AddMSTestTestClassInjection in one of those modes produces a deterministic build error, including when host registration is compiled into a referenced project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Framework | net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Testing.Extensions.Hosting (>= 1.0.0-alpha.26507.8)
- MSTest.Analyzers (>= 4.5.1)
- MSTest.TestAdapter (>= 4.5.1)
- MSTest.TestFramework (>= 4.5.1)
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Testing.Extensions.Hosting (>= 1.0.0-alpha.26507.8)
- MSTest.Analyzers (>= 4.5.1)
- MSTest.TestAdapter (>= 4.5.1)
- MSTest.TestFramework (>= 4.5.1)
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Testing.Extensions.Hosting (>= 1.0.0-alpha.26507.8)
- MSTest.Analyzers (>= 4.5.1)
- MSTest.TestAdapter (>= 4.5.1)
- MSTest.TestFramework (>= 4.5.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.5.1-alpha.26507.8 | 36 | 10/7/2026 |
See the release notes at https://github.com/microsoft/testfx/blob/main/docs/Changelog.md#4.5.1.