Installation
This guide will help you install NetMediate and its companion packages in your .NET application.
Prerequisites
- .NET 10.0, .NET Standard 2.0, or .NET Standard 2.1 compatible runtime
- Visual Studio 2022+, Visual Studio Code, or JetBrains Rider
- .NET CLI or NuGet Package Manager
Core Package Installation
Using .NET CLI (Recommended)
dotnet add package NetMediate.Core
dotnet add package NetMediate.SourceGeneration
Use NetMediate.Core in shared/contracts projects and NetMediate.SourceGeneration in the startup/application project. The generator package injects NetMediate and GenDI.SourceGenerator automatically via buildTransitive.
After running the command, your .csproj will have PackageReference entries for NetMediate.Core and NetMediate.SourceGeneration. For library projects, optionally add PrivateAssets="all" to the generator package to avoid transitive flow:
<ItemGroup>
<PackageReference Include="NetMediate.Core" Version="*" />
<PackageReference Include="NetMediate.SourceGeneration" Version="x.x.x.x">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>contentfiles; compile; runtime</PrivateAssets>
</PackageReference>
</ItemGroup>
Using Package Manager Console
Install-Package NetMediate.Core
Install-Package NetMediate.SourceGeneration
After running the command, your .csproj will have PackageReference entries for NetMediate.Core and NetMediate.SourceGeneration. See the note on PrivateAssets in the .NET CLI section above if you are building a library.
Using PackageReference
Add the following to your .csproj file:
<ItemGroup>
<PackageReference Include="NetMediate.Core" Version="*" />
<PackageReference Include="NetMediate.SourceGeneration" Version="x.x.x.x">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>contentfiles; compile; runtime</PrivateAssets>
</PackageReference>
</ItemGroup>
NetMediate.SourceGeneration should use the explicit analyzer-style metadata below:
<PackageReference Include="NetMediate.SourceGeneration" Version="x.x.x.x">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>contentfiles; compile; runtime</PrivateAssets>
</PackageReference>
NetMediate.SourceGeneration still adds NetMediate and GenDI.SourceGenerator for the direct project.
Source Generation
NetMediate.SourceGeneration is the package you install directly in the startup/application project. Its buildTransitive file adds the required NetMediate runtime and GenDI.SourceGenerator automatically.
Optional Packages
Moq Testing Utilities
Provides testing helpers for unit tests:
dotnet add package NetMediate.Moq
Version Compatibility
| Package | Minimum .NET Version | Supported TFMs |
|---|---|---|
| NetMediate.Core | .NET Standard 2.0 | netstandard2.0 |
| NetMediate | .NET Standard 2.0 | net10.0, netstandard2.0, netstandard2.1 |
| NetMediate.SourceGeneration | .NET Standard 2.0 | netstandard2.0 (analyzer) |
| NetMediate.Moq | .NET Standard 2.0 | net10.0, netstandard2.0, netstandard2.1 |
Verifying Installation
After installation, verify that NetMediate is available in your project:
using NetMediate;
using Microsoft.Extensions.DependencyInjection;
var services = new ServiceCollection();
services.AddNetMediate(); // Generated by the NetMediate.SourceGeneration package
If AddNetMediate() is not recognized, make sure:
- Your startup project references
NetMediate.SourceGeneration - You've rebuilt your project
- Your IDE has refreshed its IntelliSense cache
Next Steps
Now that you have NetMediate installed, proceed to:
- Quick Start Guide - Get up and running in 5 minutes
- Message Types - Learn about the different message types
- Handlers - Create your first handlers