feature<Project>: supports build with .NET 6

This commit is contained in:
leo 2021-10-28 15:47:47 +08:00
parent 898599afc9
commit 3628729a93
5 changed files with 74 additions and 7 deletions

View file

@ -25,4 +25,18 @@ dotnet publish SourceGit.csproj --nologo -c Release -r win-x64 -f net5.0-windows
cd ..\publish cd ..\publish
ren SourceGit.exe SourceGit.net5.0.x64.exe ren SourceGit.exe SourceGit.net5.0.x64.exe
cd ..\src
rmdir /s /q bin
rmdir /s /q obj
dotnet publish SourceGit.csproj --nologo -c Release -r win-x86 -f net6.0-windows -p:PublishSingleFile=true --no-self-contained -o ..\publish
cd ..\publish
ren SourceGit.exe SourceGit.net6.0.x86.exe
cd ..\src
rmdir /s /q bin
rmdir /s /q obj
dotnet publish SourceGit.csproj --nologo -c Release -r win-x64 -f net6.0-windows -p:PublishSingleFile=true --no-self-contained -o ..\publish
cd ..\publish
ren SourceGit.exe SourceGit.net6.0.x64.exe
cd ../ cd ../

View file

@ -1,10 +1,15 @@
using System; using System;
using System.Net;
using System.Reflection; using System.Reflection;
using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
#if NET6_0_OR_GREATER
using System.Net.Http;
#else
using System.Net;
using System.Text;
#endif
namespace SourceGit.Models { namespace SourceGit.Models {
/// <summary> /// <summary>
/// 崩溃日志上报 /// 崩溃日志上报
@ -40,6 +45,13 @@ namespace SourceGit.Models {
e.Source, e.Source,
e.StackTrace); e.StackTrace);
#if NET6_0_OR_GREATER
var req = new HttpClient();
req.DefaultRequestHeaders.Add("Content-Type", "application/json");
req.DefaultRequestHeaders.Add("charset", "UTF-8");
req.Timeout = TimeSpan.FromSeconds(1);
req.PostAsync("https://gitee.com/api/v5/repos/sourcegit/issues", new StringContent(JsonSerializer.Serialize(issue))).Wait();
#else
var req = WebRequest.CreateHttp("https://gitee.com/api/v5/repos/sourcegit/issues"); var req = WebRequest.CreateHttp("https://gitee.com/api/v5/repos/sourcegit/issues");
req.Method = "POST"; req.Method = "POST";
req.ContentType = "application/json"; req.ContentType = "application/json";
@ -53,6 +65,7 @@ namespace SourceGit.Models {
} }
req.GetResponse(); req.GetResponse();
#endif
} catch { } } catch { }
} }
} }

View file

@ -1,12 +1,17 @@
using System; using System;
using System.Net;
using System.Reflection; using System.Reflection;
using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
#if NET6_0_OR_GREATER
using System.Net.Http;
#else
using System.Net;
using System.Text;
#endif
namespace SourceGit.Models { namespace SourceGit.Models {
/// <summary> /// <summary>
@ -43,10 +48,18 @@ namespace SourceGit.Models {
var lastDayOfYear = Preference.Instance.General.LastCheckDay; var lastDayOfYear = Preference.Instance.General.LastCheckDay;
if (lastDayOfYear != curDayOfYear) { if (lastDayOfYear != curDayOfYear) {
Preference.Instance.General.LastCheckDay = curDayOfYear; Preference.Instance.General.LastCheckDay = curDayOfYear;
Task.Run(() => { Task.Run(async () => {
try { try {
#if NET6_0_OR_GREATER
var req = new HttpClient();
var rsp = await req.GetAsync("https://gitee.com/api/v5/repos/sourcegit/sourcegit/releases/latest");
rsp.EnsureSuccessStatusCode();
var raw = await rsp.Content.ReadAsStringAsync();
#else
var web = new WebClient() { Encoding = Encoding.UTF8 }; var web = new WebClient() { Encoding = Encoding.UTF8 };
var raw = web.DownloadString("https://gitee.com/api/v5/repos/sourcegit/sourcegit/releases/latest"); var raw = await web.DownloadStringTaskAsync("https://gitee.com/api/v5/repos/sourcegit/sourcegit/releases/latest");
#endif
var ver = JsonSerializer.Deserialize<Version>(raw); var ver = JsonSerializer.Deserialize<Version>(raw);
var cur = Assembly.GetExecutingAssembly().GetName().Version; var cur = Assembly.GetExecutingAssembly().GetName().Version;

View file

@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net5.0-windows;net48</TargetFrameworks> <TargetFrameworks>net6.0-windows;net5.0-windows;net48</TargetFrameworks>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
<ApplicationIcon>App.ico</ApplicationIcon> <ApplicationIcon>App.ico</ApplicationIcon>

View file

@ -11,6 +11,10 @@ using System.Windows.Controls;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
#if NET6_0_OR_GREATER
using System.Net.Http;
#endif
namespace SourceGit.Views.Controls { namespace SourceGit.Views.Controls {
/// <summary> /// <summary>
@ -192,6 +196,28 @@ namespace SourceGit.Views.Controls {
if (!requesting.ContainsKey(email)) return; if (!requesting.ContainsKey(email)) return;
try { try {
#if NET6_0_OR_GREATER
var req = new HttpClient().GetAsync(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
req.Wait();
var rsp = req.Result;
if (rsp != null && rsp.StatusCode == HttpStatusCode.OK) {
var writer = File.OpenWrite(filePath);
rsp.Content.CopyToAsync(writer).Wait();
writer.Close();
a.Dispatcher.Invoke(() => {
var img = new BitmapImage(new Uri(filePath));
loaded.Add(email, img);
if (requesting.ContainsKey(email)) {
foreach (var one in requesting[email]) one.Source = img;
}
});
} else {
if (!loaded.ContainsKey(email)) loaded.Add(email, null);
}
#else
HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404"); HttpWebRequest req = WebRequest.CreateHttp(Models.Preference.Instance.General.AvatarServer + md5 + "?d=404");
req.Timeout = 2000; req.Timeout = 2000;
req.Method = "GET"; req.Method = "GET";
@ -214,6 +240,7 @@ namespace SourceGit.Views.Controls {
} else { } else {
if (!loaded.ContainsKey(email)) loaded.Add(email, null); if (!loaded.ContainsKey(email)) loaded.Add(email, null);
} }
#endif
} catch { } catch {
if (!loaded.ContainsKey(email)) loaded.Add(email, null); if (!loaded.ContainsKey(email)) loaded.Add(email, null);
} }