Skip to content

Commit

Permalink
dotnet7 (#108)
Browse files Browse the repository at this point in the history
* fix obsolescence warning on ForEachAsyncSemaphore

* nuget updates

* drop .netstandard support, added .net 7 +semver: major

* misc updates

* added devcontainer

* fix code coverage

* change wf to tagged actions

* devcontainer to .net 7

* fix tests

* coverage fix

* try this

* fix

* nullability

* compound operator

* nullability fix

* nullability fix

* nullability fix

* nullable fix

* nullable fix

* disable sq

Co-authored-by: Azure DevOps CI <agent@dev.azure.com>
  • Loading branch information
f2calv and Azure DevOps CI committed Nov 20, 2022
1 parent 54abbff commit 806296d
Show file tree
Hide file tree
Showing 22 changed files with 94 additions and 70 deletions.
18 changes: 18 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "C# (.NET)",
"image": "mcr.microsoft.com/devcontainers/dotnet:0-7.0-bullseye",
"features": {
"ghcr.io/devcontainers/features/node:1": {
"version": "lts"
},
"ghcr.io/devcontainers/features/powershell:1": {}
}
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [5000, 5001],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "dotnet restore",
// Configure tool-specific properties.
// "customizations": {},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
# env:
# PublishPreview: ${{ inputs.PublishPreview }}
steps:
- uses: f2calv/gha-dotnet-nuget@main
- uses: f2calv/gha-dotnet-nuget@v1
id: dotnet
with:
BuildConfiguration: ${{ github.event.inputs.BuildConfiguration }}
Expand All @@ -56,10 +56,11 @@ jobs:
PublishPreview: ${{ github.event.inputs.PublishPreview }}

SonarQube:
if: false #Note: disabled as SonarQube not yet available for .NET 7.0
runs-on: windows-latest
needs: build
steps:
- uses: f2calv/gha-sonarqube@main
- uses: f2calv/gha-sonarqube@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/

# .NET Core
# .NET
project.lock.json
project.fragment.lock.json
artifacts/
Expand Down
11 changes: 10 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>

<PropertyGroup>
<!-- https://docs.microsoft.com/en-us/dotnet/core/tools/csproj -->
<!-- https://learn.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props -->
<!-- default for IsPackable is true, we change this to false here so that we must be explicit in each project when creating NuGet packages -->
<IsPackable>false</IsPackable>

Expand Down Expand Up @@ -43,6 +43,15 @@
<NoWarn>CS0162</NoWarn>
</PropertyGroup>

<!-- Note: remove below PropertyGroup when .NET 7.0 > 7.0.100 it's a temporary workaround, https://github.com/coverlet-coverage/coverlet/issues/1391#issuecomment-1313581269 -->
<PropertyGroup>
<CollectCoverage>true</CollectCoverage>
<ExcludeByAttribute>GeneratedCodeAttribute</ExcludeByAttribute>
<Exclude>[*]*.Migrations.*</Exclude>
<ExcludeByFile>**/MyFile.cs</ExcludeByFile>
<CoverletOutputFormat>lcov</CoverletOutputFormat>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<!-- <PackageReference Include="DotNet.ReproducibleBuilds" Version="1.1.1" PrivateAssets="All"/> -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<RootNamespace>CasCap.Common.Caching</RootNamespace>
</PropertyGroup>

Expand All @@ -16,23 +16,23 @@
<ProjectReference Include="..\CasCap.Common.Testing\CasCap.Common.Testing.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/CasCap.Common.Caching.Tests/Tests/CacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static async Task<MyTestClass> GetAsync()
await Task.Delay(0);
await Task.Delay(0);
//lets go fake getting some data
if (obj is null) obj = new MyTestClass();
obj ??= new MyTestClass();
return obj;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/CasCap.Common.Caching/CasCap.Common.Caching.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -18,9 +18,9 @@
<ProjectReference Include="..\CasCap.Common.Threading\CasCap.Common.Threading.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StackExchange.Redis" Version="2.6.66" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="6.0.1" />
<PackageReference Include="StackExchange.Redis" Version="2.6.70" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="7.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/CasCap.Common.Caching/Services/DistCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class DistCacheService : IDistCacheService

public async Task<T?> Get<T>(string key, Func<Task<T>>? createItem = null, int ttl = -1) where T : class
{
if (!_local.TryGetValue(key, out T cacheEntry))
if (!_local.TryGetValue(key, out T? cacheEntry))
{
var tpl = await _redis.GetCacheEntryWithTTL<T>(key);
if (tpl != default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ async Task RunServiceAsync(CancellationToken cancellationToken)
_redisCacheSvc.subscriber.Subscribe(_cachingOptions.ChannelName).OnMessage(async channelMessage =>
{
await Task.Delay(0);
var key = (string)channelMessage.Message;
if (!key.StartsWith(_cachingOptions.pubSubPrefix))
var key = (string?)channelMessage.Message;
if (key is not null && !key.StartsWith(_cachingOptions.pubSubPrefix))
{
var finalIndex = key.Split('_')[2];
_distCacheSvc.DeleteLocal(finalIndex, true);
Expand Down
24 changes: 12 additions & 12 deletions src/CasCap.Common.Caching/Services/RedisCacheService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public interface IRedisCacheService
ISubscriber subscriber { get; }
IServer server { get; }

byte[] Get(string key, CommandFlags flags = CommandFlags.None);
Task<byte[]> GetAsync(string key, CommandFlags flags = CommandFlags.None);
byte[]? Get(string key, CommandFlags flags = CommandFlags.None);
Task<byte[]?> GetAsync(string key, CommandFlags flags = CommandFlags.None);

bool Set(string key, byte[] value, TimeSpan? expiry = null, CommandFlags flags = CommandFlags.None);
Task<bool> SetAsync(string key, byte[] value, TimeSpan? expiry = null, CommandFlags flags = CommandFlags.None);
Expand Down Expand Up @@ -55,9 +55,9 @@ public RedisCacheService(ILogger<RedisCacheService> logger, IOptions<CachingOpti

public IServer server { get { return Connection.GetServer(configuration.EndPoints[0]); } }

public byte[] Get(string key, CommandFlags flags = CommandFlags.None) => db.StringGet(key, flags);
public byte[]? Get(string key, CommandFlags flags = CommandFlags.None) => db.StringGet(key, flags);

public async Task<byte[]> GetAsync(string key, CommandFlags flags = CommandFlags.None) => await db.StringGetAsync(key, flags);
public async Task<byte[]?> GetAsync(string key, CommandFlags flags = CommandFlags.None) => await db.StringGetAsync(key, flags);

public bool Set(string key, byte[] value, TimeSpan? expiry = null, CommandFlags flags = CommandFlags.None)
=> db.StringSet(key, value, expiry, flags: flags);
Expand All @@ -75,7 +75,7 @@ public async Task<(TimeSpan? expiry, T cacheEntry)> GetCacheEntryWithTTL<T>(stri
var o = await db.StringGetWithExpiryAsync(key);
if (o.Expiry.HasValue && o.Value.HasValue)
{
var requestedObject = ((byte[])o.Value).FromMessagePack<T>();
var requestedObject = ((byte[]?)o.Value).FromMessagePack<T>();
return (o.Expiry, requestedObject);
}
else
Expand All @@ -90,28 +90,28 @@ public async Task<(TimeSpan? expiry, T cacheEntry)> GetCacheEntryWithTTL_Lua<T>(

//handle binary format
var tpl = await luaGetBytes();
if (tpl != default)
if (tpl != default && tpl.bytes is not null)
{
var requestedObject = tpl.bytes.FromMessagePack<T>();
var expiry = tpl.ttl.GetExpiry();
res = (expiry, requestedObject);
}
return res;

async Task<(int ttl, byte[] bytes)> luaGetBytes()
async Task<(int ttl, byte[]? bytes)> luaGetBytes()
{
(int, byte[]) output = default;
(int, byte[]?) output = default;
var tpl = await luaGetCacheEntryWithTTL();
if (tpl != default)
output = (tpl.ttl, (byte[])tpl.payload);
output = (tpl.ttl, (byte[]?)tpl.payload);
return output;
}

async Task<(int ttl, string type, RedisResult payload)> luaGetCacheEntryWithTTL()
{
(int, string, RedisResult) tpl = default;
var retKeys = await GetCacheEntryWithTTL();
if (retKeys.Length == 3)
if (retKeys is not null && retKeys.Length == 3)
{
var ttl = retKeys[0] is not null ? (int)retKeys[0] : -1;
var type = retKeys[1] is not null ? (string)retKeys[1] : string.Empty;
Expand All @@ -121,7 +121,7 @@ async Task<(int ttl, string type, RedisResult payload)> luaGetCacheEntryWithTTL(
}

//Retrieves both the TTL and the cached item from Redis in one network call.
async Task<RedisResult[]> GetCacheEntryWithTTL()
async Task<RedisResult[]?> GetCacheEntryWithTTL()
{
try
{
Expand All @@ -132,7 +132,7 @@ async Task<RedisResult[]> GetCacheEntryWithTTL()
trackKey = (RedisKey)GetTrackKey(),//the key of the HashSet recording access attempts (expiry set to 7 days)
trackCaller = (RedisKey)caller//the method which instigated this particular access attempt
});
var retKeys = (RedisResult[])result;
var retKeys = (RedisResult[]?)result;
return retKeys;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<RootNamespace>CasCap.Common.Extensions</RootNamespace>
</PropertyGroup>

Expand All @@ -11,17 +11,17 @@
<ProjectReference Include="..\CasCap.Common.Testing\CasCap.Common.Testing.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/CasCap.Common.Extensions/CasCap.Common.Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
10 changes: 5 additions & 5 deletions src/CasCap.Common.Logging/CasCap.Common.Logging.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -13,10 +13,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions src/CasCap.Common.Net.Tests/CasCap.Common.Net.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<RootNamespace>CasCap.Common.Net</RootNamespace>
</PropertyGroup>

Expand All @@ -11,17 +11,17 @@
<ProjectReference Include="..\CasCap.Common.Testing\CasCap.Common.Testing.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.msbuild" Version="3.1.2">
<PackageReference Include="coverlet.msbuild" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 2 additions & 2 deletions src/CasCap.Common.Net/CasCap.Common.Net.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.0.0">$(TargetFrameworks);net6.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<TargetFrameworks Condition="$(MSBuildVersion) &gt;= 17.3.0">$(TargetFrameworks);net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand All @@ -12,11 +12,7 @@
<PackageTags>extensions,helpers,MessagePack</PackageTags>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="MessagePack" Version="1.9.11" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
<!--breaking changes in MessagePack v2, see https://github.com/neuecc/MessagePack-CSharp/issues/744 -->
<ItemGroup>
<PackageReference Include="MessagePack" Version="2.4.35" />
<PackageReference Include="MessagePackAnalyzer" Version="2.4.35">
<PrivateAssets>all</PrivateAssets>
Expand Down
Loading

0 comments on commit 806296d

Please sign in to comment.