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

feat: Updates to .NET 9 #1984

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"modernuoschemagenerator": {
"version": "2.11.3",
"version": "2.12.5",
"commands": [
"ModernUOSchemaGenerator"
]
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET 8
- name: Install .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
global-json-file: global.json
- name: Install Prerequisites
run: |
brew update
Expand Down Expand Up @@ -86,10 +86,10 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
- name: Setup .NET 8
- name: Install .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
global-json-file: global.json
- name: Build
run: ./publish.cmd Release
- name: Test
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:
with:
fetch-depth: 0 # avoid shallow clone so nbgv can do its work.
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Setup .NET 8
- name: Install .NET 9
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
global-json-file: global.json
- name: Install NGBV
uses: dotnet/nbgv@master
id: nbgv
Expand Down
8 changes: 4 additions & 4 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Authors>Kamron Batman</Authors>
<Company>ModernUO</Company>
<Copyright>2019-2023</Copyright>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>12</LangVersion>
<PublicRelease>true</PublicRelease>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand Down Expand Up @@ -62,11 +62,11 @@
<AnalysisLevel>latest</AnalysisLevel>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.0.0" />
<PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.Async" Version="2.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Nerdbank.GitVersioning" Condition="!Exists('packages.config')">
<Version>3.6.143</Version>
<Version>3.6.146</Version>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<AdditionalFiles Include="..\..\Rules.ruleset" />
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Client/ArtData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Rectangle2D GetStaticBounds(int index)

Span<ushort> buffer = stackalloc ushort[entry.Size / 2];
_dataStream.Seek(entry.Offset, SeekOrigin.Begin);
_dataStream.Read(MemoryMarshal.AsBytes(buffer));
_ = _dataStream.Read(MemoryMarshal.AsBytes(buffer));

var width = buffer[2];
var height = buffer[3];
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Client/UOClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static ClientVersion DetectClassicClient()
{
using FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
var buffer = GC.AllocateUninitializedArray<byte>((int)fs.Length, true);
fs.Read(buffer);
_ = fs.Read(buffer);
// VS_VERSION_INFO (unicode)
Span<byte> vsVersionInfo = stackalloc byte[]
{
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3077,7 +3077,7 @@ public virtual void SendOPLPacketTo(NetState ns)

public virtual void SendWorldPacketTo(NetState ns, ReadOnlySpan<byte> world = default)
{
if (world != null)
if (world != ReadOnlySpan<byte>.Empty)
{
ns?.Send(world);
return;
Expand Down
4 changes: 2 additions & 2 deletions Projects/Server/Localization/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private static Dictionary<int, LocalizationEntry> LoadClilocs(string lang, strin
{
using var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
Span<byte> header = stackalloc byte[6];
fs.Read(header);
_ = fs.Read(header);

byte[] data;
BufferReader br;
Expand All @@ -120,7 +120,7 @@ private static Dictionary<int, LocalizationEntry> LoadClilocs(string lang, strin
else
{
data = GC.AllocateUninitializedArray<byte>((int)fs.Length - 6);
fs.Read(data);
_ = fs.Read(data);
br = new BufferReader(data);
}

Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Network/NetState/NetState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public bool GetSendBuffer(out Span<byte> buffer)

public void Send(ReadOnlySpan<byte> span)
{
if (span == null || this.CannotSendPackets())
if (span == ReadOnlySpan<byte>.Empty || this.CannotSendPackets())
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Serial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public string ToString(string format, IFormatProvider formatProvider)

public bool TryFormat(
Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider provider
) => format != null
) => format != ReadOnlySpan<char>.Empty
? Value.TryFormat(destination, out charsWritten, format, provider)
: destination.TryWrite(provider, $"0x{Value:X8}", out charsWritten);

Expand Down
6 changes: 3 additions & 3 deletions Projects/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
<ItemGroup>
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.3.2" />
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
<PackageReference Include="PollGroup" Version="1.5.1" />
<PackageReference Include="System.IO.Hashing" Version="8.0.0" />
<PackageReference Include="PollGroup" Version="1.6.1" />
<PackageReference Include="System.IO.Hashing" Version="9.0.0" />

<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.9.1" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.11.3" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.12.1" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Migrations/*.v*.json" />
Expand Down
4 changes: 2 additions & 2 deletions Projects/Server/Text/StringHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ out int size
)
{
size = 0;
if (a == null || a.Length == 0)
if (a == ReadOnlySpan<char>.Empty || a.Length == 0)
{
return;
}
Expand Down Expand Up @@ -72,7 +72,7 @@ out int size
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Remove(this ReadOnlySpan<char> a, ReadOnlySpan<char> b, StringComparison comparison)
{
if (a == null)
if (a == ReadOnlySpan<char>.Empty)
{
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/Server/TileMatrix/TileMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ private unsafe StaticTile[][][] ReadStaticBlock(int x, int y)

fixed (StaticTile* pTiles = staTiles)
{
DataStream.Read(new Span<byte>(pTiles, length));
_ = DataStream.Read(new Span<byte>(pTiles, length));

if (m_Lists == null)
{
Expand Down Expand Up @@ -423,7 +423,7 @@ private unsafe LandTile[] ReadLandBlock(int x, int y)

fixed (LandTile* pTiles = tiles)
{
MapStream.Read(new Span<byte>(pTiles, 192));
_ = MapStream.Read(new Span<byte>(pTiles, 192));
}

return tiles;
Expand Down
4 changes: 2 additions & 2 deletions Projects/Server/TileMatrix/TileMatrixPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private unsafe int PatchLand(TileMatrix matrix, string dataPath, string indexPat
var tiles = new LandTile[64];
fixed (LandTile* pTiles = tiles)
{
fsData.Read(new Span<byte>(pTiles, 192));
_ = fsData.Read(new Span<byte>(pTiles, 192));
}

matrix.SetLandBlock(x, y, tiles);
Expand Down Expand Up @@ -149,7 +149,7 @@ private unsafe int PatchStatics(TileMatrix matrix, string dataPath, string index

fixed (StaticTile* pTiles = staTiles)
{
fsData.Read(new Span<byte>(pTiles, length));
_ = fsData.Read(new Span<byte>(pTiles, length));

StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;

Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Utilities/HashUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static ulong ComputeHash64(ReadOnlySpan<char> str)

public static uint ComputeHash32(ReadOnlySpan<char> str)
{
if (str == null)
if (str == ReadOnlySpan<char>.Empty)
{
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion Projects/UOContent/Special Systems/Engines/TestCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private static void EventSink_Speech(SpeechEventArgs args)

var name = tokenizer.MoveNext() ? tokenizer.Current : null;
var valueStr = tokenizer.MoveNext() ? tokenizer.Current : null;
if (valueStr == null)
if (valueStr == ReadOnlySpan<char>.Empty)
{
return;
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/UOContent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
</ProjectReference>
<PackageReference Include="LibDeflate.Bindings" Version="1.0.2.120" />
<PackageReference Include="MailKit" Version="4.8.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.FileSystemGlobbing" Version="9.0.0" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.3.2" />
<PackageReference Include="Argon2.Bindings" Version="1.16.1" />
<PackageReference Include="ModernUO.CodeGeneratedEvents.Annotations" Version="1.0.0" />
<PackageReference Include="ModernUO.CodeGeneratedEvents.Generator" Version="1.0.3.2" PrivateAssets="all" />
<PackageReference Include="Zstd.Binaries" Version="1.6.0" />

<PackageReference Include="ModernUO.Serialization.Annotations" Version="2.9.1" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.11.3" />
<PackageReference Include="ModernUO.Serialization.Generator" Version="2.12.1" />
</ItemGroup>
<ItemGroup>
<AdditionalFiles Include="Migrations/*.v*.json" />
Expand Down
17 changes: 9 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ trigger:

variables:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT: 1

jobs:
- job: BuildWindows
Expand All @@ -15,14 +14,16 @@ jobs:

steps:
- task: UseDotNet@2
displayName: 'Install .NET 8'
displayName: 'Install .NET 9'
inputs:
packageType: sdk
version: '8.0.x'
useGlobalJson: true
- task: NuGetAuthenticate@1
- script: ./publish.cmd Release
displayName: 'Build'
- powershell: ./.github/porcelain.ps1
displayName: Migration Changes
- script: dotnet test --no-restore
displayName: 'Test'
continueOnError: true
- publish: ./procDump
artifact: procDump
# - powershell: ./.github/porcelain.ps1
# displayName: Migration Changes
# - script: dotnet test --no-restore
# displayName: 'Test'
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.0",
"version": "9.0.100",
"rollForward": "latestMajor",
"allowPrerelease": false
}
Expand Down
93 changes: 93 additions & 0 deletions procDump.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
param (
[Parameter(Mandatory=$true)][string]$procDumpFolder
)

function Unzip([string]$zipfile, [string]$outpath) {
Add-Type -AssemblyName System.IO.Compression.FileSystem
[System.IO.Compression.ZipFile]::ExtractToDirectory($zipfile, $outpath)
}

function New-Directory([string[]] $path) {
New-Item -Path $path -Force -ItemType 'Directory' | Out-Null
}

function Run-Process([string]$fileName, [string]$arguments) {
$processInfo = New-Object System.Diagnostics.ProcessStartInfo
$processInfo.FileName = $fileName
$processInfo.RedirectStandardError = $true
$processInfo.RedirectStandardOutput = $true
$processInfo.UseShellExecute = $false
$processInfo.Arguments = $arguments
$processInfo.WorkingDirectory = $PSScriptRoot
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $processInfo

$OutEvent = Register-ObjectEvent -Action {
Write-Host $Event.SourceEventArgs.Data
} -InputObject $process -EventName OutputDataReceived

$ErrEvent = Register-ObjectEvent -Action {
Write-Host $Event.SourceEventArgs.Data
} -InputObject $process -EventName ErrorDataReceived

$process.Start() | Out-Null

$process.BeginOutputReadLine()
$process.BeginErrorReadLine()

return $process
}

Write-Host "Procdump folder: $procDumpFolder"

$filePath = Join-Path $procDumpFolder "procdump.exe"
if (-not (Test-Path $filePath)) {
Write-Host "Downloading procdump"
New-Directory $procDumpFolder
$zipFilePath = Join-Path $procDumpFolder "procdump.zip"
Invoke-WebRequest "https://download.sysinternals.com/files/Procdump.zip" -UseBasicParsing -outfile $zipFilePath | Out-Null
Unzip $zipFilePath $procDumpFolder
}

Write-Host "Running schema generator"
#$process = Start-Process -FilePath "dotnet.exe" -PassThru -ArgumentList "tool run ModernUOSchemaGenerator -- ModernUO.sln"
$toolProcess = Run-Process "dotnet.exe" "tool run ModernUOSchemaGenerator -- ModernUO.sln"

$dumpProcesses = @()
$startTime = Get-Date
while (-not $toolProcess.HasExited) {

# break after 1 minute as the tool process will likely never exit
$currentTime = Get-Date
$elapsedTime = $currentTime - $startTime

if ($elapsedTime.TotalMinutes -ge 1) {
Write-Host "Ending, 1 minute has passed."
break
}

$commandLines = Get-CimInstance Win32_Process | Select-Object ProcessId, Name, CommandLine
foreach ($commandLine in $commandLines) {
if ($dumpProcesses -contains $commandLine.ProcessId) {
continue
}

if ($commandLine.CommandLine -like "*ModernUOSchemaGenerator.dll*") {
$dumpProcesses += $commandLine.ProcessId
Write-Host "Attaching to tool process: $($commandLine.ProcessId), Name: $($commandLine.Name), CommandLine: $($commandLine.CommandLine)"
$dmp = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -s 5 -n 5 $($commandLine.ProcessId) $procDumpFolder\Tool_PROCESSNAME_YYMMDD_HHMMSS.dmp"

}
if ($commandLine.CommandLine -like "*Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll*") {
$dumpProcesses += $commandLine.ProcessId
Write-Host "Attaching to build host process: $($commandLine.ProcessId), Name: $($commandLine.Name), CommandLine: $($commandLine.CommandLine)"
$dmp = Run-Process "$procDumpFolder\procdump.exe" "-accepteula -ma -s 5 -n 5 $($commandLine.ProcessId) $procDumpFolder\BuildHost_PROCESSNAME_YYMMDD_HHMMSS.dmp "
}
}

Start-Sleep -Seconds 1
}

if (-not $toolProcess.HasExited) {
$toolProcess.Kill()
}
3 changes: 2 additions & 1 deletion publish.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ echo dotnet publish %config% %os%-%arch% --no-restore --self-contained=false
dotnet publish %config% %os%-%arch% --no-restore --self-contained=false

echo Generating serialization migration schema...
dotnet tool run ModernUOSchemaGenerator -- ModernUO.sln
powershell -ExecutionPolicy Bypass -File procDump.ps1 -procDumpFolder %~dp0procDump
::dotnet tool run ModernUOSchemaGenerator -- ModernUO.sln
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "0.13.6"
"version": "0.13.7"
}
Loading