bflattened / bflat

C# as you know it but with Go-inspired tooling (small, selfcontained, and native executables)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to include/link external nuget packages

RednibCoding opened this issue · comments

I have included some NuGet packages into my project. Now, I would like to compile the project with BFlat. However, I encounter a bunch of errors in the form of 'error CS0103: The name 'xxxx' does not exist in the current context.' Those names are from the NuGet packages."

"Is it possible to compile with BFlat when having NuGet dependencies in the project? If yes, how can I do that?

You need to download the NuGet, extract the ZIP (nuget files are just renamed zip) and pass it as a -r: reference to bflat build. If the nuget file includes any MSBuild logic, you also need to apply the msbuild logic.

There's no integrated NuGet in bflat. If you want integrated NuGet and MSBuild, what you want is the .NET SDK, not bflat.

Ok i downloaded the nuget package manually (Raylib-cs) and tried to compile the project like so: bflat build -r:raylib-cs.6.0.0\lib\net6.0\Raylib-cs.dll without any errors.
Then i copied the raylib.dll (needed for runtime since it is not statically linked) into the root folder (where the compiled exe lies) and started the exe with this output:

Unhandled Exception: System.BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
   at System.Runtime.InteropServices.NativeLibrary.LoadLibErrorTracker.Throw(String) + 0x31
   at Internal.Runtime.CompilerHelpers.InteropHelpers.FixupModuleCell(InteropHelpers.ModuleFixupCell*) + 0xfd
   at Internal.Runtime.CompilerHelpers.InteropHelpers.ResolvePInvokeSlow(InteropHelpers.MethodFixupCell*) + 0x2f
   at Raylib_cs.Raylib.InitWindow(Int32, Int32, SByte*) + 0x2b
   at Raylib_cs.Raylib.InitWindow(Int32, Int32, String) + 0x2c
   at LogiMax.Program.Main() + 0x21
   at LogiMax!<BaseAddress>+0x11e428

Any ideas what went wrong?

That's a failed p/invoke. I guess you copied the wrong raylib.dll (x86 instead of x64?).

Oh indeed, I copied the wrong raylib.dll (x86 instead of x64).
Thanks for your help!

Is it somehow possible to embedd a dll into the executable so i dont have to distrubte the dll with the exe?

@RednibCoding there are packers for this, but that should not be part of the compiler. You can however link static library to your app instead of using dll.