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

Use .NET 9 #1061

Merged
merged 1 commit into from
Nov 17, 2024
Merged
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
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ csharp_preserve_single_line_statements = true
csharp_preserve_single_line_blocks = true
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_namespace_declarations = file_scoped:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_prefer_system_threading_lock = true:suggestion
###############################
# VB Coding Conventions #
###############################
Expand Down
17 changes: 15 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-3.0-only
<PropertyGroup>
<!-- Use the latest .NET SDK -->
<!-- This product requires Windows 10 (Windows Server 2019) or higher -->
<MainTargetFramework>net8.0-windows10.0.17763</MainTargetFramework>
<MainTargetFramework>net9.0-windows10.0.17763</MainTargetFramework>
</PropertyGroup>

<!-- Sane defaults; override in project where needed -->
Expand All @@ -32,7 +32,7 @@ SPDX-License-Identifier: GPL-3.0-only
<EnableWindowsTargeting>true</EnableWindowsTargeting>

<!-- Use the latest C# language standard -->
<LangVersion>12.0</LangVersion>
<LangVersion>13.0</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>

<!-- Be very strict -->
Expand All @@ -50,6 +50,11 @@ SPDX-License-Identifier: GPL-3.0-only
<IsPublishable>false</IsPublishable>
<GenerateDependencyFile>false</GenerateDependencyFile>
<AccelerateBuildsInVisualStudio>true</AccelerateBuildsInVisualStudio>
<!--
See https://github.com/dotnet/roslyn/issues/41640
-->
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>CS1591</NoWarn>

<!-- Deterministic builds -->
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
Expand All @@ -67,4 +72,12 @@ SPDX-License-Identifier: GPL-3.0-only
<Compile Include="$(MSBuildThisFileDirectory)Fake_GitVersionInformation.cs" Condition=" '$(MSBuildRuntimeType)' != 'Core' " />
</ItemGroup>

<PropertyGroup Condition=" '$(MSBuildRuntimeType)' != 'Core' ">
<GitVersion_FullSemVer>0.9.99+999</GitVersion_FullSemVer>
<GitVersion_MajorMinorPatch>0.9.99</GitVersion_MajorMinorPatch>
<GitVersion_Major>0</GitVersion_Major>
<GitVersion_Minor>9</GitVersion_Minor>
<GitVersion_Patch>99</GitVersion_Patch>
</PropertyGroup>

</Project>
4 changes: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ SPDX-License-Identifier: GPL-3.0-only
<!-- all -->
<PackageVersion Include="GitVersion.MsBuild" Version="6.0.5" />
<!-- Usbipd -->
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="8.0.1" />
<PackageVersion Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.0" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.106" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<!-- UsbIds -->
Expand All @@ -25,7 +25,7 @@ SPDX-License-Identifier: GPL-3.0-only
<PackageVersion Include="Moq" Version="4.20.72" />
<PackageVersion Include="MSTest.TestAdapter" Version="3.6.3" />
<PackageVersion Include="MSTest.TestFramework" Version="3.6.3" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />
<PackageVersion Include="System.IO.Pipelines" Version="9.0.0" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions Installer/Installer.wixproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ SPDX-License-Identifier: GPL-3.0-only
<PackageReference Include="WixToolset.UI.wixext" />
<PackageReference Include="WixToolset.Util.wixext" />
</ItemGroup>
<ItemGroup>
<Compile Remove="..\Fake_GitVersionInformation.cs" Condition=" '$(MSBuildRuntimeType)' != 'Core' " />
</ItemGroup>
<Target Name="SetTarget" AfterTargets="GetVersion">
<!--
Now that we have determined the version, augment the OutputName to include the version number.
Expand Down Expand Up @@ -48,6 +51,9 @@ SPDX-License-Identifier: GPL-3.0-only
<CreateProperty Value="$(DefineConstants);ProductCode=EA1D5623-E6A7-4E4A-9259-E39722$([System.Byte]::Parse($(GitVersion_Major)).ToString(X2))$([System.Byte]::Parse($(GitVersion_Minor)).ToString(X2))$([System.Byte]::Parse($(GitVersion_Patch)).ToString(X2))">
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>
<CreateProperty Value="$(DefineConstants);GitVersion_MajorMinorPatch=$(GitVersion_MajorMinorPatch)" Condition=" '$(MSBuildRuntimeType)' != 'Core' " >
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>
</Target>
<Target Name="PublishUsbipd" BeforeTargets="BeforeBuild">
<Message Importance="high" Text="Publishing pre-built usbipd-win" />
Expand Down
26 changes: 13 additions & 13 deletions UnitTests/Automation_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void Device_ClientIPAddress_Null()
public void JsonConverterBusId_Read_Valid()
{
var reader = new Utf8JsonReader("\"1-42\""u8);
reader.Read();
_ = reader.Read();

var converter = new JsonConverterBusId();
var busId = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
Expand All @@ -231,10 +231,10 @@ public void JsonConverterBusId_Read_Valid()
public void JsonConverterBusId_Read_Invalid()
{
var converter = new JsonConverterBusId();
Assert.ThrowsException<FormatException>(() =>
_ = Assert.ThrowsException<FormatException>(() =>
{
var reader = new Utf8JsonReader("\"xxx\""u8);
reader.Read();
_ = reader.Read();

_ = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
});
Expand All @@ -244,10 +244,10 @@ public void JsonConverterBusId_Read_Invalid()
public void JsonConverterBusId_Read_Null()
{
var converter = new JsonConverterBusId();
Assert.ThrowsException<InvalidDataException>(() =>
_ = Assert.ThrowsException<InvalidDataException>(() =>
{
var reader = new Utf8JsonReader("null"u8);
reader.Read();
_ = reader.Read();
var busId = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
});
}
Expand All @@ -269,7 +269,7 @@ public void JsonConverterBusId_Write_Valid()
public void JsonConverterBusId_Write_NullWriter()
{
var converter = new JsonConverterBusId();
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
converter.Write(null!, new(1, 42), JsonSerializerOptions.Default);
});
Expand All @@ -279,7 +279,7 @@ public void JsonConverterBusId_Write_NullWriter()
public void JsonConverterIPAddress_Read_Valid()
{
var reader = new Utf8JsonReader("\"1.2.3.4\""u8);
reader.Read();
_ = reader.Read();

var converter = new JsonConverterIPAddress();
var address = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
Expand All @@ -290,10 +290,10 @@ public void JsonConverterIPAddress_Read_Valid()
public void JsonConverterIPAddress_Read_Invalid()
{
var converter = new JsonConverterIPAddress();
Assert.ThrowsException<FormatException>(() =>
_ = Assert.ThrowsException<FormatException>(() =>
{
var reader = new Utf8JsonReader("\"xxx\""u8);
reader.Read();
_ = reader.Read();

_ = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
});
Expand All @@ -303,10 +303,10 @@ public void JsonConverterIPAddress_Read_Invalid()
public void JsonConverterIPAddress_Read_Null()
{
var converter = new JsonConverterIPAddress();
Assert.ThrowsException<InvalidDataException>(() =>
_ = Assert.ThrowsException<InvalidDataException>(() =>
{
var reader = new Utf8JsonReader("null"u8);
reader.Read();
_ = reader.Read();
var address = converter.Read(ref reader, typeof(string), JsonSerializerOptions.Default);
});
}
Expand All @@ -328,7 +328,7 @@ public void JsonConverterIPAddress_Write_Valid()
public void JsonConverterIPAddress_Write_NullWriter()
{
var converter = new JsonConverterIPAddress();
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
converter.Write(null!, IPAddress.Parse("1.2.3.4"), JsonSerializerOptions.Default);
});
Expand All @@ -340,7 +340,7 @@ public void JsonConverterIPAddress_Write_NullValue()
using var memoryStream = new MemoryStream();
using var writer = new Utf8JsonWriter(memoryStream, new() { SkipValidation = true });
var converter = new JsonConverterIPAddress();
Assert.ThrowsException<ArgumentNullException>(() =>
_ = Assert.ThrowsException<ArgumentNullException>(() =>
{
converter.Write(writer, null!, JsonSerializerOptions.Default);
});
Expand Down
37 changes: 21 additions & 16 deletions UnitTests/BusId_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void DefaultConstructor()
[TestMethod]
public void ConstructorWithInvalidBusThrows()
{
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
{
var busId = new BusId(0, 1);
});
Expand All @@ -31,7 +31,7 @@ public void ConstructorWithInvalidBusThrows()
[TestMethod]
public void ConstructorWithInvalidPortThrows()
{
Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
_ = Assert.ThrowsException<ArgumentOutOfRangeException>(() =>
{
var busId = new BusId(1, 0);
});
Expand All @@ -51,7 +51,7 @@ public void JsonConstructor()
}

[TestMethod]
public void ÍncompatibleHub()
public void IncompatibleHub()
{
Assert.AreEqual(0, BusId.IncompatibleHub.Bus);
Assert.AreEqual(0, BusId.IncompatibleHub.Port);
Expand Down Expand Up @@ -80,10 +80,7 @@ sealed class BusIdData
"1-01",
];

public static IEnumerable<string[]> Invalid
{
get => from value in _Invalid select new string[] { value };
}
public static IEnumerable<string[]> Invalid => from value in _Invalid select new string[] { value };

static readonly string[] _Valid = [
"IncompatibleHub",
Expand All @@ -107,19 +104,27 @@ public static IEnumerable<string[]> Invalid

public static IEnumerable<string[]> Valid => from value in _Valid select new string[] { value };

static int ExpectedCompare(string left, string right) =>
BusFromValidBusId(left) < BusFromValidBusId(right) ? -1 :
BusFromValidBusId(left) > BusFromValidBusId(right) ? 1 :
PortFromValidBusId(left) < PortFromValidBusId(right) ? -1 :
PortFromValidBusId(left) > PortFromValidBusId(right) ? 1 : 0;
static int ExpectedCompare(string left, string right)
{
return BusFromValidBusId(left) < BusFromValidBusId(right) ? -1
: BusFromValidBusId(left) > BusFromValidBusId(right) ? 1
: PortFromValidBusId(left) < PortFromValidBusId(right) ? -1
: PortFromValidBusId(left) > PortFromValidBusId(right) ? 1
: 0;
}

public static IEnumerable<object[]> Compare => from left in _Valid from right in _Valid select new object[] { left, right, ExpectedCompare(left, right) };
}

static ushort BusFromValidBusId(string text) => (text == "IncompatibleHub") ? (ushort)0 : ushort.Parse(text.Split('-')[0]);

static ushort PortFromValidBusId(string text) => (text == "IncompatibleHub") ? (ushort)0 : ushort.Parse(text.Split('-')[1]);
static ushort BusFromValidBusId(string text)
{
return (text == "IncompatibleHub") ? (ushort)0 : ushort.Parse(text.Split('-')[0]);
}

static ushort PortFromValidBusId(string text)
{
return (text == "IncompatibleHub") ? (ushort)0 : ushort.Parse(text.Split('-')[1]);
}

[TestMethod]
[DynamicData(nameof(BusIdData.Invalid), typeof(BusIdData))]
Expand All @@ -146,7 +151,7 @@ public void TryParseValid(string text)
[DynamicData(nameof(BusIdData.Invalid), typeof(BusIdData))]
public void ParseInvalid(string text)
{
Assert.ThrowsException<FormatException>(() =>
_ = Assert.ThrowsException<FormatException>(() =>
{
var busId = BusId.Parse(text);
});
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/ClientContext_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void Dispose()
{
var clientContext = new ClientContext();
((IDisposable)clientContext).Dispose();
Assert.ThrowsException<ObjectDisposedException>(() =>
_ = Assert.ThrowsException<ObjectDisposedException>(() =>
{
clientContext.TcpClient.Connect(IPAddress.Loopback, 1234);
});
Expand Down
5 changes: 1 addition & 4 deletions UnitTests/ConfigurationManagerException_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ sealed class MappingData
{ (CONFIGRET)0xbaadf00d, WIN32_ERROR.ERROR_CAN_NOT_COMPLETE }, // unknown error
};

public static IEnumerable<object[]> KnownGood
{
get => from value in _KnownGood select new object[] { value.Key, value.Value };
}
public static IEnumerable<object[]> KnownGood => from value in _KnownGood select new object[] { value.Key, value.Value };
}

[TestMethod]
Expand Down
8 changes: 4 additions & 4 deletions UnitTests/DeviceFile_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void Constructor_Success()
public void Constructor_FileNotFound()
{
using var temporaryFile = new TemporaryFile();
Assert.ThrowsException<Win32Exception>(() =>
_ = Assert.ThrowsException<Win32Exception>(() =>
{
using var deviceFile = new DeviceFile(temporaryFile.AbsolutePath);
});
Expand All @@ -35,7 +35,7 @@ public void Dispose()
using var temporaryFile = new TemporaryFile(true);
var deviceFile = new DeviceFile(temporaryFile.AbsolutePath);
deviceFile.Dispose();
Assert.ThrowsException<ObjectDisposedException>(() =>
_ = Assert.ThrowsException<ObjectDisposedException>(() =>
{
_ = deviceFile.DangerousGetHandle();
});
Expand Down Expand Up @@ -104,7 +104,7 @@ public void IoControlAsync_Win32Exception()
{
deviceFile.IoControlAsync(TEST_IOCTL.FSCTL_QUERY_ALLOCATED_RANGES, null, null).Wait();
});
Assert.IsInstanceOfType(exception.InnerException, typeof(Win32Exception));
Assert.IsInstanceOfType<Win32Exception>(exception.InnerException);
}

[TestMethod]
Expand All @@ -118,6 +118,6 @@ public void IoControlAsync_ProtocolViolation()
{
deviceFile.IoControlAsync(TEST_IOCTL.FSCTL_QUERY_ALLOCATED_RANGES, Tools.StructToBytes(rangeBuffer), outputBuffer).Wait();
});
Assert.IsInstanceOfType(exception.InnerException, typeof(ProtocolViolationException));
Assert.IsInstanceOfType<ProtocolViolationException>(exception.InnerException);
}
}
2 changes: 1 addition & 1 deletion UnitTests/ExportedDevice_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ sealed class ExportedDevice_Tests
DeviceProtocol: 0x67,
ConfigurationValue: 3,
NumConfigurations: 4,
Interfaces: new() { (1, 2, 3), (4, 5, 6) }
Interfaces: [(1, 2, 3), (4, 5, 6)]
);

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion UnitTests/GlobalFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sealed class GlobalFixture
public static void AssemblyInitialize(TestContext context)
{
_ = context;
Directory.CreateDirectory(TemporaryDirectory);
_ = Directory.CreateDirectory(TemporaryDirectory);
}

[AssemblyCleanup]
Expand Down
Loading