Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-target .NET Framework 4.8 and .NET 8 #3745

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ErrorReport>prompt</ErrorReport>
<Features>strict</Features>
<IsTargetingNetFramework>$(TargetFramework.StartsWith("net4"))</IsTargetingNetFramework>
<LangVersion>10.0</LangVersion>
<LangVersion>12.0</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<NoWarn>SA0001</NoWarn>
<Nullable>enable</Nullable>
Expand All @@ -27,8 +27,7 @@
<Optimize>false</Optimize>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>portable</DebugType>
<DebugType>none</DebugType>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<PathMap>$(MSBuildProjectDirectory)=${$(MSBuildProjectName)}/</PathMap>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<PackageVersion Include="Silk.NET.OpenGL.Legacy" Version="2.18.0" />
<PackageVersion Include="SQLitePCLRaw.provider.e_sqlite3" Version="2.1.8" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.435" /><!-- don't forget to update .stylecop.json at the same time -->
<PackageVersion Include="System.Collections.Immutable" Version="7.0.0" />
<PackageVersion Include="System.Collections.Immutable" Version="8.0.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="System.Drawing.Common" Version="6.0.0" />
<PackageVersion Include="System.Memory" Version="4.5.5" />
Expand Down
Binary file modified References/BizHawk.Analyzer.dll
Binary file not shown.
Binary file modified References/BizHawk.SrcGen.ReflectionCache.dll
Binary file not shown.
Binary file modified References/BizHawk.SrcGen.SettingsUtil.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion src/BizHawk.BizInvoke/BizHawk.BizInvoke.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48;net8.0</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.BizInvoke/BizInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ private static ParameterLoadInfo EmitParamterLoad(ILGenerator il, int idx, Type
il.Emit(OpCodes.Brfalse, isNull);

var encoding = il.DeclareLocal(typeof(Encoding), false);
il.EmitCall(OpCodes.Call, typeof(Encoding).GetProperty("UTF8")!.GetGetMethod(), Type.EmptyTypes);
il.EmitCall(OpCodes.Call, typeof(Encoding).GetProperty("UTF8")!.GetGetMethod()!, Type.EmptyTypes);
il.Emit(OpCodes.Stloc, encoding);

var strlenbytes = il.DeclareLocal(typeof(int), false);
Expand Down Expand Up @@ -632,7 +632,7 @@ private static ParameterLoadInfo EmitParamterLoad(ILGenerator il, int idx, Type
il.Emit(OpCodes.Add);
// charcount
il.Emit(OpCodes.Ldloc, strval);
il.Emit(OpCodes.Call, typeof(string).GetProperty("Length")!.GetGetMethod());
il.Emit(OpCodes.Call, typeof(string).GetProperty("Length")!.GetGetMethod()!);
// bytes
il.Emit(OpCodes.Ldloc, bytes);
// bytelength
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.BizInvoke/BizInvokerUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private class CF
/// </summary>
/// <returns></returns>
public static int ComputeClassFirstFieldOffset()
=> ComputeFieldOffset(typeof(CF).GetField("FirstField"));
=> ComputeFieldOffset(typeof(CF).GetField("FirstField")!);

/// <summary>
/// Compute the byte offset of the first byte of string data (UTF16) relative to a pointer to the string.
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.BizInvoke/CallingConventionAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ private class WaterboxAdapter : ICallingConventionAdapter
{
private class ReferenceEqualityComparer : IEqualityComparer<Delegate>
{
public bool Equals(Delegate x, Delegate y)
public bool Equals(Delegate? x, Delegate? y)
=> x == y;

public int GetHashCode(Delegate obj)
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Audio/BizHawk.Bizware.Audio.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>disable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Bizware.Graphics/BizHawk.Bizware.Graphics.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Bizware.Input/BizHawk.Bizware.Input.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netstandard2.0;net8.0</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/Classes/CommApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public sealed class CommApi : ICommApi

public string? HttpTest() => HTTP == null ? null : string.Join("\n", HttpTestGet(), HTTP.SendScreenshot(), "done testing");

public string? HttpTestGet() => HTTP?.Get(HTTP.GetUrl)?.Result;
public string? HttpTestGet() => HttpCommunication.Get(HTTP?.GetUrl)?.Result;
}
}
8 changes: 4 additions & 4 deletions src/BizHawk.Client.Common/Api/ClientWebSocketWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public Task Close(WebSocketCloseStatus closeStatus, string statusDescription, Ca
return task;
}

/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync"/></summary>
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync(System.ArraySegment{byte}, CancellationToken)"/></summary>
public Task<WebSocketReceiveResult> Receive(ArraySegment<byte> buffer, CancellationToken? cancellationToken = null)
=> _w?.ReceiveAsync(buffer, cancellationToken ?? CancellationToken.None)
?? throw new ObjectDisposedException(nameof(_w));

/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync"/></summary>
/// <summary>calls <see cref="ClientWebSocket.ReceiveAsync(System.ArraySegment{byte}, CancellationToken)"/></summary>
public string Receive(int bufferCap, CancellationToken? cancellationToken = null)
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
Expand All @@ -46,12 +46,12 @@ public string Receive(int bufferCap, CancellationToken? cancellationToken = null
return Encoding.UTF8.GetString(buffer, 0, result.Count);
}

/// <summary>calls <see cref="ClientWebSocket.SendAsync"/></summary>
/// <summary>calls <see cref="ClientWebSocket.SendAsync(System.ArraySegment{byte}, WebSocketMessageType, bool, CancellationToken)"/></summary>
public Task Send(ArraySegment<byte> buffer, WebSocketMessageType messageType, bool endOfMessage, CancellationToken? cancellationToken = null)
=> _w?.SendAsync(buffer, messageType, endOfMessage, cancellationToken ?? CancellationToken.None)
?? throw new ObjectDisposedException(nameof(_w));

/// <summary>calls <see cref="ClientWebSocket.SendAsync"/></summary>
/// <summary>calls <see cref="ClientWebSocket.SendAsync(System.ArraySegment{byte}, WebSocketMessageType, bool, CancellationToken)"/></summary>
public Task Send(string message, bool endOfMessage, CancellationToken? cancellationToken = null)
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/Api/DisplaySurfaceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum DisplaySurfaceID : int
public static class DisplaySurfaceIDParser
{
#pragma warning disable BHI1005 // switching on string, possibly from user input, ArgumentException is correct here
[return: NotNullIfNotNull("str")]
[return: NotNullIfNotNull(nameof(str))]
public static DisplaySurfaceID? Parse(string? str) => str?.ToLowerInvariant() switch
{
null => null, // this makes it easy to cascade the "remembered" value
Expand Down
16 changes: 8 additions & 8 deletions src/BizHawk.Client.Common/Api/HttpCommunication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace BizHawk.Client.Common
{
public sealed class HttpCommunication
{
private readonly HttpClient _client = new HttpClient();
public static readonly HttpClient Client = new HttpClient();

private readonly Func<byte[]> _takeScreenshotCallback;

Expand All @@ -33,24 +33,24 @@ public string ExecPost(string url = null, string payload = "") => Post(
new FormUrlEncodedContent(new Dictionary<string, string> { ["payload"] = payload })
).Result;

public async Task<string> Get(string url)
public static async Task<string> Get(string url)
{
_client.DefaultRequestHeaders.ConnectionClose = false;
var response = await _client.GetAsync(url).ConfigureAwait(false);
Client.DefaultRequestHeaders.ConnectionClose = false;
var response = await Client.GetAsync(url).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
return await response.Content.ReadAsStringAsync();
}
return null;
}

public async Task<string> Post(string url, FormUrlEncodedContent content)
public static async Task<string> Post(string url, FormUrlEncodedContent content)
{
_client.DefaultRequestHeaders.ConnectionClose = true;
Client.DefaultRequestHeaders.ConnectionClose = true;
HttpResponseMessage response;
try
{
response = await _client.PostAsync(url, content).ConfigureAwait(false);
response = await Client.PostAsync(url, content).ConfigureAwait(false);
}
catch (Exception e)
{
Expand Down Expand Up @@ -87,7 +87,7 @@ public void SetTimeout(int timeout)

if (timeout != 0)
{
_client.Timeout = new TimeSpan(0, 0, 0, timeout / 1000, timeout % 1000);
Client.Timeout = new TimeSpan(0, 0, 0, timeout / 1000, timeout % 1000);
Timeout = timeout;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/BizHawk.Client.Common/BizHawk.Client.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework><!-- some NuGet packages aren't for Standard, and are only loaded at runtime because EmuHawk is still Framework. More work will be required to move to Core. -->
<TargetFrameworks>netstandard2.0;net8.0-windows</TargetFrameworks><!-- some NuGet packages aren't for Standard, and are only loaded at runtime because EmuHawk is still Framework. More work will be required to move to Core. -->
</PropertyGroup>
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/BizHawk.Client.Common/rewind/ZeldaWinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ private void MaybeResize(int requestedSize)
_dest = replacement;
}
}
#if NET6_0_OR_GREATER
public override void Write(ReadOnlySpan<byte> buffer)
#else
public void Write(ReadOnlySpan<byte> buffer)
#endif
{
var requestedSize = _position + buffer.Length;
MaybeResize(requestedSize);
Expand All @@ -305,7 +309,11 @@ public override void WriteByte(byte value)
_dest[_position] = value;
_position = requestedSize;
}
#if NET6_0_OR_GREATER
public override int Read(Span<byte> buffer) => throw new IOException();
#else
public int Read(Span<byte> buffer) => throw new IOException();
#endif
}
}
}
18 changes: 17 additions & 1 deletion src/BizHawk.Client.Common/rewind/ZwinderBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private int ComputeIdealRewindInterval()
{
return 1; // shrug
}

if (_fixedRewindInterval)
{
return _targetRewindInterval;
Expand Down Expand Up @@ -438,14 +438,22 @@ public override void Flush() {}
public override int Read(byte[] buffer, int offset, int count) => throw new IOException();
public override long Seek(long offset, SeekOrigin origin) => throw new IOException();
public override void SetLength(long value) => throw new IOException();
#if NET6_0_OR_GREATER
public override int Read(Span<byte> buffer) => throw new IOException();
#else
public int Read(Span<byte> buffer) => throw new IOException();
#endif

public override void Write(byte[] buffer, int offset, int count)
{
Write(new ReadOnlySpan<byte>(buffer, offset, count));
}

#if NET6_0_OR_GREATER
public override void Write(ReadOnlySpan<byte> buffer)
#else
public void Write(ReadOnlySpan<byte> buffer)
#endif
{
long requestedSize = _position + buffer.Length;
while (requestedSize > _notifySize)
Expand Down Expand Up @@ -521,7 +529,11 @@ public override int Read(byte[] buffer, int offset, int count)
return Read(new Span<byte>(buffer, offset, count));
}

#if NET6_0_OR_GREATER
public override int Read(Span<byte> buffer)
#else
public int Read(Span<byte> buffer)
#endif
{
long n = Math.Min(_size - _position, buffer.Length);
int ret = (int)n;
Expand Down Expand Up @@ -572,7 +584,11 @@ public override int ReadByte()
public override void SetLength(long value) => throw new IOException();
public override void Write(byte[] buffer, int offset, int count) => throw new IOException();

#if NET6_0_OR_GREATER
public override void Write(ReadOnlySpan<byte> buffer) => throw new IOException();
#else
public void Write(ReadOnlySpan<byte> buffer) => throw new IOException();
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public void Insert(int index, Watch watch)
/// </param>
public void InsertRange(int index, IEnumerable<Watch> collection)
{
#if NET6_0
#if NET6_0_OR_GREATER
if (collection.TryGetNonEnumeratedCount(out var n) && n is 0) return;
#else
if (collection is ICollection<Watch> hasCount && hasCount.Count is 0) return;
Expand Down
11 changes: 3 additions & 8 deletions src/BizHawk.Client.DiscoHawk/BizHawk.Client.DiscoHawk.csproj
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnExecutable.props" />
<PropertyGroup>
<ApplicationIcon>discohawk.ico</ApplicationIcon>
<Nullable>disable</Nullable>
<UseWindowsForms>true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Windows.Forms" />
<ProjectReference Include="$(ProjectDir)../BizHawk.Emulation.DiscSystem/BizHawk.Emulation.DiscSystem.csproj" />
<Content Include="discohawk.ico" />
<EmbeddedResource Include="discohawk.ico" />
</ItemGroup>
<ItemGroup>
<Compile Update="About.cs" SubType="Form" />
<Compile Update="About.Designer.cs" DependentUpon="About.cs" />
<EmbeddedResource Update="About.resx" DependentUpon="About.cs" />
<Compile Update="ComparisonResults.cs" SubType="Form" />
<Compile Update="ComparisonResults.Designer.cs" DependentUpon="ComparisonResults.cs" />
<EmbeddedResource Update="ComparisonResults.resx" DependentUpon="ComparisonResults.cs" />
<Compile Update="MainDiscoForm.cs" SubType="Form" />
<Compile Update="MainDiscoForm.Designer.cs" DependentUpon="MainDiscoForm.cs" />
<EmbeddedResource Update="MainDiscoForm.resx" DependentUpon="MainDiscoForm.cs" SubType="Designer" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion src/BizHawk.Client.EmuHawk/AVOut/FFmpegDownloaderForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,3 @@ private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs
}
}
}

7 changes: 4 additions & 3 deletions src/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<TargetFrameworks>net48;net8.0-windows</TargetFrameworks>
</PropertyGroup>
<Import Project="../MainSlnExecutable.props" />
<PropertyGroup>
Expand All @@ -9,11 +9,12 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<Nullable>disable</Nullable>
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
<UseWindowsForms>true</UseWindowsForms>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.IO.Compression" />
<Reference Condition="$(IsTargetingNetFramework)" Include="System.IO.Compression" />
</ItemGroup>
<ItemGroup>
<Reference Include="PcxFileTypePlugin.HawkQuantizer" HintPath="$(ProjectDir)../../References/PcxFileTypePlugin.HawkQuantizer.dll" Private="true" />
Expand Down
2 changes: 2 additions & 0 deletions src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public static void PopulateFromEnum<T>(this ComboBox box, T enumVal)
box.SelectedItem = enumVal.GetDescription();
}

#if !NET6_0_OR_GREATER
/// <summary>extension method to make <see cref="Control.Invoke(Delegate)"/> easier to use</summary>
public static void Invoke(this Control control, Action action)
=> control.Invoke(action);

/// <summary>extension method to make <see cref="Control.BeginInvoke(Delegate)"/> easier to use</summary>
public static void BeginInvoke(this Control control, Action action)
=> control.BeginInvoke(action);
#endif

public static ToolStripMenuItem ToColumnsMenu(this InputRoll inputRoll, Action changeCallback)
{
Expand Down
Loading