Paket changes csproj file when adding/updating packages
Nobody has claimed this yet.
- Dominant language
- F#
- Stars
- 2.1k
- Forks
- 528
- Avg merge
- 1d 12m
- Merged PRs (30d)
- 54
Description
Description
Same problem as #3867 - when managing Paket via Directory.Build.targets, Paket will try and insert the targets again into the csproj file. It also reformats the project file in ways not consistent with MSBuild standards.
Repro steps
- Clone https://github.com/yaakov-h/paket-directorybuild.git
- Run
dotnet tool restore - Run
dotnet paket add NUnit
Expected behavior
The csproj remains unmodified and builds successfully.
Actual behavior
The csproj has an XML header added, whitespace stripped out, and a new MSBuild import added:
+<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
-
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
-
-</Project>
+ <Import Project="..\..\.paket\Paket.Restore.targets" />
+</Project>
The project also now emits:
warning MSB4011: "C:\Temp\paket-directorybuild\.paket\Paket.Restore
.targets" cannot be imported again. It was already imported at "C:\Temp\paket-directorybuild\src\MyClassLib\MyClassLib.csproj
(8,3)". This is most likely a build authoring error. This subsequent import will be ignored.
Known workarounds
Add --no-install to most commands when invoking dotnet paket.
This was mentioned as being by design in https://github.com/fsprojects/Paket/issues/3867#issuecomment-643312060, but surely there is something that can be done to opt out of this at a repository or project level?
As it stands, using Directory.Build.targets turns Paket's CLI into a footgun as its mutilation of project files is not easily undone, if there were already pending changes then a git reset will not fix this.
Additionally, it requires of my developers have to remember to use --no-install at all times, and they can easily forget or miss this instructions, particularly when onboarding and initially familiarising themselves with Paket's documentation.
Perhaps as well as avoiding an install operation, could Paket perserve whitespace and skip the XML header when writing csproj files? This would at least minimise the impact of an unwanted install operation and make it easier to undo.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior in the linked paket-directorybuild repository with dotnet paket add NUnit, then inspect how Paket handles Directory.Build.targets and the project .csproj. Done means the command leaves the .csproj unchanged, avoids a duplicate Paket.Restore.targets import, preserves its formatting, and the project builds without the MSB4011 warning.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100