Transform fails when project is targetting multiple frameworks
CraigRichards opened this issue · 2 comments
Hi,
I regularly target multiple frameworks in the work I do and this constantly fails due to file-locking issues. I love this product and hope you can patch this easily.
Reproduction is simple.
I target multiple frameworks as the API client should work for all framework versions and my tests required different configurations depending on the environment. net4;net45;net451;net452;net461;net462;net47;net471;net472;net48;netcoreapp3.0;netcoreapp3.1;net5;net6;net7
Error Message
Severity Code Description Project File Line Suppression State
Error MSB4018 The "SlowCheetah.TransformTask" task failed unexpectedly.
System.IO.IOException: The process cannot access the file 'd:\Api.Client.Tests\appSettings.Dev3.json' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
at Microsoft.VisualStudio.Jdt.JsonTransformation..ctor(String transformFile, IJsonTransformationLogger logger)
at Microsoft.VisualStudio.SlowCheetah.JsonTransformer.Transform(String sourcePath, String transformPath, String destinationPath)
at Microsoft.VisualStudio.SlowCheetah.TransformTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext() Api.Client.Tests D:\licensing-api\packages-cache\microsoft.visualstudio.slowcheetah\4.0.50\build\Microsoft.VisualStudio.SlowCheetah.targets 115
That's caused by a bug in another repository microsoft/json-document-transforms#21
It calls File.Open(transformFile, FileMode.Open, FileAccess.Read)
, which uses FileShare.None by default, thus does not allow anything else to read the same file at the same time. Should preferably just call File.OpenRead(transformFile)
, or alternatively specify FileShare.Read explicitly.