Microsoft.Extensions.Primitives
                              
                            
                                10.0.0-preview.5.25266.103
                            
                        
                            
                                
                                
                                    Prefix Reserved
                                
                            
                    
    
        
            .NET 8.0
        
        
            
                
                
                    This package targets .NET 8.0. The package is compatible with this framework or higher.
                
            
        
    
            
        
            .NET Standard 2.0
        
        
            
                
                
                    This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
                
            
        
    
        
        
            .NET Framework 4.6.2
        
        
            
                
                
                    This package targets .NET Framework 4.6.2. The package is compatible with this framework or higher.
                
            
        
    
    
        
        
                                This is a prerelease version of Microsoft.Extensions.Primitives.
                            
    
    
        
        
                                There is a newer prerelease version of this package available.
                                
See the version list below for details.
                    See the version list below for details.
dotnet add package Microsoft.Extensions.Primitives --version 10.0.0-preview.5.25266.103
NuGet\Install-Package Microsoft.Extensions.Primitives -Version 10.0.0-preview.5.25266.103
        
        
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="Microsoft.Extensions.Primitives" Version="10.0.0-preview.5.25266.103" />
        
        
For projects that support PackageReference, copy this XML node into the project file to reference the package.
                    
    
    <PackageVersion Include="Microsoft.Extensions.Primitives" Version="10.0.0-preview.5.25266.103" />
<PackageReference Include="Microsoft.Extensions.Primitives" />
        
        
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 Microsoft.Extensions.Primitives --version 10.0.0-preview.5.25266.103
        
        
 The NuGet Team does not provide support for this client. Please contact its maintainers for support.
                    
    
    #r "nuget: Microsoft.Extensions.Primitives, 10.0.0-preview.5.25266.103"
        
        
#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 Microsoft.Extensions.Primitives@10.0.0-preview.5.25266.103
        
        
#: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=Microsoft.Extensions.Primitives&version=10.0.0-preview.5.25266.103&prerelease
#tool nuget:?package=Microsoft.Extensions.Primitives&version=10.0.0-preview.5.25266.103&prerelease
        
        
 The NuGet Team does not provide support for this client. Please contact its maintainers for support.
                    
    
    About
Microsoft.Extensions.Primitives contains isolated types that are used in many places within console or ASP.NET Core applications using framework extensions.
Key Features
- IChangeToken: An interface that represents a token that can notify when a change occurs. This can be used to trigger actions or invalidate caches when something changes. For example, the configuration and file providers libraries use this interface to reload settings or files when they are modified.
- StringValues: A struct that represents a single string or an array of strings. This can be used to efficiently store and manipulate multiple values that are logically a single value. For example, the HTTP headers and query strings libraries use this struct to handle multiple values for the same key.
- StringSegment: A struct that represents a substring of another string. This can be used to avoid allocating new strings when performing operations on parts of a string. For example, the configuration and logging libraries use this struct to parse and format strings.
How to Use
IChangeToken with configuration example
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Primitives;
using System;
class Program
{
    static void Main(string[] args)
    {
        // Create a configuration builder
        var configurationBuilder = new ConfigurationBuilder()
            .SetBasePath(Environment.CurrentDirectory)
            // appsettings.json expected to have the following contents:
            // {
            //   "SomeKey": "SomeValue"
            // }
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
        // Build the configuration
        IConfiguration configuration = configurationBuilder.Build();
        // Create a change token for the configuration
        IChangeToken changeToken = configuration.GetReloadToken();
        // Attach a change callback
        IDisposable changeTokenRegistration = changeToken.RegisterChangeCallback(state =>
        {
            Console.WriteLine("Configuration changed!");
            IConfigurationRoot root = (IConfigurationRoot)state;
            var someValue = root["SomeKey"]; // Access the updated configuration value
            Console.WriteLine($"New value of SomeKey: {someValue}");
        }, configuration);
        // go and update the value of the key SomeKey in appsettings.json.
        // The change callback will be invoked when the file is saved.
        Console.WriteLine("Listening for configuration changes. Press any key to exit.");
        Console.ReadKey();
        // Clean up the change token registration when no longer needed
        changeTokenRegistration.Dispose();
    }
}
StringValues example
using System;
using Microsoft.Extensions.Primitives;
namespace StringValuesSample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a StringValues object from a single string or an array of strings
            StringValues single = "Hello";
            StringValues multiple = new string[] { "Hello", "World" };
            // Use the implicit conversion to string or the ToString method to get the values
            Console.WriteLine($"Single: {single}"); // Single: Hello
            Console.WriteLine($"Multiple: {multiple}"); // Multiple: Hello,World
            // Use the indexer, the Count property, and the IsNullOrEmpty method to access the values
            Console.WriteLine($"Multiple[1]: {multiple[1]}"); // Multiple[1]: World
            Console.WriteLine($"Single.Count: {single.Count}"); // Single.Count: 1
            Console.WriteLine($"Multiple.IsNullOrEmpty: {StringValues.IsNullOrEmpty(multiple)}"); // Multiple.IsNullOrEmpty: False
            // Use the Equals method or the == operator to compare two StringValues objects
            Console.WriteLine($"single == \"Hello\": {single == "Hello"}"); // single == "Hello": True
            Console.WriteLine($"multiple == \"Hello\": {multiple == "Hello"}"); // multiple == "Hello": False
       }
    }
}
Main Types
The main types provided by this library are:
- IChangeToken
- StringValues
- StringSegment
Additional Documentation
Related Packages
Feedback & Contributing
Microsoft.Extensions.Primitives is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. | 
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 is compatible. 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 Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. | 
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. | 
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. | 
| MonoAndroid | monoandroid was computed. | 
| MonoMac | monomac was computed. | 
| MonoTouch | monotouch was computed. | 
| Tizen | tizen40 was computed. tizen60 was computed. | 
| Xamarin.iOS | xamarinios was computed. | 
| Xamarin.Mac | xamarinmac was computed. | 
| Xamarin.TVOS | xamarintvos was computed. | 
| Xamarin.WatchOS | xamarinwatchos was computed. | 
        
        Compatible target framework(s)
    
    
        
        Included target framework(s) (in package)
    
    Learn more about Target Frameworks and .NET Standard.
- 
                                                    .NETFramework 4.6.2- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
 
- 
                                                    .NETStandard 2.0- System.Memory (>= 4.6.3)
- System.Runtime.CompilerServices.Unsafe (>= 6.1.2)
 
- 
                                                    net10.0- No dependencies.
 
- 
                                                    net8.0- No dependencies.
 
- 
                                                    net9.0- No dependencies.
 
GitHub repositories (188)
Showing the top 20 popular GitHub repositories that depend on Microsoft.Extensions.Primitives:
| Repository | Stars | 
|---|---|
| dotnet/roslyn 
                                                            The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
                                                         | |
| dotnet/AspNetCore.Docs 
                                                            Documentation for ASP.NET Core
                                                         | |
| chocolatey/choco 
                                                            Chocolatey - the package manager for Windows
                                                         | |
| JeffreySu/WeiXinMPSDK 
                                                            微信全平台 .NET SDK, Senparc.Weixin for C#,支持 .NET Framework 及 .NET Core、.NET 8.0。已支持微信公众号、小程序、小游戏、微信支付、企业微信/企业号、开放平台、JSSDK、微信周边等全平台。 WeChat SDK for C#.
                                                         | |
| microsoft/ailab 
                                                            Experience, Learn and Code the latest breakthrough innovations with Microsoft AI
                                                         | |
| Azure/azure-sdk-for-net 
                                                            This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net. 
                                                         | |
| FastEndpoints/FastEndpoints 
                                                            A light-weight REST API development framework for ASP.NET 8 and newer.
                                                         | |
| aspnet/Mvc 
                                                            [Archived] ASP.NET Core MVC is a model view controller framework for building dynamic web sites with clean separation of concerns, including the merged MVC, Web API, and Web Pages w/ Razor. Project moved to https://github.com/aspnet/AspNetCore
                                                         | |
| ServiceStack/ServiceStack 
                                                            Thoughtfully architected, obscenely fast, thoroughly enjoyable web services for all
                                                         | |
| dotnet/aspire 
                                                            Aspire is the tool for code-first, extensible, observable dev and deploy.
                                                         | |
| openiddict/openiddict-core 
                                                            Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
                                                         | |
| Azure/azure-powershell 
                                                            Microsoft Azure PowerShell
                                                         | |
| hardkoded/puppeteer-sharp 
                                                            Headless Chrome .NET API
                                                         | |
| dotnet/aspnet-api-versioning 
                                                            Provides a set of libraries which add service API versioning to ASP.NET Web API, OData with ASP.NET Web API, and ASP.NET Core.
                                                         | |
| projectkudu/kudu 
                                                            Kudu is the engine behind git/hg deployments, WebJobs, and various other features in Azure Web Sites. It can also run outside of Azure.
                                                         | |
| 1357310795/MyComputerManager 
                                                            管理“此电脑”里删不掉的流氓“快捷方式”(包括侧边栏),同时可自己添加这类“快捷方式”
                                                         | |
| microsoft/playwright-dotnet 
                                                            .NET version of the Playwright testing and automation library.
                                                         | |
| zzzprojects/EntityFramework-Plus 
                                                            Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
                                                         | |
| zsh2401/AutumnBox 
                                                            图形化ADB工具箱
                                                         | |
| microsoft/WhatTheHack 
                                                            A collection of challenge based hack-a-thons including student guide, coach guide, lecture presentations, sample/instructional code and templates.  Please visit the What The Hack website at: https://aka.ms/wth
                                                         | 
| Version | Downloads | Last Updated | 
|---|---|---|
| 10.0.0-rc.2.25466.103 | 0 | 9/22/2025 | 
| 10.0.0-rc.1.25451.107 | 0 | 9/22/2025 | 
| 10.0.0-rc.1.25421.113 | 0 | 8/28/2025 | 
| 10.0.0-preview.7.25380.108 | 0 | 8/11/2025 | 
| 10.0.0-preview.7.25380.105 | 0 | 8/6/2025 | 
| 10.0.0-preview.6.25358.103 | 0 | 7/17/2025 | 
| 10.0.0-preview.6.25321.102 | 0 | 6/25/2025 | 
| 10.0.0-preview.5.25280.105 | 0 | 6/2/2025 | 
| 10.0.0-preview.5.25277.114 | 0 | 6/3/2025 | 
| 10.0.0-preview.5.25277.101 | 0 | 5/29/2025 | 
| 10.0.0-preview.5.25266.103 | 0 | 5/20/2025 | 
| 10.0.0-preview.4.25255.103 | 0 | 5/12/2025 | 
| 9.0.10 | 2 | 9/23/2025 | 
| 9.0.7 | 28 | 7/11/2025 | 
| 3.0.0-preview.19074.2 | 8 | 1/28/2019 | 
| 3.0.0-preview.18572.1 | 1 | 11/30/2018 |