fix: Avoid global.json when running all dotnet commands#614
Merged
Conversation
Flash0ver
commented
Jul 28, 2025
| * Spawn options to run outside the repository folder to avoid global.json constraints | ||
| * (we don't need specific dotnet/workload versions just to upload to nuget) | ||
| */ | ||
| const SPAWN_OPTIONS = { cwd: '/' }; |
Member
Author
There was a problem hiding this comment.
question: Is this the right way to do it?
Alternative:
As private readonly field on class NugetTarget.
Member
|
Thanks @asottile-sentry |
BYK
pushed a commit
that referenced
this pull request
Oct 1, 2025
* fix: apply spawnOptions to other dotnet commands * ref: more precise name and comment
BYK
pushed a commit
that referenced
this pull request
May 22, 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The Sentry .NET SDK uses a global.json file to pin a specific version of the .NET SDK and .NET Workloads to ensure reproducible builds.
When pushing the Sentry NuGet packages and Symbol packages, we can use any version of the .NET SDK,
as long as we ensure that the actual
dotnet build,dotnet test, and creating the packages viadotnet packrun with the pinned version of the .NET SDK.In a previous PR, see #601,
we applied
spawnOptionsto the invocation ofdotnet nuget pushviaspawnProcess,with which we set the Working Directory outside of the
sentry-dotnetrepository,so that the
global.jsondoes not get picked up / enforced.However,
we forgot to apply the same
spawnOptionsto the other invocations ofdotnetcommands.This manifests in failure when invoking
dotnet --version:Publish using Craft
Changes
Applying the previously added
spawnOptionsto the invocations of alldotnetcommands,not just
dotnet nuget push.See also
dotnet push#601