From d9ad4d56c1f3eca1c91757441107232cb4ad407d Mon Sep 17 00:00:00 2001 From: Liam Sho Date: Wed, 22 Sep 2021 23:24:50 +0800 Subject: [PATCH 1/3] Change target frameworks and update dependencies Set CmlLib target to netstandard 2.0 and update its dependencies. Set CmlLibCoreSample target to net5.0. Set CmlLibWinFormSample target to netframework 4.7.2. --- CmlLib/CmlLib.csproj | 10 +++++----- CmlLibCoreSample/CmlLibCoreSample.csproj | 2 +- CmlLibWinFormSample/App.config | 2 +- CmlLibWinFormSample/CmlLibWinFormSample.csproj | 6 +++++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CmlLib/CmlLib.csproj b/CmlLib/CmlLib.csproj index 2dd041f..559dbc1 100644 --- a/CmlLib/CmlLib.csproj +++ b/CmlLib/CmlLib.csproj @@ -1,7 +1,7 @@ - + - netcoreapp3.1;net462;net5.0 + netstandard2.0 8.0 enable 3.3.2 @@ -25,7 +25,7 @@ Support all version, forge, optifine all - + all runtime; build; native; contentfiles; analyzers; buildtransitive @@ -33,8 +33,8 @@ Support all version, forge, optifine all - - + + diff --git a/CmlLibCoreSample/CmlLibCoreSample.csproj b/CmlLibCoreSample/CmlLibCoreSample.csproj index fe782b4..e77fc62 100644 --- a/CmlLibCoreSample/CmlLibCoreSample.csproj +++ b/CmlLibCoreSample/CmlLibCoreSample.csproj @@ -2,7 +2,7 @@ Exe - netcoreapp3.1 + net5.0 diff --git a/CmlLibWinFormSample/App.config b/CmlLibWinFormSample/App.config index 8d23437..ecdcf8a 100644 --- a/CmlLibWinFormSample/App.config +++ b/CmlLibWinFormSample/App.config @@ -1,6 +1,6 @@ - + diff --git a/CmlLibWinFormSample/CmlLibWinFormSample.csproj b/CmlLibWinFormSample/CmlLibWinFormSample.csproj index 6886ec4..3464e0d 100644 --- a/CmlLibWinFormSample/CmlLibWinFormSample.csproj +++ b/CmlLibWinFormSample/CmlLibWinFormSample.csproj @@ -8,10 +8,11 @@ WinExe CmlLibWinFormSample CmlLibWinFormSample - v4.6.2 + v4.7.2 512 true + PackageReference AnyCPU @@ -32,6 +33,9 @@ prompt 4 + + + From c05c4f78d4de0ca48f2ec98a715e3c8d750033d5 Mon Sep 17 00:00:00 2001 From: Liam Sho Date: Wed, 22 Sep 2021 23:27:00 +0800 Subject: [PATCH 2/3] Remove any framework specific code --- CmlLib/Core/MRule.cs | 13 +------------ CmlLib/Utils/IOUtil.cs | 16 +++------------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/CmlLib/Core/MRule.cs b/CmlLib/Core/MRule.cs index b751954..d877754 100644 --- a/CmlLib/Core/MRule.cs +++ b/CmlLib/Core/MRule.cs @@ -25,24 +25,13 @@ static MRule() private static string getOSName() { - // Environment.OSVersion.Platform does not work in NET Core -#if NETCOREAPP + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) return OSX; else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) return Windows; else return Linux; -#elif NETFRAMEWORK - var osType = Environment.OSVersion.Platform; - - if (osType == PlatformID.MacOSX) - return OSX; - else if (osType == PlatformID.Unix) - return Linux; - else - return Windows; -#endif } public static bool CheckOSRequire(JArray arr) diff --git a/CmlLib/Utils/IOUtil.cs b/CmlLib/Utils/IOUtil.cs index ef62007..eba1664 100644 --- a/CmlLib/Utils/IOUtil.cs +++ b/CmlLib/Utils/IOUtil.cs @@ -175,7 +175,7 @@ public static StreamWriter AsyncStreamWriter(string path, Encoding encoding, boo return new StreamWriter(stream, encoding); } - // In .NET Framework 4.6.2, There is no File.ReadFileTextAsync. so I copied it from .NET Core source code + // In .NET Standard 2.0, There is no File.ReadFileTextAsync. so I copied it from .NET Core source code public static async Task ReadFileAsync(string path) { using var reader = AsyncStreamReader(path, Encoding.UTF8); @@ -184,20 +184,15 @@ public static async Task ReadFileAsync(string path) await disposeStreamAsync(reader.BaseStream).ConfigureAwait(false); return content; } - - // In .NET Framework 4.6.2, There is no File.WriteFileTextAsync. so I copied it from .NET Core source code + + // In .NET Standard 2.0, There is no File.WriteFileTextAsync. so I copied it from .NET Core source code public static async Task WriteFileAsync(string path, string content) { // UTF8 with BOM might not be recognized by minecraft. not tested var encoder = new UTF8Encoding(false); var writer = AsyncStreamWriter(path, encoder, false); await writer.WriteAsync(content).ConfigureAwait(false); // **MUST be awaited in this scope** - -#if NETFRAMEWORK writer.Dispose(); -#elif NETCOREAPP - await writer.DisposeAsync().ConfigureAwait(false); -#endif } public static async Task CopyFileAsync(string sourceFile, string destinationFile) @@ -214,13 +209,8 @@ public static async Task CopyFileAsync(string sourceFile, string destinationFile private static Task disposeStreamAsync(Stream stream) { - // .NET Framework does not support DisposeAsync -#if NETFRAMEWORK stream.Dispose(); return Task.CompletedTask; -#elif NETCOREAPP - return stream.DisposeAsync().AsTask(); -#endif } #endregion From 2e20905037130fcd7c7e12a4241a9ac3391019d0 Mon Sep 17 00:00:00 2001 From: Liam Sho Date: Wed, 22 Sep 2021 23:37:09 +0800 Subject: [PATCH 3/3] Update release powershell script --- release.ps1 | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/release.ps1 b/release.ps1 index 873a7e3..555d2b1 100644 --- a/release.ps1 +++ b/release.ps1 @@ -1,9 +1,7 @@ -if ($args.Length -gt 0) -{ - $ver=$args[0] +if ($args.Length -gt 0) { + $ver = $args[0] } -else -{ +else { $ver = Read-Host 'version' } @@ -14,9 +12,8 @@ mkdir .\release\SampleCoreLauncher$ver mkdir .\release\SampleWinformLauncher$ver Copy-Item .\CmlLib\bin\Release\* -Destination .\release\CmlLib.Core.$ver -Recurse -Get-ChildItem .\release\CmlLib.Core.$ver -Recurse -File | Where {($_.Extension -ne ".dll")} | Remove-Item -Copy-Item -Path .\CmlLibCoreSample\bin\Release\netcoreapp3.1\* -Destination .\release\SampleCoreLauncher$ver -Copy-Item .\CmlLibWinFormSample\bin\Release\* -Destination .\release\SampleWinformLauncher$ver -Include *.exe,*.dll,*.pdb,*.config +Get-ChildItem .\release\CmlLib.Core.$ver -Recurse -File | Where-Object { ($_.Extension -ne ".dll") } | Remove-Item +Copy-Item .\CmlLibWinFormSample\bin\Release\* -Destination .\release\SampleWinformLauncher$ver -Include *.exe, *.dll, *.pdb, *.config Compress-Archive -Path .\release\CmlLib.Core.$ver -DestinationPath .\release\CmlLib.Core.$ver.zip Compress-Archive -Path .\release\SampleCoreLauncher$ver -DestinationPath .\release\SampleCoreLauncher$ver.zip