Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI" Version="10.4.1" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.4.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.AI" Version="10.6.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.8" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.21.0" />
<PackageReference Include="Azure.AI.OpenAI" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.5.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="10.6.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="10.0.8" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.ResourceMonitoring" Version="10.6.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Spectre.Console" Version="0.55.2" />
<PackageReference Include="Spectre.Console" Version="0.56.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.7" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.8" />
</ItemGroup>

</Project>
76 changes: 64 additions & 12 deletions docs/core/testing/unit-testing-mstest-writing-tests-assertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ title: MSTest assertions
description: Learn about MSTest assertions including Assert, StringAssert, and CollectionAssert classes for validating test results.
author: Evangelink
ms.author: amauryleve
ms.date: 07/15/2025
ms.date: 06/04/2026
ai-usage: ai-assisted
---

# MSTest assertions
Expand All @@ -20,8 +21,8 @@ MSTest provides three assertion classes:
| `StringAssert` | String-specific assertions for patterns, substrings, and comparisons. |
| `CollectionAssert` | Collection assertions for comparing and validating collections. |

> [!TIP]
> When functionality exists in both `Assert` and `StringAssert`/`CollectionAssert`, prefer the `Assert` class. The `Assert` class provides better discoverability and is the recommended choice for new code. `StringAssert` and `CollectionAssert` are maintained for backward compatibility.
> [!IMPORTANT]
> For new code, always use the `Assert` class. The `StringAssert` and `CollectionAssert` classes are likely to be deprecated in a future release. They're maintained primarily for backward compatibility, but they're not recommended because splitting assertions across three types hurts discoverability.

All assertion methods accept an optional message parameter that displays when the assertion fails, helping you identify the cause:

Expand Down Expand Up @@ -107,8 +108,8 @@ public async Task AssertExamples()

Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert> class to compare and examine strings.

> [!NOTE]
> All `StringAssert` methods have equivalents in the `Assert` class. Prefer the `Assert` methods for better discoverability. The `StringAssert` class is maintained for backward compatibility.
> [!WARNING]
> The `StringAssert` class is likely to be deprecated in a future release. It's maintained for backward compatibility only and isn't recommended for new code. All `StringAssert` methods have equivalents on the `Assert` class, which offers better discoverability. To migrate existing usages, see analyzer [MSTEST0046](mstest-analyzers/mstest0046.md).

Available APIs are:

Expand All @@ -122,8 +123,8 @@ Available APIs are:

Use the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert> class to compare collections of objects, or to verify the state of a collection.

> [!NOTE]
> When an equivalent method exists in the `Assert` class (such as `Assert.Contains`, `Assert.DoesNotContain`), prefer using `Assert` for better discoverability. The `CollectionAssert` class is maintained primarily for backward compatibility.
> [!WARNING]
> The `CollectionAssert` class is likely to be deprecated in a future release. It's maintained primarily for backward compatibility and isn't recommended for new code. When an equivalent method exists on `Assert` (such as `Assert.Contains`, `Assert.DoesNotContain`, or `Assert.HasCount`), use `Assert` for better discoverability.

Available APIs are:

Expand All @@ -139,17 +140,68 @@ Available APIs are:
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.IsNotSubsetOf*?displayProperty=nameWithType>
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.IsSubsetOf*?displayProperty=nameWithType>

## Create custom assertions with `Assert.That`

The built-in assertion methods don't cover every scenario. To extend the assertion infrastructure with your own checks, MSTest exposes the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.Assert.That?displayProperty=nameWithType> singleton property as an extensibility hook. You add custom assertions as C# extension methods on the `Assert` instance type, and callers invoke them with the familiar `Assert.That.MyAssertion(...)` syntax.

For better discoverability, organize project-wide assertions in a dedicated static class. Custom assertions reached through `Assert.That` show up alongside the built-in methods in IntelliSense, so consumers don't have to remember a separate helper type.

### Author a custom assertion

Add an extension method that targets the `Assert` type and throws <xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException> when the condition fails:

```csharp
using System;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

public static class CustomAssertExtensions
{
public static void IsPrime(this Assert assert, int value)
{
if (value < 2 || Enumerable.Range(2, (int)Math.Sqrt(value) - 1).Any(i => value % i == 0))
{
throw new AssertFailedException($"Assert.That.IsPrime failed. Value <{value}> is not a prime number.");
}
}
}
```

### Use a custom assertion

After you import the namespace that contains your extension methods, call your custom assertion through `Assert.That`:

```csharp
[TestMethod]
public void Compute_ReturnsPrime()
{
int result = _calculator.NextPrime(10);
Assert.That.IsPrime(result);
}
```

### Extension hooks on `StringAssert` and `CollectionAssert`

The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert.That?displayProperty=nameWithType> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert.That?displayProperty=nameWithType> properties expose the same singleton pattern for backward compatibility. For new custom assertions, always target `Assert.That`. Otherwise, your helpers inherit the same discoverability problems as the legacy classes, and they'll need migration if `StringAssert` and `CollectionAssert` are deprecated.

### `Assert.That` property versus `Assert.That(...)` method

> [!NOTE]
> Don't confuse the `Assert.That` singleton *property*—used as an extensibility hook—with the `Assert.That(() => condition)` *method* added in MSTest 3.8. The latter accepts a Boolean expression and produces detailed failure messages by analyzing the expression tree (for example, `Assert.That(() => order.Total > 0)`). The two APIs share a name but serve different purposes.

## Best practices

1. **Use specific assertions**: Prefer `AreEqual` over `IsTrue(a == b)` for better failure messages.
- **Use specific assertions**: Prefer `AreEqual` over `IsTrue(a == b)` for better failure messages.

- **Include descriptive messages**: Help identify failures quickly with clear assertion messages.

1. **Include descriptive messages**: Help identify failures quickly with clear assertion messages.
- **Test one thing at a time**: Each test method should verify a single behavior.

1. **Test one thing at a time**: Each test method should verify a single behavior.
- **Use `Throws`/`ThrowsExactly` for exceptions**: In MSTest v3.8+, prefer `Assert.Throws`, `Assert.ThrowsExactly`, and their async counterparts (`ThrowsAsync`, `ThrowsExactlyAsync`) over the `ExpectedException` attribute.

1. **Use `Throws`/`ThrowsExactly` for exceptions**: In MSTest v3.8+, prefer `Assert.Throws`, `Assert.ThrowsExactly`, and their async counterparts (`ThrowsAsync`, `ThrowsExactlyAsync`) over the `ExpectedException` attribute.
- **Prefer `Assert` over `StringAssert`/`CollectionAssert`**: For better discoverability and consistency, use the `Assert` class. The `StringAssert` and `CollectionAssert` classes are likely to be deprecated in a future release.

1. **Prefer `Assert` over `StringAssert`/`CollectionAssert`**: When functionality exists in both classes, use the `Assert` class for better discoverability and consistency.
- **Extend `Assert.That` for custom assertions**: For consistent discoverability, add custom assertions as extension methods on `Assert` and invoke them through `Assert.That`. Don't target `StringAssert.That` or `CollectionAssert.That` in new code.

## Related analyzers

Expand Down
53 changes: 19 additions & 34 deletions docs/core/tools/enable-tab-autocomplete.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ dotnet completions script fish | source

#### Nushell

Add the following to the beginning of your `config.nu` file:
Add the following line(s) to your `config.nu` file:

```nu
dotnet completions script nushell | save -f ~/.local/share/nushell/completions/dotnet.nu
use ~/.local/share/nushell/completions/dotnet.nu *
mkdir ($nu.data-dir | path join "vendor/autoload") # Only add this line if not already present in your config.
dotnet completions script nushell | save -f ($nu.data-dir | path join "vendor/autoload/dotnet-completions.nu")
```

## Dynamic completion scripts (all versions)
Expand All @@ -115,7 +115,9 @@ pack

If that command doesn't work, make sure that .NET Core 2.0 SDK or later is installed. If it's installed but that command still doesn't work, make sure that the `dotnet` command resolves to a version of .NET Core 2.0 SDK or later. Use the `dotnet --version` command to see what version of `dotnet` your current path is resolving to. For more information, see [Select the .NET version to use](../versions/selection.md).

### PowerShell
### Configure shells to use native completions

#### PowerShell

To add tab completion to **PowerShell** for the .NET CLI, create or edit the profile stored in the variable `$PROFILE`. For more information, see [How to create your profile](/powershell/module/microsoft.powershell.core/about/about_profiles#how-to-create-a-profile) and [Profiles and execution policy](/powershell/module/microsoft.powershell.core/about/about_profiles#profiles-and-execution-policy).

Expand All @@ -131,9 +133,9 @@ Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
}
```

### bash
#### Bash

To add tab completion to your **bash** shell for the .NET CLI, add the following code to your `.bashrc` file:
Add the following code to your `.bashrc` file:

```bash
# bash parameter completion for the dotnet CLI
Expand All @@ -151,9 +153,9 @@ function _dotnet_bash_complete()
complete -f -F _dotnet_bash_complete dotnet
```

### zsh
#### Zsh

To add tab completion to your **zsh** shell for the .NET CLI, add the following code to your `.zshrc` file:
Add the following code to your `.zshrc` file:

```zsh
# zsh parameter completion for the dotnet CLI
Expand All @@ -176,43 +178,26 @@ _dotnet_zsh_complete()
compdef _dotnet_zsh_complete dotnet
```

### fish
#### Fish

To add tab completion to your **fish** shell for the .NET CLI, add the following code to your `config.fish` file:
Add the following code to your `config.fish` file:

```fish
complete -f -c dotnet -a "(dotnet complete (commandline -cp))"
```

### nushell
#### Nushell

To add tab completion to your **nushell** for .NET CLI, add the following to the beginning of your `config.nu` file:
Add the following code to your `config.nu` file:

```nu
let external_completer = { |spans|
{
dotnet: { ||
dotnet complete (
$spans | skip 1 | str join " "
) | lines
}
} | get $spans.0 | each { || do $in }
def "nu-complete dotnet" [context: string] {
^dotnet complete $"($context)" | lines
}
```

And then in the `config` record, find the `completions` section and add the `external_completer` that was defined earlier to `external`:

```nu
let-env config = {
# your options here
completions: {
# your options here
external: {
# your options here
completer: $external_completer # add it here
}
}
}
export extern "dotnet" [
...command: string@"nu-complete dotnet"
]
```

## Completion examples
Expand Down
1 change: 1 addition & 0 deletions docs/core/tools/sdk-errors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,4 @@ This list is a complete list of the errors that you might get from the .NET SDK
|[NETSDK1238](netsdk1238.md)|The current .NET SDK ({0}) has known vulnerabilities ({1}).{2} See <https://dotnet.microsoft.com/download>|
|[NETSDK1239](netsdk1239.md)|The current .NET SDK ({0}) is end of life as of {1}. It will receive no further security updates: <https://dotnet.microsoft.com/download>|
|[NETSDK1240](netsdk1240.md)|The current .NET SDK ({0}) has no newer release in its feature band. Update to version {1}: <https://dotnet.microsoft.com/download>|
|[NETSDK1242](netsdk1242.md)|Building {0} projects with the Mono runtime is not supported in .NET 11.0 and later. Use the CoreCLR runtime or target .NET 10.0.|
27 changes: 27 additions & 0 deletions docs/core/tools/sdk-errors/netsdk1242.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: "NETSDK1242: Building projects with the Mono runtime is not supported in .NET 11.0 and later"
description: Learn how to resolve build error NETSDK1242, which reports that the Mono runtime is not supported for the target mobile platform in .NET 11.0 and later.
ms.topic: error-reference
ms.date: 06/16/2026
ai-usage: ai-assisted
f1_keywords:
- NETSDK1242
---
# NETSDK1242: Building projects with the Mono runtime is not supported in .NET 11.0 and later

This error indicates that the project selects the Mono runtime (the `UseMonoRuntime` property is set to `true`) for a mobile target platform while targeting .NET 11.0 or later, where the Mono runtime is no longer supported for that platform. The full error message is similar to the following example:

> NETSDK1242: Building ios projects with the Mono runtime is not supported in .NET 11.0 and later. Use the CoreCLR runtime or target .NET 10.0.

The error applies to the `android`, `ios`, `maccatalyst`, and `tvos` target platforms.

## Resolve the error

Choose one of the following options:

- Build the project with the CoreCLR runtime. Remove the `UseMonoRuntime` property from the project, or set it to `false`.
- If the project requires the Mono runtime, target .NET 10. Change the target framework to a .NET 10 mobile target framework moniker, for example `net10.0-android` or `net10.0-ios`

## See also

- [.NET SDK error and warning reference](index.md)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ helpviewer_keywords:
- Finalizers
- Other local functions

Beginning with C# 8.0, local function parameters can shadow local variables and parameters from an enclosing scope.

However, local functions can't be declared inside an expression-bodied member.

> [!NOTE]
Expand Down
1 change: 1 addition & 0 deletions docs/csharp/whats-new/csharp-version-history.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ C# 8.0 is the first major C# release that specifically targets .NET Core. Some f
- Positional patterns
- [Using declarations](../language-reference/statements/using.md)
- [Static local functions](../programming-guide/classes-and-structs/local-functions.md)
- Lambda expressions, anonymous methods, and local functions can declare parameters that shadow local variables and parameters from an enclosing scope.
- [Disposable ref structs](../language-reference/builtin-types/ref-struct.md)
- [Nullable reference types](../language-reference/builtin-types/nullable-reference-types.md)
- [Asynchronous streams](../language-reference/statements/iteration-statements.md#await-foreach)
Expand Down
2 changes: 2 additions & 0 deletions docs/navigate/tools-diagnostics/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ items:
href: ../../core/tools/sdk-errors/netsdk1239.md
- name: NETSDK1240
href: ../../core/tools/sdk-errors/netsdk1240.md
- name: NETSDK1242
href: ../../core/tools/sdk-errors/netsdk1242.md
- name: BuildCheck rules
items:
- name: Index of rules
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.8" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="10.1.0" />
<PackageReference Include="Microsoft.Orleans.Sdk" Version="10.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.8" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.5" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.8" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.8" />
<PackageReference Include="Microsoft.Orleans.Server" Version="10.1.0" />
<PackageReference Include="Microsoft.Orleans.Transactions.AzureStorage" Version="10.1.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5" />
</ItemGroup>
Expand Down
Loading