Skip to content

[repo-assist] Fix #3209: preserve Paket.Restore.targets import position - #4364

Merged
dsyme merged 2 commits into
masterfrom
repo-assist/fix-issue-3209-import-reorder-05182a8ef02c2820
Aug 27, 2026
Merged

dsyme merged 2 commits into
masterfrom
repo-assist/fix-issue-3209-import-reorder-05182a8ef02c2820

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

This PR is submitted by Repo Assist, an automated AI assistant for this repository. 🤖

Closes #3209

Root cause

installForDotnetSDK (in src/Paket.Core/Installation/InstallProcess.fs) unconditionally called RemoveImportForPaketTargets() followed by AddImportForPaketTargets(...) on every paket install/restore, regardless of whether the correct <Import Project="...Paket.Restore.targets" /> node was already present. AddImportForPaketTargets always appends the new node at the end of the project file, so any project whose import was not already last got it moved there on every run.

Fix

Before removing/re-adding, check whether an Import node with the same relative path already exists. If it does, skip the remove/re-add entirely, leaving the existing node (and its position) untouched. This preserves import ordering for projects/tooling that depend on it, while still fixing/adding the import when it's missing or points at a different (stale) path.

Trade-offs

  • Minimal, surgical change — no behavior change for the common case where the import is missing or already at the end.
  • Did not add a dedicated unit test for this specific scenario due to the amount of scaffolding required to spin up a full ProjectFile/installForDotnetSDK test fixture; existing ProjectFile test suite (109 tests) still passes unmodified, confirming no regressions.

Test Status

  • ✅ Build: dotnet build src/Paket.Core/Paket.Core.fsproj -f netstandard2.0 — succeeded (0 errors).
  • ✅ Tests: dotnet test tests/Paket.Tests/Paket.Tests.fsproj -f net9 --filter "FullyQualifiedName~ProjectFile" — 109/109 passed.
  • Full solution build/test not run due to sandbox network restrictions (Build dependency group needs ci.appveyor.com); Main-group restore and targeted netstandard2.0/net9 build+test were used instead (documented workaround from prior runs).

Generated by 🌈 Repo Assist, see workflow run. Learn more.
Comment /repo-assist to run again

Add this agentic workflow to your repo

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@ae8d551f07c7ed7619f8c58c7bb4c3ac89395d38

Root cause: installForDotnetSDK unconditionally removed and re-appended
the <Import Project="...Paket.Restore.targets" /> node on every
install/restore, moving it to the end of the project file even when it
was already present at the same location. This broke projects that
rely on a specific import order.

Fix: skip the remove+re-add when an Import node with the same relative
path already exists, so the node's original position is preserved.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dsyme
dsyme marked this pull request as ready for review August 26, 2026 22:15
@dsyme

dsyme commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

/repo-assist Add a test for this

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

✓ Repo Assist completed successfully, see workflow run.

Command mode: responded to /repo-assist "Add a test for this" on PR #4364. Added tests/Paket.Tests/ProjectFile/InstallForDotnetSDKSpecs.fs with 2 unit tests covering InstallProcess.installForDotnetSDK's #3209 fix (import position preserved when already present; import still added when missing), registered in Paket.Tests.fsproj, and pushed the commit to the PR branch via push_to_pull_request_branch. Verified: dotnet test --filter "FullyQualifiedName~ProjectFile" — 111/111 passed. Per command-mode instructions, exiting without running the normal scheduled workflow tasks.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paket install moves <Import Project=".paket\Paket.Restore.targets" /> to the end

1 participant