Skip to content

Commit

Permalink
Update to .NET 6 and C# 10 (#5233)
Browse files Browse the repository at this point in the history
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
  • Loading branch information
DrSmugleaf and PJB3005 authored Nov 9, 2021
1 parent 29f3d2d commit af579b1
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/yaml-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 5.0.100
dotnet-version: 6.0.100
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion Content.Benchmarks/Content.Benchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Content.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Client\</OutputPath>
Expand Down
2 changes: 1 addition & 1 deletion Content.IntegrationTests/Content.IntegrationTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<OutputPath>..\bin\Content.IntegrationTests\</OutputPath>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
</PropertyGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public async Task Test()
// Test for components existing
Assert.True(human.TryGetComponent(out cuffed!), $"Human has no {nameof(CuffableComponent)}");
Assert.True(human.TryGetComponent(out hands!), $"Human has no {nameof(HandsComponent)}");
Assert.True(human.TryGetComponent(out SharedBodyComponent _), $"Human has no {nameof(SharedBodyComponent)}");
Assert.True(cuffs.TryGetComponent(out HandcuffComponent _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(secondCuffs.TryGetComponent(out HandcuffComponent _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
Assert.True(human.TryGetComponent(out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}");
Assert.True(cuffs.TryGetComponent(out HandcuffComponent? _), $"Handcuff has no {nameof(HandcuffComponent)}");
Assert.True(secondCuffs.TryGetComponent(out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");

// Test to ensure cuffed players register the handcuffs
cuffed.TryAddNewCuffs(human, cuffs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public async Task Test()
// Test for climb components existing
// Players and tables should have these in their prototypes.
Assert.That(human.TryGetComponent(out climbing!), "Human has no climbing");
Assert.That(table.TryGetComponent(out ClimbableComponent _), "Table has no climbable");
Assert.That(table.TryGetComponent(out ClimbableComponent? _), "Table has no climbable");

// Now let's make the player enter a climbing transitioning state.
climbing.IsClimbing = true;
Expand Down
8 changes: 4 additions & 4 deletions Content.Server.Database/Content.Server.Database.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Server.Database\</OutputPath>
Expand All @@ -13,12 +13,12 @@
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
</ItemGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.Analyzers.targets" />
</Project>
8 changes: 7 additions & 1 deletion Content.Server.Database/ModelPostgres.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;

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

((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());

options.ConfigureWarnings(x =>
{
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
});
}

public PostgresServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
Expand Down Expand Up @@ -82,7 +88,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)
{
foreach(var property in entity.GetProperties())
{
if (property.FieldInfo.FieldType == typeof(DateTime) || property.FieldInfo.FieldType == typeof(DateTime?))
if (property.FieldInfo?.FieldType == typeof(DateTime) || property.FieldInfo?.FieldType == typeof(DateTime?))
property.SetColumnType("timestamp with time zone");
}
}
Expand Down
6 changes: 6 additions & 0 deletions Content.Server.Database/ModelSqlite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Globalization;
using System.Net;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

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

((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());

options.ConfigureWarnings(x =>
{
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
});
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
Expand Down
27 changes: 16 additions & 11 deletions Content.Server.Database/SnakeCaseNaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ public ExtensionInfo(IDbContextOptionsExtension extension) : base(extension) {}

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

public override long GetServiceProviderHashCode() => 0;
public override int GetServiceProviderHashCode() => 0;

public override bool ShouldUseSameServiceProvider(DbContextOptionsExtensionInfo other)
{
return false;
}

public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{
Expand Down Expand Up @@ -118,26 +123,26 @@ public virtual void ProcessEntityTypeAdded(

if (entityType.BaseType is null)
{
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema());
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());

if (entityType.GetViewNameConfigurationSource() == ConfigurationSource.Convention)
{
entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()), entityType.GetViewSchema());
entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()!), entityType.GetViewSchema());
}
}
}

public void ProcessEntityTypeBaseTypeChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
IConventionEntityType newBaseType,
IConventionEntityType oldBaseType,
IConventionEntityType? newBaseType,
IConventionEntityType? oldBaseType,
IConventionContext<IConventionEntityType> context)
{
var entityType = entityTypeBuilder.Metadata;

if (newBaseType is null)
{
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema());
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());
}
else
{
Expand Down Expand Up @@ -173,8 +178,8 @@ public void ProcessForeignKeyOwnershipChanged(IConventionForeignKeyBuilder relat
public void ProcessEntityTypeAnnotationChanged(
IConventionEntityTypeBuilder entityTypeBuilder,
string name,
IConventionAnnotation annotation,
IConventionAnnotation oldAnnotation,
IConventionAnnotation? annotation,
IConventionAnnotation? oldAnnotation,
IConventionContext<IConventionAnnotation> context)
{
var entityType = entityTypeBuilder.Metadata;
Expand Down Expand Up @@ -216,7 +221,7 @@ public void ProcessEntityTypeAnnotationChanged(
&& (string)annotation.Value != ownership.PrincipalEntityType.GetTableName())
{
foreach (var property in entityType.GetProperties()
.Except(entityType.FindPrimaryKey().Properties)
.Except(entityType.FindPrimaryKey()!.Properties)
.Where(p => p.Builder.CanSetColumnName(null)))
{
RewriteColumnName(property.Builder);
Expand Down Expand Up @@ -271,7 +276,7 @@ public void ProcessModelFinalizing(IConventionModelBuilder modelBuilder, IConven

if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
{
columnName = property.GetColumnName(identifier.Value);
columnName = property.GetColumnName(identifier.Value)!;
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
{
property.Builder.HasColumnName(
Expand Down Expand Up @@ -314,7 +319,7 @@ private void RewriteColumnName(IConventionPropertyBuilder propertyBuilder)
if (name == "Id")
name = entityType.GetTableName() + name;
propertyBuilder.HasColumnName(
RewriteName(name), identifier.Value);
RewriteName(name!), identifier.Value);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Content.Server.Chemistry.EntitySystems;
using Content.Server.Inventory.Components;
using Content.Server.Items;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint;
using Content.Shared.Foam;
using Content.Shared.Inventory;
Expand Down Expand Up @@ -51,7 +50,7 @@ protected override void ReactWithEntity(IEntity entity, double solutionFraction)
slot == EquipmentSlotDefines.Slots.IDCARD)
continue;

if (inventory.TryGetSlotItem(slot, out ItemComponent _))
if (inventory.TryGetSlotItem(slot, out ItemComponent? _))
protection += 0.025f;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Content.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Server\</OutputPath>
Expand Down
5 changes: 5 additions & 0 deletions Content.Server/Database/ServerDbBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ private static async Task DeleteCharacterSlot(ServerDbContext db, NetUserId user
.Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot)
.SingleOrDefaultAsync();

if (profile == null)
{
return;
}

db.Profile.Remove(profile);
}

Expand Down
5 changes: 2 additions & 3 deletions Content.Server/Database/ServerDbManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Content.Shared;
using Content.Shared.CCVar;
using Content.Shared.Preferences;
using Microsoft.Data.Sqlite;
Expand Down Expand Up @@ -382,8 +381,8 @@ public MSLogger(ISawmill sawmill)
_sawmill = sawmill;
}

public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception exception,
Func<TState, Exception, string> formatter)
public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception?, string> formatter)
{
var lvl = logLevel switch
{
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Inventory/InventoryHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static bool SpawnItemInSlot(this InventoryComponent inventory, Slots slot
return false;

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

// If the prototype in question doesn't exist, we do nothing.
Expand Down
4 changes: 2 additions & 2 deletions Content.Server/Strip/StrippableComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ bool Check()
if (!inventory.HasSlot(slot))
return false;

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

if (Owner.TryGetComponent<InventoryComponent>(out var inventory))
{
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent _))
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent? _))
placingItem = false;

if (placingItem)
Expand Down
2 changes: 1 addition & 1 deletion Content.Shared/Content.Shared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Configurations>Release;Debug</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion Content.Tests/Content.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion>
<LangVersion>10</LangVersion>
<IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Tests\</OutputPath>
Expand Down
4 changes: 2 additions & 2 deletions Content.Tools/Content.Tools.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>$(TargetFramework)</TargetFramework>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Content.YAMLLinter/Content.YAMLLinter.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>$(TargetFramework)</TargetFramework>
<OutputPath>..\bin\Content.YAMLLinter\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions Pow3r/Pow3r.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>$(TargetFramework)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
2 changes: 1 addition & 1 deletion RobustToolbox
Submodule RobustToolbox updated 29 files
+1 −1 .github/workflows/build-test.yml
+1 −1 .github/workflows/codeql-analysis.yml
+1 −1 .github/workflows/publish-client.yml
+2 −2 .github/workflows/test-content.yml
+2 −2 MSBuild/Robust.Engine.props
+1 −1 MSBuild/Robust.Properties.targets
+4 −2 Robust.Client/Player/LocalPlayer.cs
+1 −1 Robust.Client/Robust.Client.csproj
+6 −6 Robust.Server/Console/Commands/TestbedCommand.cs
+23 −21 Robust.Server/GameObjects/EntitySystems/ActorSystem.cs
+7 −10 Robust.Server/GameObjects/EntitySystems/ViewSubscriberSystem.cs
+3 −3 Robust.Server/GameStates/PVSSystem.cs
+8 −0 Robust.Server/Player/IPlayerSession.cs
+13 −4 Robust.Server/Player/PlayerSession.cs
+1 −1 Robust.Server/ServerStatus/StatusHost.cs
+3 −0 Robust.Shared/ContentPack/Sandbox.yml
+1 −1 Robust.Shared/GameObjects/Component.cs
+5 −0 Robust.Shared/GameObjects/Components/MetaDataComponent.cs
+4 −75 Robust.Shared/GameObjects/Entity.cs
+68 −5 Robust.Shared/GameObjects/EntityManager.Components.cs
+10 −6 Robust.Shared/GameObjects/EntityManager.cs
+10 −0 Robust.Shared/GameObjects/IEntityManager.Components.cs
+6 −6 Robust.Shared/Map/MapManager.cs
+2 −2 Robust.Shared/Network/NetManager.ServerAuth.cs
+3 −6 Robust.Shared/Serialization/RobustMappedStringSerializer.MappedStringDict.cs
+12 −3 Robust.Shared/Utility/StreamExt.cs
+2 −2 Robust.UnitTesting/Client/UserInterface/StylesheetTest.cs
+1 −1 Robust.UnitTesting/Server/GameObjects/Components/Container_Test.cs
+1 −1 Robust.UnitTesting/Shared/Map/MapManager_Tests.cs

0 comments on commit af579b1

Please sign in to comment.