MSTest.Extensions.Hosting 4.5.1-alpha.26507.8

Prefix Reserved
This is a prerelease version of MSTest.Extensions.Hosting.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MSTest.Extensions.Hosting" Version="4.5.1-alpha.26507.8" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MSTest.Extensions.Hosting" Version="4.5.1-alpha.26507.8" />
                    
Directory.Packages.props
<PackageReference Include="MSTest.Extensions.Hosting" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MSTest.Extensions.Hosting --version 4.5.1-alpha.26507.8
                    
#r "nuget: MSTest.Extensions.Hosting, 4.5.1-alpha.26507.8"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MSTest.Extensions.Hosting@4.5.1-alpha.26507.8
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MSTest.Extensions.Hosting&version=4.5.1-alpha.26507.8&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MSTest.Extensions.Hosting&version=4.5.1-alpha.26507.8&prerelease
                    
Install as a Cake Tool

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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