GithubHelp home page GithubHelp logo

commandtaskrunner's Introduction

Command Task Runner extension

Adds support for command line batch files in Visual Studio 2015's & 2017's Task Runner Explorer. Supports .exe, .cmd, .bat, .ps1 and .psm1 files.

Build status

Download the extension at the VS Marketplace or get the nightly build

Add commands

The easiest way to add a batch file to Task Runner Explorer is to right-click it in Solution Explorer and select Add to Task Runner

Context menu

You can right-click supported batch files in either solution folders or from within a any project.

Doing so will create a commands.json file. If you right-clicked a batch file in a solution folder, then the commands.json file will be placed in the solution folder. If the batch file is in a project you will be prompted to select to either put it in the project or solution folder.

If a commands.json file already exist, the new batch file will be added.

Execute scripts

When scripts are specified, the Task Runner Explorer will show those scripts.

Task list

Each script can be executed by double-clicking the task.

commands.json locations

The Task Runner Explorer supports multiple task runners in the same solution. For instance, you can have commands specified for the solution and additional ones for each project in that solution.

Task Runner Explorer will try to find a commands.json file in any parent folder to either the individual projects or the solution until it hits the root of the drive.

You can also add a "commands.user.json" file if you need local, user specific commands. This file follows the same schema as the "commands.json" file. Any commands added to this file will appear under a "User Commands" group.

Commands

Inside commands.json it is possible to add custom scripts inside the "scripts" element.

{
	"commands": {
		"Build": {
			"FileName": "cmd.exe",
			"WorkingDirectory": ".",
			"Arguments": "/c build\\build.cmd"
		}
	}
}

Commands with no batch file

You can execute any command inside commands.json by manually editing it. A batch file is not needed if you just need to execute simple commands.

Drag and drop

You can drag any supported batch file onto commands.json to add it. Just keep in mind that Visual Studio doesn't support drag and drop from solution folders.

Bindings

Script bindings make it possible to associate individual scripts with Visual Studio events such as "After build" etc.

Visual Studio bindings

Limitations

Some projects (vcxproj (C++ and C++/cli projects), website folder projects, TwinCAT projects, etc.) do not propagate some properties regarding solution and project configuration that are needed by this extension. If there are no .NET project in the solution, this extension may not work at it's full capacity. At the moment, this extension works best with .NET projects.

Open Command Line

For the optimal experience with batch file and Visual Studio, try the free Open Command Line extension for even more features.

License

Apache 2.0

commandtaskrunner's People

Contributors

drywolf avatar gregtrevellick avatar ksuamel avatar madskristensen avatar sergey-vlasov avatar thieum avatar ylepikhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

commandtaskrunner's Issues

Variables such as $(SolutionDir) don't seem to be replaced/applied

Installed product versions

  • Visual Studio: 2017 Enterprise
  • This extension: 1.2.34

Description

My commands.json file uses variables such as $(SolutionDir) but they don't get applied. Looking at the code they should be applied:

https://github.com/madskristensen/CommandTaskRunner/blob/master/src/TaskRunner/TaskRunnerProvider.cs

Steps to recreate

  1. Add a new commands.json file or edit an existing one
  2. Use a variable, e.g. $(SolutionDir) in any of the fields (should be supported in Filename, Workingdirectory, Arguments and Name (again, looking at the code), for example the arguments field for passing a variable to a PowerShell script
  3. Run the task

Example commands.json:

{
"commands": {
"Publish": {
"fileName": "powershell.exe",
"workingDirectory": ".",
"arguments": "-ExecutionPolicy ByPass -File "..\build\publish.ps1" -SolutionDir "$(SolutionDir)""
}
}
}

Current behavior

Upon running the task, the used variable is not being replaced, but used 'as-is'.

Expected behavior

Looking at the code, it should support variable replacing so that it gets populated by the correct value.

Exception when web tools are not installed

Installed product versions

  • Visual Studio: 2015 Professional Update 3
  • This extension: 1.2.31

Description

Installing this extension on a visual studio that doesn't have web tools installed gives an exception when adding a command.

Steps to recreate

  1. Install Visual Studio without web tools
  2. Install the extension
  3. Add a command
  4. Exception

Current behavior

An exception is thrown when adding a command as the task runner is part of the web tools. The Task runner is nowhere to be found in a visual studio that doesn't have web tools installed. As this extension is intended for scripts and commands that are not only web related, it could be surprising, and the dependency is not documented.

Expected behavior

The dependency to web tools should be made explicit to inform the user that it's needed to use this extension.
Long term, the task runner could become a separate module or part of the core Visual Studio as it could be used for other tasks that are not web related.

Bindings not working in VS2019

Installed product versions

  • Visual Studio: Visual Studio 2019 Enterprise
  • This extension: 1.2.41

Description

bindings not working, the commands.json get modified and everything but in the Task Runner Explorer after saving the json file the bind disappear, even though it is in the json file

Steps to recreate

  1. open the task runner explorer
  2. add an after build binding
  3. rebuild the solution
  4. the binding does not run and also disappear from the task runner explorer windows
{
  "commands": {
    "TestCommand": {
      "fileName": "powershell.exe",
      "workingDirectory": ".",
      "arguments": "Start-Process -FilePath \"C:\\Windows\\System32\\cmd.exe\" -ArgumentList \"\/k\",\"C:\\src\\deployment.cmd\" -Verb RunAs"
    }
  },
  "-vs-binding": { "AfterBuild": [ "TestCommand" ] }
}

if you click on run from the task runner explorer it executes correctly

Current behavior

the binding does not run and also disappear from the task runner explorer windows

Expected behavior

run the binding after the build

Variable values are outdated

Installed product versions

  • Visual Studio: 2017 Professional
  • This extension: 1.3.50

Description

If I add a simple powershell script, which only outputs the arguments, I added before, mentioned here:
#13

Steps to recreate

  1. Create new solution with empty project
  2. Add command file to solution
    { "commands": { "example0": { "fileName": "powershell.exe", "workingDirectory": ".", "arguments": "-ExecutionPolicy Bypass -NonInteractive -File example.ps1 \"$(ConfigurationName)\" \"$(DevEnvDir)\" \"$(SolutionDir)\" \"$(ProjectDir)\"" } }
  3. add example.ps1 to solution
    param ( [String]$ConfigurationName, [String]$DevEnvDir, [String]$SolutionDir, [String]$ProjectDir ) Write-Output "Configuration: $ConfigurationName" Write-Output "DevEnvDir: $DevEnvDir" Write-Output "SolutionDir: $SolutionDir" Write-Output "ProjectDir: $ProjectDir"

Current behavior

If I switch from debug to release, the variable is not updated, it still contains "debug".
Also the current project and many more.

Expected behavior

I expect that the variables are up 2 date when the script is running and the configurationName should contain "release", when the current build configuration is "release".

I debugged the extension and saw, that the variables are "compiled" into the task configuration and not updated again, when the task is starting. Only when the file is changed.

It is possible to change that?

I tried to understand it a little bit and it seems that somehow VS catches up the task runner configuration, which contains the complete file. And it runs it when I click on in in the task runner.
There is only one hook, when the commands file changes, there is the possibility to update the configuration.

When you cannot update it right before the task is gonna run,
maybe it's possible to invalidate/update it when one of the Environment Variables will change (e.g. switch build configuration ...)

Is it possible to run WSL shell as the FileName?

Installed product versions

  • Visual Studio: 2017
  • This extension: 1.1.41

Description

I've tried several variations to run the Windows Subsystem for Linux shells from CommandTaskRunner and have been unsuccessful. All variations so far either crash visual studio, say 'wsl' is not recognized as an internal or external command..., or produce an error dialog.

Steps to recreate

Try any of the following as the FileName+Argument pairs in a new command in commands.json.

wsl
wsl.exe
cmd /C wsl
cmd /C C:\windows\System32\wsl.exe
cmd /C C:\windows\System32\bash.exe

If any of these produced a bash shell, or executed a .sh script inside that bash shell, it would be sufficient. Most of them work just fine if I run them from command prompt, but something about the way it's implemented in TaskRunnerExplorer makes them all fail. Perhaps someone who understands TaskRunnerExplorer internals might be able to imagine a working incantation.

Of note, some tutorials I've seen for VSCode say things like this:
add this rule to your User Settings:
"terminal.integrated.shell.windows": "C:\WINDOWS\sysnative\bash.exe"

Feature Request: Expose VS Macros as environment variables

Many use cases for this plugin seem like they would involve passing paths from visual studio to the script. This like SolutionDir, ProjectDir, OutputDir etc. It would be great if there were a way to pass this information from Visual Studio to the scripts it's calling.

Is there some way to do this already that I am missing?

1.2.40 - VS2015/2017 - Doesn't discover the commands.json anymore.

Installed product versions

  • Visual Studio: 2015 Pro / 2017 Pro
  • This extension: 1.2.40

Description

The extension doesn't discover the commands.json anymore. The commands list remains empty even with a commands.json available in the solution.

Steps to recreate

  1. Open a solution with an existing commands.json, and commands defined.
  2. The commands list remains empty even when refreshing.

Current behavior

The extension cannot find the command.json file.

Expected behavior

The extension should be able to find the command.json file, and populate the commands list accordingly.

Task Exit code <> 0 on pre-Build doesn't fail the build.

Installed product versions

  • Visual Studio: 2015 Professional Update 3
  • This extension: 1.2.34

Description

Task failing when bound to pre-build should prevent the build succeeding.

Steps to recreate

Create a .bat that exits with code != 0, bind it to pre-build

Current behavior

Doesn't fail build job

Expected behavior

Should fail build job

Does not work if the Task Runner Explorer is not the active tool window.

Installed product versions

  • Visual Studio: 2017 Enterprise
  • This extension: 1.2.41

Description

Does not seem to work unless the Task Runner Explorer window is active. I, for instance, have the Output pane active on start, so as long as I do not switch to the Task Runner Explorer window, it does not run any commands.

Steps to recreate

  1. Add command to run on project open
  2. Switch to the Output pane and close VS - it seems to remember it the next time it is open.
  3. Now open the solution - it remains on the Output, which should be active now.

Current behavior

The command to be run on Project Open does not run.

Expected behavior

The command to be run on Project Open runs.

Failed to run "C:/.................../commands.json" in Output window

Installed product versions

  • Visual Studio: 2022 preview 3
  • This extension: latest

Description

I'm unable to run any command which works perfectly in 2019.

Steps to recreate

  1. Open an existing configuration, which works fine in 2019.
  2. Refresh task runner explorer
  3. Output window shows error 'Failed to run "C:/.................../commands.json'

Current behavior

Error

Expected behavior

Full functionality as it works in 2019

VS2019 Support

Installed product versions

  • Visual Studio: 2019 Preview 2
  • This extension: 2019-01-29

Description

Website project and dotnet core api projects included in solution. Want to run a .bat file to serve the website. When I choose to add this as a task, it does create the commands.json, but the task does not appear in task runner explorer. Opening the same SLN in VS2017 it does work correctly.

Add VS2019 support please.

1.2.43 - VS2015/2017 - Doesn't discover the commands.json anymore in solutions with website folder projects or twincat projects.

Installed product versions

  • Visual Studio: 2015 Enterprise / 2017 Pro
  • This extension: 1.2.41

Description

Follow up of #21 . The fix helped for solutions where there are C++/CLR projects mixed with C# projects. @spayton reported that it was still not working with website folder projets (File -> Add -> Existing Web Site). I encountered a similar issue with a third party project type (TwinCat).

Steps to recreate

  1. Create a new solution.
  2. Add a new Existing Web Site project or a TwinCat project
  3. Create an empty batch file in the project folder
  4. Add the batch file to the project
  5. Add it to the task runner.

Current behavior

The json file will be succesfully created and added to the solution, but it will be not be loaded by the extension. The following error message will be output in the console:

Failed to run "C:\Users\xxx\Documents\Visual Studio 2015\Projects\ClassLibrary2\commands.json"...

The same file will successfully load in a solution where there are only C# projects.

Expected behavior

The json file should be able to load like in the other kind of solutions.

I'll send a PR right away, the fix is ready.

Feature request: add colour support in output text

I've created a simple ps1 file containing just one line:

Write-Host "Hello World" -ForegroundColor Red

When the script is executed the text is displayed in the task runner console but in white, rather than in red.
Colours are very useful to distinguish the various parts of the output text. Can we please add support to this feature?

Thanks

Simone

Run Commands with Powershell bitness

I noticed that when I run a powershell command, it automatically runs as x86. Is there a way to force task runner to use 64bit instead? I've tried a few things, but nothing seems to be working.

No Intellisense, and COM error on add of new .cmd file.

Installed product versions

  • Visual Studio: 2015 Professional
  • This extension: 1.2.34

Description

I get no intellisense when editing the commands.json file. What's the correct schema for this file?
And I get a COM error when I add a .cmd file by right-click.

Steps to recreate

  1. Right-mouse-click on a .cmd file in Solution Explorer.
  2. Select "Add to Task Runner".
  3. Answer "No" to the prompt to add at the solution level.
  4. COM error:
    image

Current behavior

COM Error.

Expected behavior

No com error

Are visual c/c++ projects (.vcxproj) supported?

Installed product versions

  • Visual Studio: [example 2017 Professional]
  • This extension: [example 1.1.41]

Description

Task Runner Explorer is always empty in my .vcxproj, even when i add commands.json from the README.md of this repo to the solution project root. After looking at source code, I found this line and suspect that it's just silently unsupported for some undocumented reason:

Project proj = projs.Cast<Project>().FirstOrDefault(x => x.FileName.Contains(cmdsDir) && !x.FullName.EndsWith("vcxproj"));

Steps to recreate

  1. Create or open a visual c/c++ project (.vcxproj)
  2. Add a commands.json file from the readme.
  3. Open Task Runner Explorer
  4. Refresh, look for tasks.

Current behavior

The Task Runner Explorer window shows "No task runner configurations were found" message. The dropdown box is empty and deactivated.

Expected behavior

After adding commands.json, I expected that I would be able to run the commands described within it. Seems relatively simple.

If it's not supported, it would be nice to understand why, and I suggest documenting this limitation on the readme. If it's possible that support could be added but it will just take some work, then I can rename this ticket to "feature request...".

Project variables for projects in solution folders aren't applied

Installed product versions

  • Visual Studio: Community 2017 v15.8.4
  • This extension: 1.2.41

Description

I added a simple script with a single parameter under a web project in Visual Studio. I want to pass in the name of the project to the script with $(ProjectName). It doesn't seem to resolve the variable in the SetVariables method. When I use $(ConfigurationName) or $(SolutionDir) it works fine.

When I move the web application out of the solution folders, it works as expected.

Steps to recreate

Create an empty solution
Add a solution folder (two, in my example: Client>Source)
Add an empty web application
Add a script that takes in a single parameter: param([String]$Project = "*")
Set up task runner to pass in $(ProjectName) in the commands.json for the project

I've attached my example solution.

Example.zip

Current behavior

It seems to bypass the project variables when solution folders are present and leaves the variables unresolved in the commands.json file.

Expected behavior

I would expect that regardless of the organization of the projects in the solution, the LoadHierarchy method should be able to parse successfully and resolve all variables for the solution as well as the project.

Feature Request: Currently opened file name as parameter

Installed product versions

  • Visual Studio: 2019 Professional
  • This extension: 1.3.62

Description

It would be nice to be able to pass the currently opened file path (relative or absolute would probably have both their use-cases) to the command.
Currently I have a working batch-file which is able to do a single analysis of a source file and I'd like to integrate this into Visual Studio, but I'm unable to find a method to pass the currently opened file to a command.

I hoped this extension might help, but I haven't been able to get it to work in this way and looking at the source where the solution variables get substituted, it doesn't look like there is a variable available for it.

Task doesn't appear in task explorer anymore

Installed product versions

  • Visual Studio: 2015 Community Update 2 14.0.25123.00
  • This extension: 1.1.22

Description

I added Command Task Runner to a new machine today, but now the task I had doesn't show in Task Runner Explorer

Steps to recreate

  1. Clone https://github.com/JonCubed/angular2-cli-quick-start-aspnet-core-vs2015
  2. Open solution file
  3. Check Task Runner Explorer

Current behavior

No tasks show up in the Task Runner Explorer and I can see any errors (admittedly I'm not exactly sure where I should be looking for them)

Expected behavior

Tasks should show up in the Task Runner Explorer

commands.json not getting refreshed properly.

When I update commands.json to add an additional parameter to the script (-NoProfile in this case), the command doesn't seem to get refreshed. I need to rename the command in order for it to get picked up as a new command, otherwise the original command gets run.

  1. Create a command, e.g.
    "TestCommand": {
    "fileName": "powershell.exe",
    "workingDirectory": ".",
    "arguments": "-Command & { Write-Host 'Test 1' }"
    }
  2. Save commands.json
    • If you already have a list of commands, TestCommand automatically appears in the list.
  3. Right click command -> Run Command
    • Output: Test 1
  4. Update command output to 'Test 2' and save commands.json.
  5. Run again.
    • Output: Test 1
  6. Rename command to "TestCommand2" and save commands.json.
    • TestCommand2 appears in the Task Runner Explorer
  7. Run TestCommand2
    • Output: Test 2

Dependence on "ASP.NET and web development tools" on VS2019 when trying to install

Installed product versions

  • Visual Studio: 2019
  • This extension: 1.3.62

Description

I've been going through your published extensions and I absolutely love them (8 installed so far).

This one though has a problem, it seems to have a dependence on "ASP.NET and web development tools" which is probably an error? I want to use this on my C++ development environment.

1.2.41 - VS2015/2017 - Doesn't discover the commands.json anymore in C++/CLR and C# mixed solutions.

Installed product versions

  • Visual Studio: 2015 Enterprise / 2017 Pro
  • This extension: 1.2.41

Description

Follow up of #20 . The fix helped for .NET solutions with only C# projects, but doesn't with solutions where there are C++/CLR projects mixed with C# projects.

Steps to recreate

  1. Create a new solution.
  2. Add a new C++ / CLR library project
  3. Add a new winforms project
  4. Make the winforms project depend on the C++/CLR one
  5. Close the solution
  6. Open the solution
  7. Create an empty batch file in the WinForms project folder
  8. Add the batch file to the project
  9. Add it to the task runner.

Current behavior

The json file will be succesfully created and added to the solution, but it will be not be loaded by the extension. The following error message will be output in the console:

Failed to run "C:\Users\xxx\Documents\Visual Studio 2015\Projects\ClassLibrary2\commands.json"...

The same file will successfully load in a solution where there are only C# projects.

Expected behavior

The json file should be able to load like in the other kind of solutions.

AngularJS 2 CLI - "ng serve" stdin error

Installed product versions

  • Visual Studio: 2015 Professional
  • This extension: 1.2.32

Description

AngularJS 2 ng commands are throwing an error regarding stdin.

Steps to recreate

  1. Install VS NodeJS project plugin from https://visualstudiogallery.msdn.microsoft.com/68faf8ac-b953-42f5-a908-55555deccf7a
  2. Create a new NodeJS project
  3. Add a commands.json file. "FileName": "cmd.exe", Arguments": "/c npm start". This calls "ng serve" which is the AngularJS 2 CLI command that starts WebPack.

Current behavior

Here is the output:

ng serve
internal/process/stdio.js:82
throw new Error('Implement me. Unknown stdin file type!');
^
Error: Implement me. Unknown stdin file type!
at process.getStdin as stdin
at C:...\node_modules\angular-cli\bin\ng:38:27
at C:...\node_modules\resolve\lib\async.js:44:21
at ondir (C:...\node_modules\resolve\lib\async.js:187:31)
at C:...\node_modules\resolve\lib\async.js:153:39
at onex (C:...\node_modules\resolve\lib\async.js:93:22)
at C:...\node_modules\resolve\lib\async.js:24:18
at FSReqWrap.oncomplete (fs.js:123:15)
npm ERR! Windows_NT 6.1.7601
Process terminated with code 1.
npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "start"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: ng serve
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] start script 'ng serve'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the web-ui package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! ng serve
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs web-ui
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls web-ui
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:...\npm-debug.log

Expected behavior

The ng serve command works OK from a manual CMD prompt, and it would be very handy if it worked from VS. BTW I get the same error with the NPM Task Runner.

Add Variable Indicating Build Success/Failure

Installed product versions

  • Visual Studio: 2017 Enterprise 15.8.9
  • This extension: 1.2.41

Description

When executing solution and project post-build scripts it would be very helpful to pass an argument indicating the success or failure of the build.

[Feature Request] Prevent Post-Build Tasks on Build Failure

Installed product versions

  • Visual Studio: 2017, 2019
  • This extension: 1.3.62

Description

It would be nice to either configure how a post-build task behaves when the build has failed or at least provide a variable to allow scripts to determine their own behavior if a build has failed. We have a rather long running post-build script that doesn't need to execute if the build itself failed and it's a bit of a productivity burden.

Active build configuration

Is it possible to get the current buildconfiguration and pass it as an argument for example

{
"commands": {
"Demo": {
"fileName": "powershell.exe",
"workingDirectory": ".",
"arguments": "-ExecutionPolicy Bypass -NonInteractive -File Demo.ps1 $BuildConfiguration"
}
}

Please add support for Visual Studio 2017

I want to start testing the new VS2017 at work, but it'll be harder without this awesome extension. Is there anything in the extension code that prevents it from working properly in the new Visual Studio?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.