Skip to content

Commit 830621a

Browse files
Copilotbaronfel
andcommitted
Fix build errors: update StreamWriter constructor and fix shouldWriteFile variable usage
Co-authored-by: baronfel <573979+baronfel@users.noreply.github.com>
1 parent e0a5f02 commit 830621a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ private static void WriteToJsonFile(string fileName, object value)
397397

398398
// Generate new content
399399
contentStream = new MemoryStream();
400-
using (var streamWriter = new StreamWriter(contentStream, Encoding.UTF8, leaveOpen: true))
400+
using (var streamWriter = new StreamWriter(contentStream, Encoding.UTF8, 1024, true))
401401
using (var jsonWriter = new JsonTextWriter(streamWriter))
402402
{
403403
serializer.Serialize(jsonWriter, value);
@@ -430,16 +430,18 @@ private static void WriteToJsonFile(string fileName, object value)
430430
// If hashes are equal, content is the same - don't write
431431
if (existingHashBuffer.SequenceEqual(newHashBuffer))
432432
{
433-
contentStream?.Dispose();
434-
return;
433+
shouldWriteFile = false;
435434
}
436435
}
437436

438-
// Write the new content to file using CopyTo
439-
using (var fileStream = File.Create(fileName))
437+
if (shouldWriteFile)
440438
{
441-
contentStream.Position = 0;
442-
contentStream.CopyTo(fileStream);
439+
// Write the new content to file using CopyTo
440+
using (var fileStream = File.Create(fileName))
441+
{
442+
contentStream.Position = 0;
443+
contentStream.CopyTo(fileStream);
444+
}
443445
}
444446

445447
contentStream?.Dispose();

0 commit comments

Comments
 (0)