Skip to content
Merged
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
21 changes: 20 additions & 1 deletion src/targets/nuget.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs';
Comment thread
BYK marked this conversation as resolved.
import {
existsSync,
readFileSync,
readdirSync,
renameSync,
writeFileSync,
} from 'fs';
import { join } from 'path';

import { TargetConfig, TypedTargetConfig } from '../schemas/project_config';
Expand Down Expand Up @@ -78,6 +84,15 @@ export class NugetTarget extends BaseTarget {
}

if (hasExecutable(NUGET_DOTNET_BIN)) {
// `dotnet-setversion` operates in cwd and will pickup global.json,
// which breaks if the pinned SDK isn't installed on the craft runner.
// See: https://github.com/getsentry/craft/issues/819
const globalJsonPath = join(rootDir, 'global.json');
const globalJsonBackup = `${globalJsonPath}.craft-bak`;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use a unique name per instance to avoid any potential clashes but since the probabiliy is very low, I'll merge it as it. Would appreciate a follow up to fix this tho.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const globalJsonMoved = existsSync(globalJsonPath);
if (globalJsonMoved) {
renameSync(globalJsonPath, globalJsonBackup);
}
try {
const result = await spawnProcess(
NUGET_DOTNET_BIN,
Expand All @@ -99,6 +114,10 @@ export class NugetTarget extends BaseTarget {
logger.debug(
'dotnet-setversion not available, falling back to manual edit',
);
} finally {
if (globalJsonMoved) {
renameSync(globalJsonBackup, globalJsonPath);
}
}
}

Expand Down
Loading