Skip to content

fix: Avoid global.json when running dotnet push#601

Merged
asottile-sentry merged 3 commits into
getsentry:masterfrom
jamescrosswell:any-dotnet-version
May 2, 2025
Merged

fix: Avoid global.json when running dotnet push#601
asottile-sentry merged 3 commits into
getsentry:masterfrom
jamescrosswell:any-dotnet-version

Conversation

@jamescrosswell

Copy link
Copy Markdown
Contributor

Resolves #598:

Pinning the version of of the .NET SDK used to build the sentry-dotnet repo prevents us from making relases, since that version of .NET is not installed on the machine that publishes NuGet packages.

We can run dotnet push using any version of .NET so this PR simply runs that command from outside the repository working directory.

Resolves getsentry#598:
- getsentry#598

Pinning the version of of the .NET SDK used to build the sentry-dotnet repo prevents us from making relases, since that version of .NET is not installed on the machine that publishes NuGet packages.

We can run `dotnet push` using any version of .NET so this PR simply runs that command from outside the repository working directory.
Comment thread src/targets/nuget.ts Outdated
Comment thread src/targets/nuget.ts

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.

@asottile-sentry any tips on how to test this? As far as I can tell, this would only ever be run when we try to make a release from the sentry-dotnet repo.

spawnProcess is well and truly battle tested. uploadAsset is simply a wrapper for this (passing specific arguments). There's no real logic to test. Ultimately, it "passes" the test if those arguments result in a real NuGet package being uploaded to nuget.org... I can't think of any meaningful tests other than that.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah there's not really much to test without copying the implementation details into the test

@jamescrosswell jamescrosswell May 1, 2025

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.

In that case, I think this PR is ready. We can make a new release from the sentry-dotnet repository as soon as it's merged to make sure it all hangs together.

@jamescrosswell jamescrosswell marked this pull request as ready for review May 1, 2025 03:55

@asottile-sentry asottile-sentry left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@jamescrosswell

jamescrosswell commented May 1, 2025

Copy link
Copy Markdown
Contributor Author

@asottile-sentry I suspect you might need to merge this (I don't think I have permission... I certainly don't have any merge button).

image

@asottile-sentry asottile-sentry merged commit d48a8b0 into getsentry:master May 2, 2025
8 checks passed
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.
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.

Temporarily disable global.json when pushing NuGet packages

2 participants