I'm trying to execute a simple script just after a project is generated from a dotnet template. The script will try to create a new file called new.txt in the generated project's root directory.
Some sample code I was referencing to make this comes from the official dotnet templating wiki
note template.json references the batch script under postActions > args > executable
template.json
{
"$schema": "http://json.schemastore.org/template",
"author": "Me",
"classifications": [ "Console" ],
"name": "MyTemplate",
"defaultName": "MyPlugin",
"identity": "MyCompany.MyTemplate",
"shortName": "myplugin",
"tags": {
"language": "C#",
"type": "solution"
},
"sourceName": "MyPlugin",
"preferNameDirectory": true,
"guids": [
...
],
"symbols": {
...
},
"sources": [
...
],
"postActions": [
{
"actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
"description": "Runs a script to add a new.txt file in the root dir",
"manualInstructions": [
{
"text": "something went wrong trying to make the new.txt file"
}
],
"continueOnError": false,
"args": {
"executable": "GenerateNewFile.cmd",
"args": "",
"redirectStandardOutput": false,
"redirectStandardError": false
}
}
]
}
From the mentioned wiki source it says
The working directory for the launched executable is set to the root of the output template content.
So I have included a batch script "GenerateNewFile.cmd" in the root directory of the template which also ends up in the root directory of the generated project. Since the root directory of the generated project is the working directory for any postAction scripts, the "executable" value only needs to contain the file name, as the path is relative.
The contents of the GenerateNewFile.cmd is one line. It should create a new file new.txt in the root directory of the generated project and insert hello as the contents. Running the file manually (double clicking it) does what is intended.
GenerateNewFile.cmd
echo hello > new.txt
After updating the template, I try to create a new project from the template but the postAction script is not run. I do not see a new.txt file in my generated project's root directory.
How can I execute this postAction script?