Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ weight: 2
filter: 'type:References'
---

{% aside type="caution" title="Experimental Plugin" %}
The `@nx/dotnet` plugin is currently experimental. Features and APIs may change.
{% /aside %}

[.NET](https://dotnet.microsoft.com/) 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](/docs/guides/nx-cloud/setup-ci).
Expand Down
9 changes: 8 additions & 1 deletion packages/dotnet/migrations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
{
"generators": {},
"generators": {
"update-23-0-0-migrate-dotnet-plugin-path": {
"cli": "nx",
"version": "23.0.0-beta.24",
"description": "Update `nx.json` plugin registrations that use the removed `@nx/dotnet/plugin` subpath to the bare `@nx/dotnet` specifier.",
"implementation": "./dist/migrations/update-23-0-0/update-plugin-path"
}
},
"packageJsonUpdates": {}
}
4 changes: 0 additions & 4 deletions packages/dotnet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./plugin": {
"default": "./dist/plugin.js",
"types": "./dist/plugin.d.ts"
},
"./generators/*/schema.json": "./dist/generators/*/schema.json",
"./generators/*/schema": "./dist/generators/*/schema.d.ts",
"./generators.json": "./generators.json",
Expand Down
2 changes: 0 additions & 2 deletions packages/dotnet/readme-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@

<hr>

> Note: The `@nx/dotnet` plugin is currently experimental. Features and APIs may change.

# Nx: Smart Monorepos · Fast Builds

Get to green PRs in half the time. Nx optimizes your builds, scales your CI, and fixes failed PRs. Built for developers and AI agents.
Expand Down
6 changes: 5 additions & 1 deletion packages/dotnet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export * from './plugin';
export {
createNodes,
createNodesV2,
createDependencies,
} from './plugins/plugin';

export { DotNetPluginOptions } from './plugins/create-nodes';
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { readNxJson, Tree } from '@nx/devkit';
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import update from './update-plugin-path';

describe('update-plugin-path migration', () => {
let tree: Tree;

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should do nothing when there are no plugins', () => {
tree.write('nx.json', JSON.stringify({ namedInputs: {} }));
update(tree);
expect(readNxJson(tree)).toMatchInlineSnapshot(`
{
"namedInputs": {},
}
`);
});

it('should leave the bare @nx/dotnet plugin untouched', () => {
tree.write('nx.json', JSON.stringify({ plugins: ['@nx/dotnet'] }));
update(tree);
expect(readNxJson(tree)?.plugins).toEqual(['@nx/dotnet']);
});

it('should rewrite the string @nx/dotnet/plugin entry to @nx/dotnet', () => {
tree.write('nx.json', JSON.stringify({ plugins: ['@nx/dotnet/plugin'] }));
update(tree);
expect(readNxJson(tree)?.plugins).toEqual(['@nx/dotnet']);
});

it('should rewrite the object @nx/dotnet/plugin entry while preserving options', () => {
tree.write(
'nx.json',
JSON.stringify({
plugins: [
{
plugin: '@nx/dotnet/plugin',
options: { build: { targetName: 'compile' } },
},
],
})
);
update(tree);
expect(readNxJson(tree)?.plugins).toEqual([
{ plugin: '@nx/dotnet', options: { build: { targetName: 'compile' } } },
]);
});

it('should update the entry in place, preserving the position of other plugins', () => {
tree.write(
'nx.json',
JSON.stringify({
plugins: ['@nx/js', '@nx/dotnet/plugin', { plugin: '@nx/eslint' }],
})
);
update(tree);
expect(readNxJson(tree)?.plugins).toEqual([
'@nx/js',
'@nx/dotnet',
{ plugin: '@nx/eslint' },
]);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { readNxJson, Tree, updateNxJson } from '@nx/devkit';

const OLD_PATH = '@nx/dotnet/plugin';
const NEW_PATH = '@nx/dotnet';

/**
* The `@nx/dotnet/plugin` subpath export has been removed in favor of the bare
* `@nx/dotnet` specifier. This migration rewrites any `nx.json` plugin entries
* that still register the plugin via the old `@nx/dotnet/plugin` path, updating
* each entry in place so the order of the `plugins` array is preserved.
*/
export default function update(tree: Tree) {
const nxJson = readNxJson(tree);
if (!nxJson?.plugins?.length) {
return;
}

let updated = false;
for (let i = 0; i < nxJson.plugins.length; i++) {
const plugin = nxJson.plugins[i];
if (typeof plugin === 'string') {
if (plugin === OLD_PATH) {
nxJson.plugins[i] = NEW_PATH;
updated = true;
}
} else if (plugin.plugin === OLD_PATH) {
plugin.plugin = NEW_PATH;
updated = true;
}
}

if (updated) {
updateNxJson(tree, nxJson);
}
}
5 changes: 0 additions & 5 deletions packages/dotnet/src/plugin.ts

This file was deleted.

28 changes: 13 additions & 15 deletions packages/dotnet/src/plugins/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import { createNodes, type DotNetPluginOptions } from './create-nodes';
import { createDependencies } from './create-dependencies';
import { NxPlugin } from '@nx/devkit';
import { createNodes as createDotNetNodes } from './create-nodes';
import { createDependencies as createDotNetDependencies } from './create-dependencies';

const regularPlugin: NxPlugin<DotNetPluginOptions> = {
name: '@nx/dotnet',
createNodes,
createNodesV2: createNodes,
createDependencies,
};
// The plugin can be fully disabled (e.g. to debug graph issues) via the
// NX_DOTNET_DISABLE environment variable. When disabled, no nodes or
// dependencies are created so Nx effectively ignores .NET projects.
const disabled = process.env.NX_DOTNET_DISABLE === 'true';

const noopPlugin: NxPlugin = {
name: '@nx/dotnet [disabled]',
};
export const name = disabled ? '@nx/dotnet [disabled]' : '@nx/dotnet';

const plugin: NxPlugin<DotNetPluginOptions> =
process.env.NX_DOTNET_DISABLE === 'true' ? noopPlugin : regularPlugin;
export const createNodes = disabled ? undefined : createDotNetNodes;

export = plugin;
export const createNodesV2 = disabled ? undefined : createDotNetNodes;

export const createDependencies = disabled
? undefined
: createDotNetDependencies;
Loading