Update to .NET 6 and C# 10 (#5233)

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
This commit is contained in:
Javier Guardia Fernández
2021-11-09 15:05:07 +01:00
committed by GitHub
parent 29f3d2d1ca
commit af579b15cc
23 changed files with 63 additions and 43 deletions

View File

@@ -42,7 +42,7 @@ jobs:
- name: Setup .NET Core - name: Setup .NET Core
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 5.0.100 dotnet-version: 6.0.100
- name: Install dependencies - name: Install dependencies
run: dotnet restore run: dotnet restore
- name: Build - name: Build

View File

@@ -19,7 +19,7 @@ jobs:
- name: Setup .NET Core - name: Setup .NET Core
uses: actions/setup-dotnet@v1 uses: actions/setup-dotnet@v1
with: with:
dotnet-version: 5.0.100 dotnet-version: 6.0.100
- name: Install dependencies - name: Install dependencies
run: dotnet restore run: dotnet restore
- name: Build - name: Build

View File

@@ -8,7 +8,7 @@
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" /> <PackageReference Include="BenchmarkDotNet" Version="0.12.1" />

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 --> <!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Client\</OutputPath> <OutputPath>..\bin\Content.Client\</OutputPath>

View File

@@ -6,7 +6,7 @@
<OutputPath>..\bin\Content.IntegrationTests\</OutputPath> <OutputPath>..\bin\Content.IntegrationTests\</OutputPath>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" /> <Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup> <ItemGroup>

View File

@@ -68,9 +68,9 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
// Test for components existing // Test for components existing
Assert.True(human.TryGetComponent(out cuffed!), $"Human has no {nameof(CuffableComponent)}"); 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 hands!), $"Human has no {nameof(HandsComponent)}");
Assert.True(human.TryGetComponent(out SharedBodyComponent _), $"Human has no {nameof(SharedBodyComponent)}"); Assert.True(human.TryGetComponent(out SharedBodyComponent? _), $"Human has no {nameof(SharedBodyComponent)}");
Assert.True(cuffs.TryGetComponent(out HandcuffComponent _), $"Handcuff has no {nameof(HandcuffComponent)}"); 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(secondCuffs.TryGetComponent(out HandcuffComponent? _), $"Second handcuffs has no {nameof(HandcuffComponent)}");
// Test to ensure cuffed players register the handcuffs // Test to ensure cuffed players register the handcuffs
cuffed.TryAddNewCuffs(human, cuffs); cuffed.TryAddNewCuffs(human, cuffs);

View File

@@ -55,7 +55,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.Movement
// Test for climb components existing // Test for climb components existing
// Players and tables should have these in their prototypes. // Players and tables should have these in their prototypes.
Assert.That(human.TryGetComponent(out climbing!), "Human has no climbing"); 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. // Now let's make the player enter a climbing transitioning state.
climbing.IsClimbing = true; climbing.IsClimbing = true;

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 --> <!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Server.Database\</OutputPath> <OutputPath>..\bin\Content.Server.Database\</OutputPath>
@@ -13,12 +13,12 @@
<Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" /> <Import Project="..\RobustToolbox\MSBuild\Robust.DefineConstants.targets" />
<ItemGroup> <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> <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets> <PrivateAssets>all</PrivateAssets>
</PackageReference> </PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.3" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" /> <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0-rc.2" />
</ItemGroup> </ItemGroup>
<Import Project="..\RobustToolbox\MSBuild\Robust.Analyzers.targets" /> <Import Project="..\RobustToolbox\MSBuild\Robust.Analyzers.targets" />
</Project> </Project>

View File

@@ -2,6 +2,7 @@
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using System.Net; using System.Net;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage;
@@ -28,6 +29,11 @@ namespace Content.Server.Database
options.ReplaceService<IRelationalTypeMappingSource, CustomNpgsqlTypeMappingSource>(); options.ReplaceService<IRelationalTypeMappingSource, CustomNpgsqlTypeMappingSource>();
((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension()); ((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());
options.ConfigureWarnings(x =>
{
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
});
} }
public PostgresServerDbContext(DbContextOptions<ServerDbContext> options) : base(options) public PostgresServerDbContext(DbContextOptions<ServerDbContext> options) : base(options)
@@ -82,7 +88,7 @@ namespace Content.Server.Database
{ {
foreach(var property in entity.GetProperties()) 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"); property.SetColumnType("timestamp with time zone");
} }
} }

View File

@@ -3,6 +3,7 @@ using System.ComponentModel.DataAnnotations.Schema;
using System.Globalization; using System.Globalization;
using System.Net; using System.Net;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
@@ -25,6 +26,11 @@ namespace Content.Server.Database
options.UseSqlite("dummy connection string"); options.UseSqlite("dummy connection string");
((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension()); ((IDbContextOptionsBuilderInfrastructure) options).AddOrUpdateExtension(new SnakeCaseExtension());
options.ConfigureWarnings(x =>
{
x.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning);
});
} }
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)

View File

@@ -33,7 +33,12 @@ namespace Content.Server.Database
public override string LogFragment => "Snake Case 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) public override void PopulateDebugInfo(IDictionary<string, string> debugInfo)
{ {
@@ -118,26 +123,26 @@ namespace Content.Server.Database
if (entityType.BaseType is null) if (entityType.BaseType is null)
{ {
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema()); entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());
if (entityType.GetViewNameConfigurationSource() == ConfigurationSource.Convention) if (entityType.GetViewNameConfigurationSource() == ConfigurationSource.Convention)
{ {
entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()), entityType.GetViewSchema()); entityTypeBuilder.ToView(RewriteName(entityType.GetViewName()!), entityType.GetViewSchema());
} }
} }
} }
public void ProcessEntityTypeBaseTypeChanged( public void ProcessEntityTypeBaseTypeChanged(
IConventionEntityTypeBuilder entityTypeBuilder, IConventionEntityTypeBuilder entityTypeBuilder,
IConventionEntityType newBaseType, IConventionEntityType? newBaseType,
IConventionEntityType oldBaseType, IConventionEntityType? oldBaseType,
IConventionContext<IConventionEntityType> context) IConventionContext<IConventionEntityType> context)
{ {
var entityType = entityTypeBuilder.Metadata; var entityType = entityTypeBuilder.Metadata;
if (newBaseType is null) if (newBaseType is null)
{ {
entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()), entityType.GetSchema()); entityTypeBuilder.ToTable(RewriteName(entityType.GetTableName()!), entityType.GetSchema());
} }
else else
{ {
@@ -173,8 +178,8 @@ namespace Content.Server.Database
public void ProcessEntityTypeAnnotationChanged( public void ProcessEntityTypeAnnotationChanged(
IConventionEntityTypeBuilder entityTypeBuilder, IConventionEntityTypeBuilder entityTypeBuilder,
string name, string name,
IConventionAnnotation annotation, IConventionAnnotation? annotation,
IConventionAnnotation oldAnnotation, IConventionAnnotation? oldAnnotation,
IConventionContext<IConventionAnnotation> context) IConventionContext<IConventionAnnotation> context)
{ {
var entityType = entityTypeBuilder.Metadata; var entityType = entityTypeBuilder.Metadata;
@@ -216,7 +221,7 @@ namespace Content.Server.Database
&& (string)annotation.Value != ownership.PrincipalEntityType.GetTableName()) && (string)annotation.Value != ownership.PrincipalEntityType.GetTableName())
{ {
foreach (var property in entityType.GetProperties() foreach (var property in entityType.GetProperties()
.Except(entityType.FindPrimaryKey().Properties) .Except(entityType.FindPrimaryKey()!.Properties)
.Where(p => p.Builder.CanSetColumnName(null))) .Where(p => p.Builder.CanSetColumnName(null)))
{ {
RewriteColumnName(property.Builder); RewriteColumnName(property.Builder);
@@ -271,7 +276,7 @@ namespace Content.Server.Database
if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention) if (property.GetColumnNameConfigurationSource(identifier.Value) == ConfigurationSource.Convention)
{ {
columnName = property.GetColumnName(identifier.Value); columnName = property.GetColumnName(identifier.Value)!;
if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal)) if (columnName.StartsWith(entityType.ShortName() + '_', StringComparison.Ordinal))
{ {
property.Builder.HasColumnName( property.Builder.HasColumnName(
@@ -314,7 +319,7 @@ namespace Content.Server.Database
if (name == "Id") if (name == "Id")
name = entityType.GetTableName() + name; name = entityType.GetTableName() + name;
propertyBuilder.HasColumnName( propertyBuilder.HasColumnName(
RewriteName(name), identifier.Value); RewriteName(name!), identifier.Value);
} }
} }
} }

View File

@@ -2,7 +2,6 @@
using Content.Server.Chemistry.EntitySystems; using Content.Server.Chemistry.EntitySystems;
using Content.Server.Inventory.Components; using Content.Server.Inventory.Components;
using Content.Server.Items; using Content.Server.Items;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.FixedPoint; using Content.Shared.FixedPoint;
using Content.Shared.Foam; using Content.Shared.Foam;
using Content.Shared.Inventory; using Content.Shared.Inventory;
@@ -51,7 +50,7 @@ namespace Content.Server.Chemistry.Components
slot == EquipmentSlotDefines.Slots.IDCARD) slot == EquipmentSlotDefines.Slots.IDCARD)
continue; continue;
if (inventory.TryGetSlotItem(slot, out ItemComponent _)) if (inventory.TryGetSlotItem(slot, out ItemComponent? _))
protection += 0.025f; protection += 0.025f;
} }
} }

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 --> <!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Server\</OutputPath> <OutputPath>..\bin\Content.Server\</OutputPath>

View File

@@ -93,6 +93,11 @@ namespace Content.Server.Database
.Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot) .Where(p => p.Preference.UserId == userId.UserId && p.Slot == slot)
.SingleOrDefaultAsync(); .SingleOrDefaultAsync();
if (profile == null)
{
return;
}
db.Profile.Remove(profile); db.Profile.Remove(profile);
} }

View File

@@ -5,7 +5,6 @@ using System.IO;
using System.Net; using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Content.Shared;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Microsoft.Data.Sqlite; using Microsoft.Data.Sqlite;
@@ -382,8 +381,8 @@ namespace Content.Server.Database
_sawmill = sawmill; _sawmill = sawmill;
} }
public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception exception, public void Log<TState>(MSLogLevel logLevel, EventId eventId, TState state, Exception? exception,
Func<TState, Exception, string> formatter) Func<TState, Exception?, string> formatter)
{ {
var lvl = logLevel switch var lvl = logLevel switch
{ {

View File

@@ -19,7 +19,7 @@ namespace Content.Server.Inventory
return false; return false;
// If we don't have that slot or there's already an item there, we do nothing. // 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; return false;
// If the prototype in question doesn't exist, we do nothing. // If the prototype in question doesn't exist, we do nothing.

View File

@@ -178,7 +178,7 @@ namespace Content.Server.Strip
if (!inventory.HasSlot(slot)) if (!inventory.HasSlot(slot))
return false; 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))); user.PopupMessageCursor(Loc.GetString("strippable-component-item-slot-occupied",("owner", Owner)));
return false; return false;
@@ -403,7 +403,7 @@ namespace Content.Server.Strip
if (Owner.TryGetComponent<InventoryComponent>(out var inventory)) if (Owner.TryGetComponent<InventoryComponent>(out var inventory))
{ {
if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent _)) if (inventory.TryGetSlotItem(inventoryMessage.Slot, out ItemComponent? _))
placingItem = false; placingItem = false;
if (placingItem) if (placingItem)

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 --> <!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Configurations>Release;Debug</Configurations> <Configurations>Release;Debug</Configurations>

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<!-- Work around https://github.com/dotnet/project-system/issues/4314 --> <!-- Work around https://github.com/dotnet/project-system/issues/4314 -->
<TargetFramework>$(TargetFramework)</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<LangVersion>9</LangVersion> <LangVersion>10</LangVersion>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>..\bin\Content.Tests\</OutputPath> <OutputPath>..\bin\Content.Tests\</OutputPath>

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<OutputPath>..\bin\Content.YAMLLinter\</OutputPath> <OutputPath>..\bin\Content.YAMLLinter\</OutputPath>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
</PropertyGroup> </PropertyGroup>

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\RobustToolbox\MSBuild\Robust.Properties.targets" />
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework> <TargetFramework>$(TargetFramework)</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>