Remove NoWarn and fix .NET 10 warnings

This removes the repository-level NoWarn suppression and fixes the warnings that appear after the .NET 10 migration in #9179.

The changes keep the build warning-free by annotating Windows-only APIs, fixing Avalonia/WPF build warnings, and pinning package versions that otherwise produce restore/build warnings.
This commit is contained in:
Miheichev Aleksandr Sergeevich 2026-04-28 20:05:36 +03:00
parent aba0e9c222
commit 9e62b1d6fe
16 changed files with 40 additions and 10 deletions

View file

@ -8,7 +8,6 @@
<TargetFramework>net10.0</TargetFramework>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<NoWarn>CA1031;CS1591;NU1507;CA1416;IDE0058;IDE0053;IDE0200</NoWarn>
<Nullable>annotations</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Authors>2dust</Authors>

View file

@ -24,13 +24,15 @@
<PackageVersion Include="Semi.Avalonia" Version="11.3.7.3" />
<PackageVersion Include="Semi.Avalonia.AvaloniaEdit" Version="11.2.0.2" />
<PackageVersion Include="Semi.Avalonia.DataGrid" Version="11.3.7.3" />
<PackageVersion Include="SQLitePCLRaw.bundle_green" Version="2.1.11" />
<PackageVersion Include="NLog" Version="6.1.2" />
<PackageVersion Include="sqlite-net-pcl" Version="1.9.172" />
<PackageVersion Include="TaskScheduler" Version="2.12.2" />
<PackageVersion Include="Tmds.DBus.Protocol" Version="0.21.3" />
<PackageVersion Include="WebDav.Client" Version="2.9.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.1.5" />
<PackageVersion Include="xunit.v3" Version="3.2.2" />
<PackageVersion Include="YamlDotNet" Version="16.3.0" />
<PackageVersion Include="ZXing.Net.Bindings.SkiaSharp" Version="0.16.14" />
</ItemGroup>
</Project>
</Project>

View file

@ -1114,12 +1114,14 @@ public class Utils
#region Platform
[SupportedOSPlatformGuard("windows")]
public static bool IsWindows() => OperatingSystem.IsWindows();
public static bool IsLinux() => OperatingSystem.IsLinux();
public static bool IsMacOS() => OperatingSystem.IsMacOS();
[UnsupportedOSPlatformGuard("windows")]
public static bool IsNonWindows() => !OperatingSystem.IsWindows();
public static string GetExeName(string name)
@ -1214,6 +1216,16 @@ public class Utils
}
public static bool SetUnixFileMode(string? fileName)
{
if (IsWindows())
{
return false;
}
return SetUnixFileModeInternal(fileName);
}
[UnsupportedOSPlatform("windows")]
private static bool SetUnixFileModeInternal(string? fileName)
{
try
{

View file

@ -2,6 +2,7 @@ using Microsoft.Win32;
namespace ServiceLib.Common;
[SupportedOSPlatform("windows")]
internal static class WindowsUtils
{
private static readonly string _tag = "WindowsUtils";

View file

@ -8,6 +8,7 @@ global using System.Reactive.Disposables;
global using System.Reactive.Linq;
global using System.Reflection;
global using System.Runtime.InteropServices;
global using System.Runtime.Versioning;
global using System.Security.Cryptography;
global using System.Text;
global using System.Text.Encodings.Web;

View file

@ -41,6 +41,7 @@ public static class AutoStartupHandler
#region Windows
[SupportedOSPlatform("windows")]
private static async Task ClearTaskWindows()
{
var autoRunName = GetAutoRunNameWindows();
@ -53,6 +54,7 @@ public static class AutoStartupHandler
await Task.CompletedTask;
}
[SupportedOSPlatform("windows")]
private static async Task SetTaskWindows()
{
try
@ -82,6 +84,7 @@ public static class AutoStartupHandler
/// <param name="fileName"></param>
/// <param name="description"></param>
/// <exception cref="ArgumentNullException"></exception>
[SupportedOSPlatform("windows")]
public static void AutoStartTaskService(string taskName, string fileName, string description)
{
if (taskName.IsNullOrEmpty())

View file

@ -2,6 +2,7 @@ using static ServiceLib.Handler.SysProxy.ProxySettingWindows.InternetConnectionO
namespace ServiceLib.Handler.SysProxy;
[SupportedOSPlatform("windows")]
public static class ProxySettingWindows
{
private const string _regPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";

View file

@ -88,6 +88,7 @@ public static class SysProxyHandler
}
}
[SupportedOSPlatform("windows")]
private static async Task SetWindowsProxyPac(int port)
{
var portPac = AppManager.Instance.GetLocalPort(EInboundProtocol.pac);

View file

@ -8,6 +8,7 @@ public class CoreManager
private static readonly Lazy<CoreManager> _instance = new(() => new());
public static CoreManager Instance => _instance.Value;
private Config _config;
[SupportedOSPlatform("windows")]
private WindowsJobService? _processJob;
private ProcessService? _processService;
private ProcessService? _processPreService;

View file

@ -3,6 +3,7 @@ namespace ServiceLib.Services;
/// <summary>
/// http://stackoverflow.com/questions/6266820/working-example-of-createjobobject-setinformationjobobject-pinvoke-in-net
/// </summary>
[SupportedOSPlatform("windows")]
public sealed class WindowsJobService : IDisposable
{
private nint handle = nint.Zero;

View file

@ -23,6 +23,7 @@ public partial class QRCodeAvaloniaUtils
}
}
[SupportedOSPlatform("windows")]
private static byte[]? CaptureScreenWindows()
{
var hdcScreen = IntPtr.Zero;

View file

@ -5,6 +5,7 @@ global using System.IO;
global using System.Linq;
global using System.Reactive.Disposables.Fluent;
global using System.Reactive.Linq;
global using System.Runtime.Versioning;
global using System.Text;
global using System.Threading;
global using System.Threading.Tasks;

View file

@ -8,6 +8,7 @@ public sealed class HotkeyManager
private static readonly Lazy<HotkeyManager> _instance = new(() => new());
public static HotkeyManager Instance = _instance.Value;
private readonly Dictionary<int, EGlobalHotkey> _hotkeyTriggerDic = new();
[SupportedOSPlatform("windows")]
private GlobalHotKeys.HotKeyManager? _hotKeyManager;
private Config? _config;
@ -16,6 +17,7 @@ public sealed class HotkeyManager
public bool IsPause { get; set; } = false;
[SupportedOSPlatform("windows")]
public void Init(Config config, Action<EGlobalHotkey> updateFunc)
{
_config = config;
@ -26,9 +28,14 @@ public sealed class HotkeyManager
public void Dispose()
{
if (!Utils.IsWindows())
{
return;
}
_hotKeyManager?.Dispose();
}
[SupportedOSPlatform("windows")]
private void Register()
{
if (_config.GlobalHotkeys.Any(t => t.KeyCode > 0) == false)

View file

@ -4,6 +4,11 @@ namespace v2rayN.Desktop.Views;
public partial class MessageBoxDialog : Window
{
public MessageBoxDialog()
: this(string.Empty, string.Empty)
{
}
public MessageBoxDialog(string caption, string message)
{
InitializeComponent();

View file

@ -1,12 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
<!-- Enable themes for Windows common controls and dialogs (Windows XP and later) -->
<dependency>
<dependentAssembly>
@ -20,4 +13,4 @@
/>
</dependentAssembly>
</dependency>
</assembly>
</assembly>

View file

@ -7,6 +7,7 @@
<UseWPF>true</UseWPF>
<ApplicationIcon>Resources\v2rayN.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationHighDpiMode>PerMonitorV2</ApplicationHighDpiMode>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>