Templating: Update PostAction with symbol parameters to cmd file arguments

Created on 3 Jul 2018  路  9Comments  路  Source: dotnet/templating

I need to pass symbols parameters to args when executing setup.cmd file using postActions property as below .template.config file.

Here, i am passing two symbols of type string jsonFileNamePath and myfilename as arguments to setup.cmd.

{
  "$schema": "http://json.schemastore.org/template",
  "identity": "SampleTemplate",
  "groupIdentity": "SampleTemplate",
  "author": "Abhishek",
  "classifications": ["api", "apiswagger"],
  "name": "Sample Template",
  "shortName": "SampleTemplate",
  "tags": {
    "language": "C#"
  },
  "sourceName": "SampleTemplate",
  "primaryOutputs": [
    {
        "path": "SampleTemplate.csproj"
    }
  ],
  "guids": [
    "98048C9C-BF28-46BA-A98E-63767EE5E3A8",
    "FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF"
  ],
  "symbols": {
    "skipRestore": {
      "type": "parameter",
      "datatype": "bool",
      "description": "Skips the execution of 'dotnet restore' on project creation.",
      "defaultValue": "false"
    },
    "jsonFileNamePath": {
      "type": "parameter",
      "datatype": "string",
      "description": "Path of the json file ",
      "defaultValue": "myjson.json",
      "isRequired" : "true"
    },
    "myfilename": {
      "type": "parameter",
      "datatype": "string",
      "description": "Name of the json file ",
      "defaultValue": "myjson",
      "isRequired" : "true"
    }
  },
  "postActions": [
    {
      "condition": "(!skipRestore)",
      "description": "Restore NuGet packages required by this project.",
      "manualInstructions": [
        { "text": "Run 'dotnet restore'" }
      ],
      "actionId": "210D431B-A78B-4D2F-B762-4ED3E3EA9025",
      "continueOnError": true
    },
    {
    "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
    "args": {
      "executable": "setup.cmd",
      "args": "jsonFileNamePath myfilename"
    },
    "manualInstructions": [{ 
       "text": "Run 'setup.cmd jsonFileNamePath myfilename'" 
       }],
    "continueOnError": "false",
    "description ": "setups the project by calling setup.cmd"
  }
  ]
}
feature triaged

Most helpful comment

@wazzamatazz , thanks for the additional details. We are currently updating documents (working through that particular backlog). We can then move on to the "Template authoring" backlog, relevant to this issue. Please stay tuned.

All 9 comments

Currently, post-actions do not support accessing user input. As a workaround, you could change setup.cmd to contain the values you're currently passing (or generate another script that calls setup.cmd) - treating that file like normal template content

Closing this since there hasn't been any activity. Please let us know if this approach doesn't work for your use case.

@mlorbetske I think, it will be very useful - be able to pass the symbols in postAction. I'd like to solve a similiar use case.

I want to run command like this:

{
      "actionId": "3A7C4B45-1F5D-4A30-959A-51B88E82B5D2",
      "args": {
        "executable": "dotnet",
        "args": "run /seed --project src/(name).csproj"
      },
      "manualInstructions": [
        {
          "text": "Seeds the initial user database"
        }
      ],
      "continueOnError": false,
      "description ": "seeds the database"
    }

I need get the name of created csproj according user input.
Any idea how to achieve that?
Thx.

@skoruba currently, this would be achieved by including script files in your template content that execute the command you want (presumably you鈥檇 want both a .cmd file and a .sh file) that perform the action you鈥檇 like and call the script file from the post-action. The script file being subject to the operations set up in template.json, if it contains the original value of sourceName (and either sourceName has distinct value forms, or a derived symbol is used to capture the identity form), after creation it would contain the name the user had chosen.

Thanks all for the suggestions, however we were expecting some straight forward approach. I hope we can suggest this type of requirements as Enhancement feature.

A post-action rework with access to parameters & such has been on our radar for a while now, the responses here were intended to help enable this sort of functionality in the short run. I鈥檒l re-open this to make sure we track this scenario.

  1. Adding item to specific project corresponding to a targeted delivery area
  2. Once this has been done for the entire backlog, the next steps will be to prioritize within each project & output a delivery roadmap.
  3. At that point, the issues will be assigned to a corresponding milestone
  4. The team will then begin to deliver against the road map, contributions always welcome

Just to add another use case: the previous suggested workaround of using a symbol replacement in the script file itself isn't always viable, because the action might be e.g. to encrypt and/or store sensitive information such as a client secret somewhere.

@wazzamatazz , thanks for the additional details. We are currently updating documents (working through that particular backlog). We can then move on to the "Template authoring" backlog, relevant to this issue. Please stay tuned.

Was this page helpful?
0 / 5 - 0 ratings