Create a File-Based App - Engine Only
The Create a File-Based App page runs a toolkit scene from a single .cs
file. This is the same idea with no toolkit package: a ground, a cube and a camera against Stride alone,
so you can see what the toolkit's helpers stand for. The project version
walks through the code and maps each part to the helper it replaces; this page is only what changes
when the app is a single file.
Steps
Create a folder for the app and go into it - one app per folder, for the reason on the file-based app page.
Create
Program.cswith these directives at the top, then the code from the project version after them:#:package Stride.Engine@4.4.1 #:package Stride.AssetCompiler@4.4.1 #:property PublishAot=falseUse the Stride version you are on.
PublishAot=falseis there because file-based apps publish as native AOT by default and Stride is not AOT-compatible.Create
Directory.Build.targetsnext to it - the second file, and the reason this page exists:<Project> <ItemGroup> <PackageReference Update="Stride.AssetCompiler" IncludeAssets="build;buildTransitive" /> </ItemGroup> </Project>Run it:
dotnet run Program.cs
Why the second file
The asset compiler has to be referenced build-only. As a plain reference its own assemblies are
copied next to the app, and the app fails at start-up with
Could not load file or assembly 'Stride.NuGetResolver'. A .csproj says build-only with
IncludeAssets="build;buildTransitive" on the reference; a #:package directive has no way to, so
a Directory.Build.targets beside the file says it instead - a file-based app imports one like any
project. The toolkit's file-based apps do not need this because Stride.CommunityToolkit
already passes the asset compiler on build-only; this is the one thing the toolkit does on the
packaging side, and the reason the engine-only version is not quite a single file.
See it in the repository
ProgramEngineOnly.cs
is this app in the toolkit's repository, in the examples folder
examples/code-only/E01_3D_BasicScene_FileBasedApp, next to the toolkit versions of the same scene.
Two things differ from the steps above, both because the file lives inside the repository:
- It writes the version as
@$(StrideVersion), which the repository'sDirectory.Build.propsresolves. Outside the repository write the version number. - The
Directory.Build.targetsbeside it has one more line, anImportof the examples folder's ownDirectory.Build.targets. MSBuild imports only the nearest file of that name, so a folder that adds one has to pass the outer one on. Your own app has no outer file and does not need the line.
That Directory.Build.targets is read by all three apps in the folder, but it only changes the
engine-only one: it updates a direct reference to Stride.AssetCompiler, and the two toolkit apps
have none. Run the engine-only app with:
dotnet run examples/code-only/E01_3D_BasicScene_FileBasedApp/ProgramEngineOnly.cs