jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
497 stars 50 forks source link

Compile fails to add 'required' to net7.0 generated code #348

Closed Dzoay closed 1 year ago

Dzoay commented 1 year ago

Just cloned the latest code and rebuilt the samples with these project settings:

<TargetFramework>net7.0</TargetFramework>
<LangVersion>latest</LangVersion>

Building this generates code as follows that is an error due to the lack of required

#if NET7_0_OR_GREATER
            public override System.Collections.Generic.IList<System.String> Message
#else
            public override System.Collections.Generic.IList<System.String> Message
#endif

Am I missing some configuration here?

Further investigations:

ben3441 commented 1 year ago

I have the same issue after upgrading to .net 7

Dzoay commented 1 year ago

More info: Locally I have locally rebuilt the nuget package at an arbitrary version 7.0.2 and a local feed with the following changes as an experiment: I added this to the nuspec:

<file src="$OutDir$\net7.0\**" target="tools/net7.0" />

I updated the FlatSharp.Compiler.targets to include the $(TargetFramework) in the compiler path:

<CompilerPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\..\tools\$(TargetFramework)\FlatSharp.Compiler.dll'))</CompilerPath>

This deals with the required build errors identified above. I am uncertain this is the right fix but wanted to post my findings here.

jamescourtney commented 1 year ago

This looks like a bug. I'm sorry for the miss here. I will take a look this evening. Thanks for pointing this out!

jamescourtney commented 1 year ago

My best guess at the moment is that this is because your build machine does not have .NET 7 installed (as all of the test environments do...). This means that when Flatsharp runs, it sees "non-required" properties. You can mitigate this quickly by installing NET7 on your build machines or local machines.

jamescourtney commented 1 year ago

Fixed in 7.0.1