From a382c557cf2f926219a2ceb56fdfbd79333f7091 Mon Sep 17 00:00:00 2001 From: yuanwj Date: Thu, 3 Mar 2022 11:05:31 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=87=BA=E6=9D=A5=E7=9A=84=E6=96=87=E4=BB=B6=E5=9C=A8VS?= =?UTF-8?q?=E4=B8=AD=E6=8F=90=E7=A4=BA=E2=80=9C=E4=B8=8D=E4=B8=80=E8=87=B3?= =?UTF-8?q?=E7=9A=84=E8=A1=8C=E5=B0=BE=E2=80=9D=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SmartCode.App/Outputs/FileOutput.cs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/SmartCode.App/Outputs/FileOutput.cs b/src/SmartCode.App/Outputs/FileOutput.cs index 1efd8a3..1c089e5 100644 --- a/src/SmartCode.App/Outputs/FileOutput.cs +++ b/src/SmartCode.App/Outputs/FileOutput.cs @@ -69,21 +69,21 @@ public async Task Output(BuildContext context, Output output = null) { case Configuration.CreateMode.None: case Configuration.CreateMode.Incre: - { - _logger.LogWarning( - $"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------"); - return; - } + { + _logger.LogWarning( + $"------ Mode:{output.Mode},Build:{context.BuildKey},FilePath:{filePath} Exists ignore output End! ------"); + return; + } case Configuration.CreateMode.Full: - { - File.Delete(filePath); - _logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------"); - break; - } + { + File.Delete(filePath); + _logger.LogWarning($"------ Mode:{output.Mode},FilePath:{filePath} Exists Deleted ! ------"); + break; + } } } - using (StreamWriter streamWriter = new StreamWriter(filePath)) + using (StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding(true))) { await streamWriter.WriteAsync(context.Result.Trim()); } From a1005f4fbd9642359f6caec735b2e06684528279 Mon Sep 17 00:00:00 2001 From: yuanwj Date: Thu, 3 Mar 2022 11:45:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E8=A1=8C=E5=B0=BE?= =?UTF-8?q?=E4=B8=BA=20\R\N?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SmartCode.App/Outputs/FileOutput.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/SmartCode.App/Outputs/FileOutput.cs b/src/SmartCode.App/Outputs/FileOutput.cs index 1c089e5..602a4f0 100644 --- a/src/SmartCode.App/Outputs/FileOutput.cs +++ b/src/SmartCode.App/Outputs/FileOutput.cs @@ -7,6 +7,7 @@ using HandlebarsDotNet; using SmartCode.Configuration; using SmartCode.Utilities; +using System.Text.RegularExpressions; namespace SmartCode.App.Outputs { @@ -83,9 +84,12 @@ public async Task Output(BuildContext context, Output output = null) } } + //采购VS默认的UTF-8 WITH BOM 编码 using (StreamWriter streamWriter = new StreamWriter(filePath, false, new UTF8Encoding(true))) { - await streamWriter.WriteAsync(context.Result.Trim()); + //强制行尾为 \r\n + var result = Regex.Replace(context.Result.Trim(), @"[\r\n]+", "\r\n", RegexOptions.Multiline); + await streamWriter.WriteAsync(result); } _logger.LogInformation($"------ Mode:{output.Mode},Build:{context.BuildKey} -> {filePath} End! ------");