Compile fails to add 'required' to net7.0 generated code
Dzoay opened this issue · comments
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:
- The required test (Required_Attribute_OnSerialize) passes when running specifically net7.0 and debugging indicates correct adding of the required keyword
- I am not sure this is relevant but FlatSharp.Compiler 7.0.0 nuget package does not contain net7.0 tools only net6.0
I have the same issue after upgrading to .net 7
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.
This looks like a bug. I'm sorry for the miss here. I will take a look this evening. Thanks for pointing this out!
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.
Fixed in 7.0.1