Bflata
A wrapper/buildscript generator/project flattener for BFlat, a native C# compiler, to recursively build/flatten MSBuild oriented C# projects with referenced projects, packages, dependencies & resources.
Install / Use
/learn @xiaoyuvax/BflataREADME
BFlatA
BFlatA Purpose: Write your program in VS, and Build it Flat (with bflat)
BFlatA is a wrapper, build script generator and project flattener for BFlat - a native C# compiler, in order to recusively build/flatten C# projects(.csproj) originally created for MSBuild (by Visual Studio) with their:
- Referenced projects
- Nuget package dependencies
- Native library dependencies
- Embedded resources etc.
Some intuitive demos of usage:
bflata build myproject.csproj
would produce a myproject.exe and a build.rsp if bflat is properly installed, set in %PATH%, and args properly served. If the build verb not specified, only rsp file generated, which you can use to build later with BFlat (please notice the difference between BFlat, the compiler and BFlatA, the wrapper).
bflata flatten-all myproject.csproj
would produce a myproject.flat folder, into which all code files, libs, resources of myproject even together with what all child projects referenced would be extracted and copied, as a complete project package, in which u would expect to build the project with bflat direclty like 'go build'.
You can find BFlat, the C# native compiler at flattened.net.
BFlatA is relevent to an issue from bflat: https://github.com/bflattened/bflat/issues/61
Update Logs
Update 24-02-08 (V1.5.0.8)
- Matching a version range of packages is allowed.
Update 23-03-30 (V1.4.3.0)
<NoStdLib>flag bug fixed.
Update 23-03-29 (V1.4.2.2)
- Support Prebuild/Postbuild Actions.
- This version supports building project like MOOS, check out the Demo Projects
Update 23-03-22 (V1.4.2.0)
- Allow specifying an external linker instead of that comes with bflat, such as MSVC linker(link.exe).
Update 23-03-16 (V1.3.0.0):
- Removed support for Windows Batch or Linux Shell Script (not meaningful if RSP is available), now BFlatA only generates RSP script.
- Allow specifying one or more RSP files to be included with -inc:<rsp file> options, in case certain groups of fixed building options need to be included and used for certain project. Usually you can put linker args, home path in one rsp file and include it with specified csproj.
Update 23-03-15 (V1.2.1.1):
- Add support for NativeLibrary.
Update 23-03-03 (V1.2.0.0):
- Adding support compiling .resx files by calling resgen.exe, which u must specify with
--resgen. Namespace for each .resx file will be determined by checking corresponding code file. eg. myForm.cs for myForm.resx and Resources.Designer.cs for Resources.resx. But there might still be some problem running winform program with resources, as described in Known Issues below.
Update 23-02-26 (V1.1.0.0):
- Exclu mechanism added. Some (but not all) dependencies referenced by nuget packages with name starting with "System.*" might have already been included in runtime, which is enabled with
bflat --stdlib Dotnetoption, and must be excluded from the BFlata generated build script, otherwise you may see a lot of error CS0433 as below:
error CS0433: The type 'MD5' exists in both 'System.Security.Cryptography.Algorithms, Version=4.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'System.Security.Cryptography, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
BFlatA introduced a mechanism called "Exclu" to exclude packages from dependencies during scripting. Literally, Exclu means the Excluded Packages. BFlatA supports extracting names to be excluded from Dotnet runtime, more exactly, the specific Shared Frameworks such as Microsoft.NETCore.App(which is what BFlat incorprates so far), to generate ".exclu" file, which can be reused in later builds, by using the -xx option which uses the moniker name specified by -fx to save/load Exclus from files accordingly, in addition to an always-load "packages.exclu" file, if exists, where you can put in custom Exclus.
I provided a net7.0.exclu file in the repository as the default Exclu for net7.0, which is the default target of both BFlata and BFlat by now, and you can copy it to ur working directory, if you don't want to extract Exclus by youself from Dotnet runtime(with -xx option).
- 'build-il' is allowed now. This verb is consistent with that of BFlat, and it only affects root project. Dependent projects will always being built under TREE mode with 'build-il' on.
- A new Build Mode
-bm:treedis introduced to provide a shortcut for-bm:tree -dd, simply a short. - BFlat style args are supported now, u can use both space or ":" for evaluation of argument values.
- BFlat's
-o|--out<file>option is now hijacked by BFlatA as to be properly scripted in the generated script. At least, it will not be passed to every referenced projects.
Update 23-02-24:
- Response file(.rsp) support added, and 'arguments too long' problem solved. The .rsp script will be taken as default build script format of BFlatA. You can use the generated build.rsp file like
bflat build @build.rspto build a FLATTENED project. Note: a single .rsp file itself does not support building project Tree, instead you may use-st:bator-st:shto generate script that supports building project trees, or build through BFlatA directly(with bothbuildand-bm:treeoption on). - Paths cache of Nuget packages are now saved to packages.cache in the working path, and will be reused at the next run, as to improve performance.
- A new
-dd(Deposit Dependencies) option is introduced for compiling projects who uses references of child projects indirectly, and still offering certain extent of version consistency, where dependencies are added-up (deposited) along the hiearchy line and be accumulatively served to the parent project level by level (if any dependency version conflict upon merging with parent level, higher version will be retained, as to guarantee maximal version compatibility).
Usage
Usage: bflata [build|build-il|flatten|flatten-all] <root csproj file> [options]
[build|build-il|flatten|flatten-all] BUILD|BUILD-IL = build with BFlat in %Path% in native or in IL.
FLATTEN = extract code files from project hierachy into a "flattened, Go-like" path hierachy,
FALTTEN-ALL = flatten + copy all dependencies and resources to dest path,
both with dependency references written to a BFA file.
If omitted, generate build script only, with -bm option still valid.
<root csproj file> Must be the 2nd arg if 'build' specified, or the 1st otherwise, only 1 root project allowed.
Options:
-pr|--packageroot:<path to package storage> eg.'C:\Users\%username%\.nuget\packages' or '$HOME/.nuget/packages'.
-h|--home:<MSBuildStartupDirectory> Path to VS solution usually, default:current directory.
Caution: this path may not be the same as <root csproj file>,
and is needed for entire solution to compile correctly.
-fx|--framework:<moniker> The TFM compatible with the built-in .net runtime of BFlat(see 'bflat --info')
mainly purposed for matching dependencies, e.g. 'net7.0'
-bm|--buildmode:<flat|tree|treed> FLAT = flatten project tree to one for building;
TREE = build each project alone and reference'em accordingly with -r option;
TREED = '-bm:tree -dd'.
--resgen:<path to resgen.exe> Path to Resource Generator(e.g. ResGen.exe).
-inc|--include:<path to BFA file> BFA files(.bfa) contain any args for BFlatA, each specified by -inc:<filename>.
Unlike RSP file, each line in BFA file may contain multiple args with macros enabled(listed at foot).
BFAs can be used as project-specific build profile, somewhat equivalent to .csproj file.
If any arg duplicated, valid latters will overwrite, except for <root csproj file>.
-pra|--prebuild:<cmd or path to executable> One command line to be executed before build.Can be multiple.
-poa|--postbuild:<cmd or path to executable> One command line to be executed after build.Can be multiple.
Shared Options with BFlat:
--target:<Exe|Shared|WinExe> Build Target.default:<BFlat default>
--os <Windows|Linux|Uefi> Build Target.default:Windows.
--arch <x64|arm64|x86|...> Platform archetecture.default:x64.
-o|--out:<File> Output file path for the root project.
--verbose Enable verbose logging
Obsolete Options:
-dd|--depdep Deposit Depend
