Skip to content

Overview of the Nx Plugin for .NET

.NET is a free, cross-platform, open-source developer platform for building many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, games, IoT, and more.

The Nx plugin for .NET registers .NET projects in your Nx workspace. It allows MSBuild tasks to be run through Nx. Nx effortlessly makes your CI faster.

Nx adds the following features to your workspace:

You can install Nx globally. Depending on your package manager, use one of the following commands:

npm add --global nx@latest

In any .NET workspace, run the following command to add Nx and the @nx/dotnet plugin:

nx init

Then, you can run .NET tasks using Nx. For example:

nx build <your dotnet project>

If you already have an Nx workspace set up, you can add the @nx/dotnet plugin by running the following command:

nx add @nx/dotnet

The @nx/dotnet plugin uses MSBuild to analyze your .NET solution and project structure. When using nx add, the plugin is automatically configured in your nx.json file.

The plugin automatically detects .NET projects by scanning for the following project file patterns:

  • **/*.csproj (C# projects)
  • **/*.fsproj (F# projects)
  • **/*.vbproj (Visual Basic projects)

The plugin analyzes your MSBuild project files to determine:

  • Project dependencies (via <ProjectReference> elements)
  • Available build targets (build, test, clean, etc.)
  • Project outputs and configuration

To view inferred tasks for a project, open the project details view in Nx Console or run nx show project my-project in the command line.

The @nx/dotnet is configured in the plugins array in nx.json.

nx.json
{
"plugins": [
{
"plugin": "@nx/dotnet",
"options": {
"buildTargetName": "build",
"testTargetName": "test",
"cleanTargetName": "clean",
"restoreTargetName": "restore",
"publishTargetName": "publish",
"packTargetName": "pack"
}
}
]
}

Once a .NET project file has been identified, the targets are created with the names you specify in the nx.json plugins array. The default names for the inferred targets are:

  • build - Compiles the project
  • test - Runs unit tests (for test projects)
  • clean - Removes build outputs
  • restore - Restores NuGet package dependencies
  • publish - Publishes the application (for executable projects)
  • pack - Creates a NuGet package (for library projects)

Not all targets are available for every project type. The plugin intelligently determines which targets to create based on the project type:

  • Console Applications & Web Projects: build, clean, restore, publish
  • Class Libraries: build, clean, restore, pack
  • Test Projects: build, clean, restore, test

.NET doesn't have a standard way to identify tasks which are continuous, like run or watch for serving an application during development. To ensure Nx handles these continuous tasks correctly, you can explicitly mark them as continuous.

In the nx.json, you can specify the target default configuration like so:

nx.json
{
"targetDefaults": {
"watch": {
"continuous": true
}
}
}

The @nx/dotnet plugin supports MSBuild configurations (Debug, Release, etc.) through Nx's configuration system. You can run tasks with specific configurations:

# Build with Release configuration
nx build my-app --configuration release
# Build with Debug configuration (usually the default)
nx build my-app --configuration debug