jamescourtney / FlatSharp

Fast, idiomatic C# implementation of Flatbuffers
Apache License 2.0
511 stars 51 forks source link

FlatSharp.Compiler in netcore 3.1 #62

Closed SpontaneousDuck closed 3 years ago

SpontaneousDuck commented 4 years ago

Currently including the FlatSharp.Compiler NuGet package in my ASP.NET Core 3.1 and I am getting incompatible framework error when trying to build. It tells me: The framework 'Microsoft.NETCore.App', version '2.1.0' was not found. When I do not include the Compiler, the project builds successfully. Is there a way to easily bump the version requirements or is there some work that needs to be done to make it compatible?

jamescourtney commented 4 years ago

Can you share a .csproj file that reproduces this behavior?

jamescourtney commented 4 years ago

Also, please share the output of "dotnet --list-sdks" and "dotnet --list-runtimes" from the machine where this fails.

SpontaneousDuck commented 4 years ago

csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FlatSharpSchema Include="../messages/Control.fbs" />
    <FlatSharpSchema Include="../messages/Status.fbs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FlatSharp" Version="3.3.1" />
    <PackageReference Include="FlatSharp.Compiler" Version="3.3.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="FlatSharp.Runtime" Version="3.3.1" />
    <PackageReference Include="NetMQ" Version="4.0.1.6" />
  </ItemGroup>

</Project>
PS> dotnet --list-sdks
3.1.401 [C:\Program Files\dotnet\sdk]
PS> dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Should I have .NET Core 2.1 installed to build the Compiler even if I am targeting 3.1? Thanks for the help!

jamescourtney commented 4 years ago

Thanks for sharing this. According to this Stackoverflow answer, .Net core 3.1 can't run apps compiled for 2.1. The currently published compiler is only built for 2.1.

It'll take a little of time for me to figure out all the different configurations and detection of what runtimes are installed when invoking the compiler. I'm going to mark this as a bug, but since there's an easy workaround, I don't want to rush out a new version for it.

SpontaneousDuck commented 4 years ago

Ahhh, so if I understand this correctly, I only need the runtime installed for 2.1 so the compiler can be invoked on build. But I can still use the generated code for a new v3.1 project. Is that correct?

jamescourtney commented 4 years ago

I only need the runtime installed for 2.1 so the compiler can be invoked on build.

Yes.

But I can still use the generated code for a new v3.1 project. Is that correct?

The generated code is framework agnostic. It should compile for anything that supports .NET standard (assuming that you reference the required packages: System.Memory, FlatSharp.Runtime, etc)