Samples in Sharpmake are managed via a data-driven approach using the SamplesDef.json file. This file defines how samples are executed in CI pipelines (GitHub/GitLab) and via the RunSample.ps1 script.
Each sample entry in SamplesDef.json is an object that specifies its metadata, target environments, and the sequence of commands required to run it. Commands are executed using the PowerShell Invoke-Expression cmdlet, meaning they share the same execution context; variables set in one command are available to subsequent commands.
{
"Name": "HelloWorld",
"CIs": [ "github", "gitlab" ],
"OSs": [ "windows-2019", "windows-2022" ],
"Frameworks": [ "net6.0" ],
"Configurations": [ "debug", "release" ],
"TestFolder": "samples/HelloWorld",
"Commands":
[
"./RunSharpmake.ps1 -workingDirectory {testFolder} -sharpmakeFile \"HelloWorld.sharpmake.cs\" -framework {framework}",
"./Compile.ps1 -slnOrPrjFile \"helloworld_vs2019_win32.sln\" -configuration {configuration} -platform \"Win32\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
"&'./{testFolder}/projects/output/win32/{configuration}/helloWorld.exe'",
"./Compile.ps1 -slnOrPrjFile \"helloworld_vs2019_win64.sln\" -configuration {configuration} -platform \"x64\" -WorkingDirectory \"{testFolder}/projects\" -VsVersion {os} -compiler MsBuild",
"&'./{testFolder}/projects/output/win64/{configuration}/helloWorld.exe'"
]
}