How to add pre/post build steps to plugin

I’ve seen information about PreBuildSteps and PostBuildSteps in uproject and uplugin. But the following structure of uplugin seems doesn’t work.

{
	"FileVersion": 3,
	"Version": 1,
	"VersionName": "5.5.5",
	"EngineVersion" : "4.22.0",
	"FriendlyName": "MyPlugin",
	"Description": "UE4 Plugin",
	"Category": "Advertising",
	"Modules": [
		{
			"Name": "MyPlugin",
			"Type": "Runtime",
			"LoadingPhase" : "PreDefault",
			"WhitelistPlatforms": [ 
				"IOS", 
				"Android",
				"Win64",
				"Mac",
				"Linux"
			]
		}
	],
	"EnabledByDefault": true,
	"CanContainContent": true,
	"IsBetaVersion": false,
	"Installed": true,
	"RequiresBuildPlatform": true,
	"PostBuildSteps":
	 {
	     "IOS": [
	         "echo gooby"
	     ],
	     "Android": [
	     	"echo goodby"
	     ]
	 },
	 "PreBuildSteps":
	 {
	     "IOS": [
	         "echo hello"
	     ],
	     "Android": [
	     	"echo hello"
	     ]
	 }
}

Hi,

I had the same issue, but got it working with the following structure:

{
	"FileVersion": 3,
	"Version": 1,
	"VersionName": "1.0",
	"FriendlyName": "FriendlyName",
	"Description": "",
	"Category": "Other",
	"CreatedBy": "",
	"CreatedByURL": "",
	"DocsURL": "",
	"MarketplaceURL": "",
	"SupportURL": "",
	"CanContainContent": true,
	"IsBetaVersion": true,
	"IsExperimentalVersion": false,
	"Installed": false,
	"Modules": [
		{
			"Name": "ModuleName",
			"Type": "Runtime",
			"LoadingPhase": "Default"
		}
	],
	"PreBuildSteps": {
		"Win64": [
			"echo 'PreBuildSteps...'",
			"echo 'PreBuild Info: RootDir=$(RootDir)'",
			"echo 'PreBuild Info: EngineDir=$(EngineDir)'",
			"echo 'PreBuild Info: ProjectDir=$(ProjectDir)'",
			"echo 'PreBuild Info: TargetName=$(TargetName)'",
			"echo 'PreBuild Info: TargetPlatform=$(TargetPlatform)'",
			"echo 'PreBuild Info: TargetConfiguration=$(TargetConfiguration)'",
			"echo 'PreBuild Info: TargetType=$(TargetType)'",
			"echo 'PreBuild Info: ProjectFile=$(ProjectFile)'",
			"echo 'PreBuild Info: PluginDir=$(PluginDir)'",
		],
		"Mac": [
			"echo 'PreBuildSteps...'"
		],
		"Linux": [
			"echo 'PreBuildSteps...'"
		]
	}
}

The listed variables are the ones expanded by the Unreal build pipeline, and you can use them at will.
For more info check here at the Unreal source code.

You might need to double-check the Target names.

2 Likes

Casually resurrecting this, I’m to copy a file as a post build step, my command works “copy $(PluginDir)\foo\bar.exe D:\” but it only seemed to work the first time I packaged. Doesn’t seem to be doing it for any subsequent packages?

Also, do you know if there’s a “Target Name” such as $(RootDir) but for the output directory of the build?