.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:
- Cache task results
- Distribute task execution
- Run only tasks affected by a PR
- Interactively explore your workspace
Setup @nx/dotnet
Section titled “Setup @nx/dotnet”Install Nx
Section titled “Install Nx”You can install Nx globally. Depending on your package manager, use one of the following commands:
npm add --global nx@latest
brew install nx
choco install nx
sudo add-apt-repository ppa:nrwl/nxsudo apt updatesudo apt install nx
Add Nx to a .NET Workspace
Section titled “Add Nx to a .NET Workspace”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>
Add .NET to an Existing Nx Workspace
Section titled “Add .NET to an Existing Nx Workspace”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
How @nx/dotnet Infers Tasks
Section titled “How @nx/dotnet Infers Tasks”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
View Inferred Tasks
Section titled “View Inferred Tasks”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.
@nx/dotnet Configuration
Section titled “@nx/dotnet Configuration”The @nx/dotnet
is configured in the plugins
array in 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 projecttest
- Runs unit tests (for test projects)clean
- Removes build outputsrestore
- Restores NuGet package dependenciespublish
- Publishes the application (for executable projects)pack
- Creates a NuGet package (for library projects)
Target Availability
Section titled “Target Availability”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
Continuous Tasks
Section titled “Continuous Tasks”.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:
{ "targetDefaults": { "watch": { "continuous": true } }}
In a project.json
, you can specify the target configuration like so:
{ "watch": { "continuous": true }}
Working with Configurations
Section titled “Working with Configurations”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 configurationnx build my-app --configuration release
# Build with Debug configuration (usually the default)nx build my-app --configuration debug