Getting Started
Prerequisites
- Have an existing nx workspace. For creating this, see nrwl's documentation.
- .NET SDK is installed, and
dotnet
is available on the path. For help on this, see Microsoft's documentation
Installation
NPM
npm i --save-dev @nx-dotnet/core
npx nx g @nx-dotnet/core:init
PNPM
pnpm i --save-dev @nx-dotnet/core
pnpx nx g @nx-dotnet/core:init
Yarn
yarn add --dev @nx-dotnet/core
npx nx g @nx-dotnet/core:init
Generate and run your first api!
Generate my-api, and my-api-test with C# and nunit tests.
npx nx g @nx-dotnet/core:app my-api --test-template nunit --language C#
Run my-api locally
npx nx serve my-api
nrwl/nx/enforce-module-boundaries support
Nrwl publishes an eslint rule for enforcing module boundaries based on tags in a library. We recently added similar support to nx-dotnet.
To avoid duplicating the rules configuration, if your workspace already has it, nx-dotnet can read the dependency constraints from your workspace's eslint files. It does this by looking at what is configured for typescript files.
If your workspace does not currently contain eslint, do not worry! You do not have to install eslint just for its configuration. The same dependency constraints can be placed inside of your .nx-dotnet.rc.json file at workspace root. This should look something like below:
{
"moduleBoundaries": [
{
"onlyDependOnLibsWithTags": ["a", "shared"],
"sourceTag": "a"
},
{
"onlyDependOnLibsWithTags": ["b", "shared"],
"sourceTag": "b"
},
{
"onlyDependOnLibsWithTags": ["shared"],
"sourceTag": "shared"
}
],
"nugetPackages": {}
}
API Reference
Generators
library
nx-dotnet generator
application
Generate a new C# project.
project-reference
Adds a reference from one project to another.
init
init generator
sync
sync generator
nuget-reference
nuget-reference generator
restore
Restores NuGet packages and .NET tools used by the workspace
test
Generate a .NET test project for an existing application or library
import-projects
Import existing projects into your nx workspace
add-swagger-target
Generate a target to extract the swagger.json file from a .NET webapi
swagger-typescript
Generates typescript code based on a specified openapi/swagger json file
move
Moves a dotnet based project and updates project references which pointed to it.
Executors
build
Invokes dotnet build
to build a project with .NET Core CLI
serve
Invokes dotnet watch
in combination with dotnet build
to run a dev-server
test
Invokes dotnet test
to execute unit tests via .NET Core CLI
publish
Invokes dotnet publish
format
Formats and lints a project using the dotnet-format tool
update-swagger
Generates a swagger document for an API project
openapi-codegen
Invokes nx g @nx-dotnet/core:swagger-typescript
with the proper parameters to update a codegen based library