The problem I am trying to fix is this
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.
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