The problem I am trying to fix is this
- we work with more than one person on several projects
- when person 1 updates a nuget package from version 1 to 2, then he sometimes has to uninstall version 1 and delete version 1 manually from the packages folder, since version 2 installed next to version 1 in stead of updating
- when person 2 does an "update" from SVN than he receives a packages.config that instructs his VS to get package version 2, but the package version 1 remains on his computer
- because the old package is still there, sometimes VS complains about it, or pushes it out again when we publish
So I thought I write a command line in the pre build
events, to clear the packages directory, so VS only fetches the correct versions before building,
but, it seems that the pre build
event does this AFTER Visual Studio fetches missing packages, which keeps the packages folder empty, and VS not building...
Is there a pre-pre build event ? That fires before VS starts fetching missing packages ? Or is there a better way to fix this problem ?
EDIT
Or is there maybe a command to tell VS to fetch missing packages ?
Then I could still use the pre-build
event, and just clear the packages folder and then tell VS to fetch its missing packages again.
CodePudding user response:
I found a solution,
after I cleared the packages folder I run the msbuild command with the task to restore all packages defined in my packages.config file.
If the folder was empty to start with (or missed on or more packages) then the restore happens 2 times, that I cannot avoid using this.
del /f /s /q $(ProjectDir)packages\*.*
rmdir /s /q $(ProjectDir)packages
cd $(SolutionDir)
"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild" "$(SolutionFileName)" -p:RestorePackagesConfig=true -t:restore