Description
See dotnet/msbuild#8273
It appears that when passed a symlink, File.Copy overwrites the file at the other end of the symlink rather than overwriting the symlink. Is this intentional behavior? If so, perhaps there should be an overload that just overwrites the symlink?
Reproduction Steps
(From the issue above)
- Build an executable project with hard or symbolic links enabled
- Update the version of referenced NuGet package
- Build the application again, but this time, without using hard/symbolic links.
MSBuild will try to update dependencies in the application's output folder. Sadly, instead of replacing existing links, it replaces actual files in NuGet cache (thus corrupting it).
dotnet nuget locals --clear all
dotnet new console
dotnet add package newtonsoft.json -v 13.0.1
dotnet build /p:CreateHardLinksForCopyLocalIfPossible=true
dotnet add package newtonsoft.json -v 13.0.2
dotnet build
dotnet nuget locals --clear all
dotnet new console
dotnet add package newtonsoft.json -v 13.0.1
dotnet build /p:CreateSymbolicLinksForCopyLocalIfPossible=true
dotnet add package newtonsoft.json -v 13.0.2
dotnet build
In both cases file newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dll is silently replaced with newtonsoft.json\13.0.2\lib\net6.0\Newtonsoft.Json.dll:
Expected behavior
Files in the NuGet cache remain untouched.
Actual behavior
Files in a NuGet package are silently replaced with files from another version.
Regression?
No response
Known Workarounds
Delete the file before calling Copy
Configuration
No response
Other information
No response
Description
See dotnet/msbuild#8273
It appears that when passed a symlink, File.Copy overwrites the file at the other end of the symlink rather than overwriting the symlink. Is this intentional behavior? If so, perhaps there should be an overload that just overwrites the symlink?
Reproduction Steps
(From the issue above)
MSBuild will try to update dependencies in the application's output folder. Sadly, instead of replacing existing links, it replaces actual files in NuGet cache (thus corrupting it).
In both cases file
newtonsoft.json\13.0.1\lib\netstandard2.0\Newtonsoft.Json.dllis silently replaced withnewtonsoft.json\13.0.2\lib\net6.0\Newtonsoft.Json.dll:Expected behavior
Files in the NuGet cache remain untouched.
Actual behavior
Files in a NuGet package are silently replaced with files from another version.
Regression?
No response
Known Workarounds
Delete the file before calling Copy
Configuration
No response
Other information
No response