Skip to content

fix(nuget): move global.json aside during dotnet setversion#820

Merged
BYK merged 3 commits into
getsentry:masterfrom
jamescrosswell:fix/setversion-global-json
May 22, 2026
Merged

fix(nuget): move global.json aside during dotnet setversion#820
BYK merged 3 commits into
getsentry:masterfrom
jamescrosswell:fix/setversion-global-json

Conversation

@jamescrosswell
Copy link
Copy Markdown
Contributor

@jamescrosswell jamescrosswell commented May 21, 2026

Summary

Fixes #819. Refs getsentry/sentry-dotnet#5250.

The automatic version bumping added in #707 invokes dotnet setversion with cwd: rootDir, so the dotnet host reads any global.json in the consumer repo. The release runner won't always have that exact SDK installed — dotnet then refuses to launch and craft prepare aborts.

Other dotnet invocations in this target dodge this by spawning with cwd: '/' (see #601, #614). That isn't viable here because dotnet-setversion operates on files in cwd.

Instead, this PR temporarily renames global.json to global.json.craft-bak for the duration of the call and restores it in a finally. The XML-fallback path is unchanged and unaffected.

Notes for reviewers

  • An alternative workaround would be to skip dotnet-setversion altogether and rely on the xml based version update logic that is currently a fallback. Hard to say which workaround is better.
  • No existing test file for nuget.ts (src/targets/__tests__/ has no nuget.test.ts), so this PR doesn't add one. Happy to add one if you'd like — let me know the preferred shape.

Consumer repos often pin SDK/workload versions in global.json with
rollForward: disable for deterministic builds. The automatic version
bump path added in getsentry#707 invokes `dotnet setversion` with cwd=rootDir,
which causes the dotnet host to read global.json and refuse to launch
if the pinned SDK isn't installed on the release runner.

Other dotnet invocations in this target avoid this by spawning with
cwd: '/' (see getsentry#601, getsentry#614). That's not viable for `dotnet-setversion`
because it operates on files in cwd. Instead, temporarily rename
global.json out of the way for the duration of the call and restore
it in a finally block.

Fixes getsentry#819
Refs getsentry/sentry-dotnet#5250
Comment thread src/targets/nuget.ts
The Lint workflow only runs on pull_request, so this pre-existing
violation in nuget.ts never failed CI on master. Surfacing it via this
PR — applying `pnpm format:check` so the workflow passes.
@jamescrosswell jamescrosswell marked this pull request as ready for review May 22, 2026 00:53
@jamescrosswell
Copy link
Copy Markdown
Contributor Author

The Change log Preview fails, but I suspect that's because I'm making the PR from a fork (I'm a contractor so don't have permission to create a PR on the repo directly).

Copy link
Copy Markdown
Member

@BYK BYK left a comment

Choose a reason for hiding this comment

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

Thanks so much and sorry for the trouble!

Comment thread src/targets/nuget.ts
// 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.

@BYK BYK merged commit da0e0c1 into getsentry:master May 22, 2026
14 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in nuget automatic version bump breaks dotnet releases Release pipeline fails: craft prepare picks up pinned SDK via global.json

2 participants