Skip to content

Commit af579b1

Browse files
DrSmugleafPJB3005
andauthored
Update to .NET 6 and C# 10 (space-wizards#5233)
Co-authored-by: Pieter-Jan Briers <[email protected]>
1 parent 29f3d2d commit af579b1

File tree

23 files changed

+63
-43
lines changed

23 files changed

+63
-43
lines changed

.github/workflows/build-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Setup .NET Core
4343
uses: actions/setup-dotnet@v1
4444
with:
45-
dotnet-version: 5.0.100
45+
dotnet-version: 6.0.100
4646
- name: Install dependencies
4747
run: dotnet restore
4848
- name: Build

.github/workflows/yaml-linter.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET Core
2020
uses: actions/setup-dotnet@v1
2121
with:
22-
dotnet-version: 5.0.100
22+
dotnet-version: 6.0.100
2323
- name: Install dependencies
2424
run: dotnet restore
2525
- name: Build

Content.Benchmarks/Content.Benchmarks.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputType>Exe</OutputType>
1010
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
11-
<LangVersion>9</LangVersion>
11+
<LangVersion>10</LangVersion>
1212
</PropertyGroup>
1313
<ItemGroup>
1414
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />

Content.Client/Content.Client.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
55
<TargetFramework>$(TargetFramework)</TargetFramework>
6-
<LangVersion>9</LangVersion>
6+
<LangVersion>10</LangVersion>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputPath>..\bin\Content.Client\</OutputPath>

Content.IntegrationTests/Content.IntegrationTests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<OutputPath>..\bin\Content.IntegrationTests\</OutputPath>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
9-
<LangVersion>9</LangVersion>
9+
<LangVersion>10</LangVersion>
1010
</PropertyGroup>
1111
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
1212
<ItemGroup>

Content.IntegrationTests/Tests/GameObjects/Components/ActionBlocking/HandCuffTest.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ public async Task Test()
6868
// Test for components existing
6969
Assert.True(human.TryGetComponent(out cuffed!), $"Human has no {nameof(CuffableComponent)}");
7070
Assert.True(human.TryGetComponent(out hands!), $"Human has no {nameof(HandsComponent)}");
71-
Assert.True(human.TryGetComponent(out SharedBodyComponent _), $"Human has no {nameof(SharedBodyComponent)}");
72-
Assert.True(cuffs.TryGetComponent(out HandcuffComponent _), $"Handcuff has no {nameof(HandcuffComponent)}");
73-
Assert.True(secondCuffs.TryGetComponent(out HandcuffComponent _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
71+
Assert.True(human.TryGetComponent(out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}");
72+
Assert.True(cuffs.TryGetComponent(out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
73+
Assert.True(secondCuffs.TryGetComponent(out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
7474

7575
// Test to ensure cuffed players register the handcuffs
7676
cuffed.TryAddNewCuffs(human, cuffs);

Content.IntegrationTests/Tests/GameObjects/Components/Movement/ClimbUnitTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public async Task Test()
5555
// Test for climb components existing
5656
// Players and tables should have these in their prototypes.
5757
Assert.That(human.TryGetComponent(out climbing!), "Human has no climbing");
58-
Assert.That(table.TryGetComponent(out ClimbableComponent _), "Table has no climbable");
58+
Assert.That(table.TryGetComponent(out ClimbableComponent? _), "Table has no climbable");
5959

6060
// Now let's make the player enter a climbing transitioning state.
6161
climbing.IsClimbing = true;

Content.Server.Database/Content.Server.Database.csproj

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
55
<TargetFramework>$(TargetFramework)</TargetFramework>
6-
<LangVersion>9</LangVersion>
6+
<LangVersion>10</LangVersion>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputPath>..\bin\Content.Server.Database\</OutputPath>
@@ -13,12 +13,12 @@
1313
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
1414

1515
<ItemGroup>
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
1717
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1818
<PrivateAssets>all</PrivateAssets>
1919
</PackageReference>
20-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" />
21-
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
20+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
21+
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
2222
</ItemGroup>
2323
<Import Project="..\RobustToolbox\MSBuild\Robust.Analyzers.targets" />
2424
</Project>

Content.Server.Database/ModelPostgres.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel.DataAnnotations.Schema;
33
using System.Net;
44
using Microsoft.EntityFrameworkCore;
5+
using Microsoft.EntityFrameworkCore.Diagnostics;
56
using Microsoft.EntityFrameworkCore.Infrastructure;
67
using Microsoft.EntityFrameworkCore.Storage;
78

@@ -28,6 +29,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder options)
2829
options.ReplaceService<IRelationalTypeMappingSource, CustomNpgsqlTypeMappingSource>();
2930

3031
((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());
32+
33+
options.ConfigureWarnings(x =>
34+
{
35+
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
36+
});
3137
}
3238

3339
public PostgresServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
@@ -82,7 +88,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
8288
{
8389
foreach(var property in entity.GetProperties())
8490
{
85-
if (property.FieldInfo.FieldType == typeof(DateTime) || property.FieldInfo.FieldType == typeof(DateTime?))
91+
if (property.FieldInfo?.FieldType == typeof(DateTime) || property.FieldInfo?.FieldType == typeof(DateTime?))
8692
property.SetColumnType("timestamp with time zone");
8793
}
8894
}

Content.Server.Database/ModelSqlite.cs

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Globalization;
44
using System.Net;
55
using Microsoft.EntityFrameworkCore;
6+
using Microsoft.EntityFrameworkCore.Diagnostics;
67
using Microsoft.EntityFrameworkCore.Infrastructure;
78
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
89

@@ -25,6 +26,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder options)
2526
options.UseSqlite("dummy connection string");
2627

2728
((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());
29+
30+
options.ConfigureWarnings(x =>
31+
{
32+
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
33+
});
2834
}
2935

3036
protected override void OnModelCreating(ModelBuilder modelBuilder)

Content.Server.Database/SnakeCaseNaming.cs

+16-11
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@ public ExtensionInfo(IDbContextOptionsExtension extension) : base(extension) {}
3333

3434
public override string LogFragment => "Snake Case Extension";
3535

36-
public override long GetServiceProviderHashCode() => 0;
36+
public override int GetServiceProviderHashCode() => 0;
37+
38+
public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
39+
{
40+
return false;
41+
}
3742

3843
public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
3944
{
@@ -118,26 +123,26 @@ public virtual void ProcessEntityTypeAdded(
118123

119124
if (entityType.BaseType is null)
120125
{
121-
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema());
126+
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());
122127

123128
if (entityType.GetViewNameConfigurationSource() == ConfigurationSource.Convention)
124129
{
125-
entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()), entityType.GetViewSchema());
130+
entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()!), entityType.GetViewSchema());
126131
}
127132
}
128133
}
129134

130135
public void ProcessEntityTypeBaseTypeChanged(
131136
IConventionEntityTypeBuilder entityTypeBuilder,
132-
IConventionEntityType newBaseType,
133-
IConventionEntityType oldBaseType,
137+
IConventionEntityType? newBaseType,
138+
IConventionEntityType? oldBaseType,
134139
IConventionContext<IConventionEntityType> context)
135140
{
136141
var entityType = entityTypeBuilder.Metadata;
137142

138143
if (newBaseType is null)
139144
{
140-
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema());
145+
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());
141146
}
142147
else
143148
{
@@ -173,8 +178,8 @@ public void ProcessForeignKeyOwnershipChanged(IConventionForeignKeyBuilder relat
173178
public void ProcessEntityTypeAnnotationChanged(
174179
IConventionEntityTypeBuilder entityTypeBuilder,
175180
string name,
176-
IConventionAnnotation annotation,
177-
IConventionAnnotation oldAnnotation,
181+
IConventionAnnotation? annotation,
182+
IConventionAnnotation? oldAnnotation,
178183
IConventionContext<IConventionAnnotation> context)
179184
{
180185
var entityType = entityTypeBuilder.Metadata;
@@ -216,7 +221,7 @@ public void ProcessEntityTypeAnnotationChanged(
216221
&& (string)annotation.Value != ownership.PrincipalEntityType.GetTableName())
217222
{
218223
foreach (var property in entityType.GetProperties()
219-
.Except(entityType.FindPrimaryKey().Properties)
224+
.Except(entityType.FindPrimaryKey()!.Properties)
220225
.Where(p => p.Builder.CanSetColumnName(null)))
221226
{
222227
RewriteColumnName(property.Builder);
@@ -271,7 +276,7 @@ public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConven
271276

272277
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
273278
{
274-
columnName = property.GetColumnName(identifier.Value);
279+
columnName = property.GetColumnName(identifier.Value)!;
275280
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
276281
{
277282
property.Builder.HasColumnName(
@@ -314,7 +319,7 @@ private void RewriteColumnName(IConventionPropertyBuilder propertyBuilder)
314319
if (name == "Id")
315320
name = entityType.GetTableName() + name;
316321
propertyBuilder.HasColumnName(
317-
RewriteName(name), identifier.Value);
322+
RewriteName(name!), identifier.Value);
318323
}
319324
}
320325
}

Content.Server/Chemistry/Components/FoamSolutionAreaEffectComponent.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Content.Server.Chemistry.EntitySystems;
33
using Content.Server.Inventory.Components;
44
using Content.Server.Items;
5-
using Content.Shared.Chemistry.Reagent;
65
using Content.Shared.FixedPoint;
76
using Content.Shared.Foam;
87
using Content.Shared.Inventory;
@@ -51,7 +50,7 @@ protected override void ReactWithEntity(IEntity entity, double solutionFraction)
5150
slot == EquipmentSlotDefines.Slots.IDCARD)
5251
continue;
5352

54-
if (inventory.TryGetSlotItem(slot, out ItemComponent _))
53+
if (inventory.TryGetSlotItem(slot, out ItemComponent? _))
5554
protection += 0.025f;
5655
}
5756
}

Content.Server/Content.Server.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
55
<TargetFramework>$(TargetFramework)</TargetFramework>
6-
<LangVersion>9</LangVersion>
6+
<LangVersion>10</LangVersion>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputPath>..\bin\Content.Server\</OutputPath>

Content.Server/Database/ServerDbBase.cs

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ private static async Task DeleteCharacterSlot(ServerDbContext db, NetUserId user
9393
.Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot)
9494
.SingleOrDefaultAsync();
9595

96+
if (profile == null)
97+
{
98+
return;
99+
}
100+
96101
db.Profile.Remove(profile);
97102
}
98103

Content.Server/Database/ServerDbManager.cs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Net;
66
using System.Threading;
77
using System.Threading.Tasks;
8-
using Content.Shared;
98
using Content.Shared.CCVar;
109
using Content.Shared.Preferences;
1110
using Microsoft.Data.Sqlite;
@@ -382,8 +381,8 @@ public MSLogger(ISawmill sawmill)
382381
_sawmill = sawmill;
383382
}
384383

385-
public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception exception,
386-
Func<TState, Exception, string> formatter)
384+
public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception? exception,
385+
Func<TState, Exception?, string> formatter)
387386
{
388387
var lvl = logLevel switch
389388
{

Content.Server/Inventory/InventoryHelpers.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static bool SpawnItemInSlot(this InventoryComponent inventory, Slots slot
1919
return false;
2020

2121
// If we don't have that slot or there's already an item there, we do nothing.
22-
if (!inventory.HasSlot(slot) || inventory.TryGetSlotItem(slot, out ItemComponent _))
22+
if (!inventory.HasSlot(slot) || inventory.TryGetSlotItem(slot, out ItemComponent? _))
2323
return false;
2424

2525
// If the prototype in question doesn't exist, we do nothing.

Content.Server/Strip/StrippableComponent.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ bool Check()
178178
if (!inventory.HasSlot(slot))
179179
return false;
180180

181-
if (inventory.TryGetSlotItem(slot, out ItemComponent _))
181+
if (inventory.TryGetSlotItem(slot, out ItemComponent? _))
182182
{
183183
user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied",("owner", Owner)));
184184
return false;
@@ -403,7 +403,7 @@ private void HandleUserInterfaceMessage(ServerBoundUserInterfaceMessage obj)
403403

404404
if (Owner.TryGetComponent<InventoryComponent>(out var inventory))
405405
{
406-
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent _))
406+
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent? _))
407407
placingItem = false;
408408

409409
if (placingItem)

Content.Shared/Content.Shared.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
55
<TargetFramework>$(TargetFramework)</TargetFramework>
6-
<LangVersion>9</LangVersion>
6+
<LangVersion>10</LangVersion>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<Configurations>Release;Debug</Configurations>

Content.Tests/Content.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
55
<TargetFramework>$(TargetFramework)</TargetFramework>
6-
<LangVersion>9</LangVersion>
6+
<LangVersion>10</LangVersion>
77
<IsPackable>false</IsPackable>
88
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
99
<OutputPath>..\bin\Content.Tests\</OutputPath>

Content.Tools/Content.Tools.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>$(TargetFramework)</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>

Content.YAMLLinter/Content.YAMLLinter.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>$(TargetFramework)</TargetFramework>
66
<OutputPath>..\bin\Content.YAMLLinter\</OutputPath>
77
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
88
</PropertyGroup>

Pow3r/Pow3r.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
5+
<TargetFramework>$(TargetFramework)</TargetFramework>
66
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
77
</PropertyGroup>
88

0 commit comments

Comments
 (0)