Skip to content

Commit e0f04eb

Browse files
authored
fix(core): remove workaround for broken dotnet format builtin (#443)
1 parent ef7c11d commit e0f04eb

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

packages/core/src/executors/format/executor.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { workspaceRoot } from 'nx/src/utils/app-root';
33

44
import { existsSync } from 'fs';
55
import { join } from 'path';
6+
import * as semver from 'semver';
67

78
import { DotNetClient, dotnetFactory } from '@nx-dotnet/dotnet';
89
import {
@@ -35,18 +36,20 @@ export default async function runExecutor(
3536
dotnetClient: DotNetClient = new DotNetClient(dotnetFactory()),
3637
) {
3738
const sdkVersion = dotnetClient.getSdkVersion();
38-
const majorVersion = parseInt(sdkVersion.split('.')[0]);
39-
const isNet6OrHigher = majorVersion >= 6;
39+
const forceToolUsage = semver.satisfies(sdkVersion, '6.0.0 - 6.0.203');
40+
const majorVersion = semver.major(sdkVersion);
4041

4142
const nxProjectConfiguration = getExecutedProjectConfiguration(context);
4243
const projectFilePath = await getProjectFileForNxProject(
4344
nxProjectConfiguration,
4445
);
4546

46-
const normalized = normalizeOptions(options, isNet6OrHigher);
47+
const normalized = normalizeOptions(options, majorVersion >= 6);
4748

48-
ensureFormatToolInstalled(context, dotnetClient, majorVersion);
49-
dotnetClient.format(projectFilePath, normalized, isNet6OrHigher);
49+
if (forceToolUsage || majorVersion < 6) {
50+
ensureFormatToolInstalled(context, dotnetClient, majorVersion);
51+
}
52+
dotnetClient.format(projectFilePath, normalized, forceToolUsage);
5053

5154
return {
5255
success: true,
@@ -58,14 +61,6 @@ function ensureFormatToolInstalled(
5861
dotnetClient: DotNetClient,
5962
majorVersion: number,
6063
) {
61-
// Currently the built-in .NET Format executor is broken on .NET 6
62-
// Fall back to installing and using the tool directly
63-
// eslint-disable-next-line no-constant-condition
64-
if (false && majorVersion >= 6) {
65-
// dotnet-format is already included as part of .NET SDK 6+
66-
return;
67-
}
68-
6964
const manifestPath = join(workspaceRoot, './.config/dotnet-tools.json');
7065
console.log(manifestPath);
7166
const manifest = existsSync(manifestPath)

packages/dotnet/src/lib/core/dotnet.client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ export class DotNetClient {
169169
forceToolUsage?: boolean,
170170
): void {
171171
const params = forceToolUsage
172-
? ['tool', 'run', 'dotnet-format', project]
172+
? ['tool', 'run', 'dotnet-format', '--', project]
173173
: [`format`, project];
174174
if (parameters) {
175175
parameters = swapKeysUsingMap(parameters, formatKeyMap);

0 commit comments

Comments
 (0)