VS Code tasks 2.0 troubles - task

I use:
VS Code 1.14.1
Tasks 2.0
node 6.11.1
My problem is that some tasks are working, and some are not.
Here my tasks.json file.
{
"version": "2.0.0",
"tasks": [
{ // This task work fine.
"label": "tsc",
"type": "typescript",
"tsconfig": "tsconfig.json",
"group": {
"kind": "build",
"isDefault": true
}
},
{ // This task work fine.
"taskName": "css",
"type": "shell",
"command": "./scss.sh",
"windows": {
"command": "./scss.cmd"
},
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{ // This task not work. (See output #1 below)
"taskName": "npm-install",
"type": "shell",
"command": "npm install",
"problemMatcher": [],
"presentation": {
"reveal": "always",
}
},
{ // This task not work. (See output #2 below)
"type": "gulp",
"task": "clean",
"problemMatcher": []
}
]
}
Output #1 - When I try to run npm task with type shell\npm, I get the same result:
> Executing task: npm install <
Usage: npm <command>
where <command> is one of:
access, adduser, bin, bugs, c, cache, completion, config,
ddp, dedupe, deprecate, dist-tag, docs, edit, explore, get,
help, help-search, i, init, install, install-test, it, link,
list, ln, login, logout, ls, outdated, owner, pack, ping,
prefix, prune, publish, rb, rebuild, repo, restart, root,
run, run-script, s, se, search, set, shrinkwrap, star,
stars, start, stop, t, tag, team, test, tst, un, uninstall,
unpublish, unstar, up, update, v, version, view, whoami
npm <cmd> -h quick help on <cmd>
npm -l display full usage info
npm help <term> search for help on <term>
npm help npm involved overview
Specify configs in the ini-formatted file:
C:\Users\usr\.npmrc
or on the command line via: npm <command> --key value
Config info can be viewed via: npm help config
npm#3.10.10 C:\Program Files\nodejs\node_modules\npm
Output #2 - When I try to run gulp task I get next (gulp package installed as global (npm install gulp -g),(I have gulpfile.js with correct content)):
> Executing task: node_modules\.bin\gulp.cmd clean <
clean: node_modules.bingulp.cmd: command not found
I can use gulp, npm, node and other tools from cmd as usually, and it's works fine, but not in the VS Code.
Current solution of this thing:
Create batch files for each stuff.
Create shell task for each batch file (as scss.cmd)
Run those tasks.
Yep, it works well, but you need to do too much action for simple tasks.
What can you advise in this regard?

I found a solution to this problem, the problem was in the default terminal application.
By default on Windows OS visual studio code use powershell as terminal app, in my case, I changed it to the git-bash app and got this problem. After that I changed it back to powershell and all works fine.
I did not bother about why gitbash does not work, it is possible that additional configuration is required in the configuration in the vs code.

This is an issue in VS Code. A < gets added at the end of commands, making them fail. There doesn't seem to be a direct fix at the moment.

Related

Electron-builder release tries to publish to Github and complains about GH_Token

running the release script without publish option tries to publish the build to GitHub ( and fails while complaining about not being able to find GHToken! )
Error: GitHub Personal Access Token is not set, neither programmatically, nor using env "GH_TOKEN"
Setting "publish": "never" will fail also complaining about not being able to find module electron-publisher-never!
Error: Cannot find module 'electron-publisher-never'
It all happens while the project is built but build scripts exits non-zero!
I'm using the latest version of electron-builder.
my build script:
"build": {
"appId": "eu.armand.[****]",
"copyright": "Copyright © 2017 mim_Armand",
"productName": "[****]",
"mac": {
"publish": "never",
"category": "public.app-category.[****]",
"icon": "assets/icons/mac/icon.icns"
}
Any idea what's going on or if I'm doing it wrong?!
,m
try building with
"build": "electron-builder --publish never"
to never publish.
rename your script to something else.
if the script name is release → publish is set to always
the documentation states this:
CLI --publish option values:
...
If npm script named release, — always.
Add to scripts in the development package.json:
"release": "build"
and if you run yarn release, a release will be drafted (if doesn’t
already exist) and artifacts published.
I solved it this way, because I didn't need to put it in any repository
"build":{
"appId": "XXX",
"productName": "XXX",
"directories":{
"output": "build"
},
"win":{
"target": "nsis",
"publish" : []
}
}
https://www.electron.build/configuration/publish

How to run asp.net mvc 4.5 in visual studio code editor?

I am looking forward to run asp.net mvc apps in vscode but it seems that the only pages that I found on google is with asp.net core which is not what I am looking. Can someone guide me with some steps, I installed some plugins like c# and msbuild. After attempt to run it. it display the following error:
"Failed to launch external program msbuild . spawn msbuild ENOENT"
The error Failed to launch external program msbuild . spawn msbuild ENOENT happens because vscode\task runner cannot find msbuild.
To run asp.net mvc 4.5 in visual studio code editor, you will need to install msbuild tools (I have installed the 2017 version) and IIS Express.
You could use vswhere to check msbuild location, in my case is C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe
In vscode execute the command Tasks: Configure Task Runner and edit the content of tasks.json according the file.
{
"version": "0.1.0",
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"windows": {
// change according your msbuild location
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
{
"suppressTaskName": true,
"taskName": "iisexpress",
"isShellCommand": true,
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args": [
// change according your project folder and desired port
"/path:${workspaceRoot}\\MyProjectFolder",
"/port:51714"
],
// Show the iisexpress output always.
"showOutput": "always"
}
]
}
You don't need to restart your IIS on every change, you just need to build the application CTRL+SHIFT+B.
If you wan't to stop IIS use the vscode command Tasks: Terminate Running Task.
References:
https://stackoverflow.com/a/42719644/5270073
https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line
I've created a gulpfile that handle the build for me:
It starts an IISExpress instance.
Refresh my browser on razor code change.
And automatically rebuild my application when I change C# code.
You can find the gulpfile on my project's Github
As per VS Code documentation, VS Code does not support debugging applications running on the Desktop .NET Framework. The ASP.NET MVC Application (though ASP.NET Core is supported) are not recognized by VS Code. Hence VS Code is lightweight tool to edit a file, they are recommending to use Visual Studio Community.
For Visual Studio Code 1.30.2 I've got it configured to build and run my ASP.NET applications in IISExpress using the following setup.
Terminal -> Configure Tasks
Then select Create tasks.json file from template entry.
Once you do that then select the MSBuild template
This will create the default MS build task template.
You should be able to copy the following to the task.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
//Task for building your ASP.NET Solution
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build"
],
"windows": {
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "always"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
//Task for running App in IIS Express
//You can add additional projects here if you want to run more than one project in IIS Express
//For example this shows how I'm running my WebApp and API locally in IIS Expresse
{
"label": "iisexpress-WebApp",
"type": "shell",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args":[
"/path:${workspaceRoot}\\Web",
"/port:52945"
],
"presentation": {
"reveal": "always"
}
},
{
"label": "iisexpress-API",
"type": "shell",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args":[
"/path:${workspaceRoot}\\Api",
"/port:49243"
],
"presentation": {
"reveal": "always"
}
}
]
}
Once you save the file just hit Ctrl + Shift + B and select the Build task from the window. If all goes well you should see the output displayed in the terminal below.
Then to spin up your Apps in IIS go to Terminal -> Run Task
That window will then show your IIS Express tasks, select the one you want to spin up and you should see the Output window show IIS starting up. Once that is successful just open your browser and navigate to localhost:{portyouconfigured} and you should see your application running.
I know I'm a little late, but after researching this myself in 2019, I think using VSCode's tasks is a better approach.
Create a tasks.json file inside your project's .vscode folder, this is where the below code will live.
Add the following script to tasks.json, I'm using this to build the project and then run iisexpress.
Once saved, you can run the Build & Run Server task by pressing pressing CTRL+SHIFT+B. You can also just access the available commands with CTRL+SHIFT+P and search for task: run build task.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build & Run Server",
"dependsOrder": "sequence",
"group": "build",
"dependsOn":["Build ASP.NET", "Run IIS EXPRESS"]
},
{
"type": "shell",
"label": "Build ASP.NET",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"windows": {
// change according your msbuild location
"command":"${env:ProgramFiles(x86)}\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\msbuild.exe"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
{
"type":"shell",
"label": "Run IIS EXPRESS",
"group": "build",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args": [
// change according your project folder and desired port
"/path:${workspaceRoot}\\VSSMVCProj",
"/port:59010"
],
// Show the iisexpress output always.
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
}
],
}
Since Visual Studio Code 1.14
There is a new syntax to create tasks.
In your Menu Click on
Terminal -> Configure Tasks
Create a task in vscode that build your project like so:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"args": [
"${workspaceRoot}\\Some\\Window\\Path\\ToSolution.sln",
"/target:Build"
],
// Path to your msbuild
// The path used corresponds to the path provided by a Visual Studio 2017 installation.
// To find it your msbuild path, go in your file explorer, and search for "msbuild.exe".
"windows": {
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
"problemMatcher": "$msCompile"
}
]
}
The path used corresponds to the path provided by a Visual Studio 2017 installation.
To find it your msbuild path, go in your file explorer, and search for "msbuild.exe".
I would better recommend you installing dotnet cli to get started on it within 10 minutes as page says. If you're using Linux as I was using CentOS and followed the steps below in terminal:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.2
To confirm if dotnet-cli installed successfully:
dotnet
The commmand below sets up a basic asp.net web application in myWebApp folder:
dotnet new webApp -o myWebApp --no-https
cd myWebApp
Simply type dotnet run in terminal to run your first asp.net app This makes your first project run sucessfully. In my opinion, this would work better with Visual studio code than any other method. I use this link source

How to create release channels with electron/electron-builder?

I have an Electron app where I want to introduce parallel release channels: stable, next (for early adopters) and dev (for testing the latest build).
These will have a branch each, with new features appearing first in dev, progressing to next for beta testing and finally moving into stable.
I'm using electron-builder to make these release packages, and I want each to have its own auto-updates - so when I publish a new next release all the users with it get the update.
I want the applications to be independent - a user can have two channels installed and run both at the same time. They'll have different names and different icons.
I can manually set these up in the branches, but really I want to automate this as much as possible - a publish from the next branch should use the right name, icons, IDs and updater without risk of it going to the wrong channel.
Is there a way to do this with electron or electron-builder?
It's possible with electron-builder. I would have several build configurations and tell electron-builder which to use when building.
For example, create file config/beta.json with the following setup:
{
"appId": "com.company.beta",
"productName": "App Beta",
"directories": {
"buildResources": "build/beta" // directory containing your build-specific assets (e.g., beta icons - icon.icns, icon.ico & background.png)
},
"mac": {
"category": "public.app-category.finance"
},
"win": {
"target": [
"nsis"
]
},
"nsis": {
"perMachine": false
},
"publish": [
{
"provider": "s3",
"bucket": "com-app-beta" // dedicated S3 bucket for each build
}
],
}
And duplicate config/beta.json for next.json and current.json (make sure to edit settings accordingly).
In package.json, add the following build scripts (note --em.name=app-beta to overwrite package.json's "name" value):
{
"scripts": {
"build": "build -owl --x64 --config ./config/current.json -p always --em.name=app",
"build-beta": "build -owl --x64 --config ./config/beta.json -p always --em.name=app-beta",
"build-next": "build -owl --x64 --config ./config/next.json -p always --em.name=app-next"
}
}
Run build script when ready to deploy:
npm run build-beta
Using electron-builder version 20.15.1 and MacOS, #Jon Saw's solution needs a minor change because em option is not valid:
"build-beta": "build -owl --x64 --config ./config/beta.json -p always -c.extraMetadata.name=app-beta"

How to expose node binary to electron app without install node

I build an Electron app with plugin system based on yarn (installed as node module), since I don't want to force users to install node or npm.
Some plugins depends on modules with postinstall script "node index.js".
This script failed because node doesn't exists.
Since Electron contains some version of node I thought to add the directory with electron's node to PATH, but I can't find the node binary in packaged app.
I missed something?
Can you think about any other workaround?
I use electron-packager on mac.
I don't think it's relevant to issue but here the main part of install function:
var modulePath = join(__dirname, '../', 'node_modules', 'yarn', 'bin', 'yarnpkg')
var args = ['add', `${plugin.name}#${plugin.version}`, '--json' ]
var child = fork(modulePath, args ,{ silent: true, cwd: this.pluginsPath })
process info:
{
"PATH": "/usr/bin:/bin:/usr/sbin:/sbin",
"versions": {
"http_parser": "2.7.0",
"node": "6.5.0",
"v8": "5.3.332.45",
"uv": "1.9.1",
"zlib": "1.2.8",
"ares": "1.10.1-DEV",
"modules": "50",
"openssl": "1.0.2h",
"electron": "1.4.5",
"chrome": "53.0.2785.113",
"atom-shell": "1.4.5"
}
}

VSCode: how does tasks work?

After digging into VSCode's documentation and playing with the tasks, I'm not sure I understand how tasks are definied.
I'd like to call my grunt tasks from VSCode. The problem is that I'm using a plugin called "load-grunt-config" which makes loading of grunt plugins automatic (no need to type grunt.loadNpmTasks() for each plugin you use), and makes it easy to have each plugin's configuration defined in its own file.
So my gruntfile is almost empty and tasks are defined in a file grunt/aliases.js, and configurations for each plugin is separated in its own file (for eg. grunt/connect.js contains the configurations for the connect plugin).
When typing "run tasks", it shows every task available (including builtin ones, like svgmin, imagemin,...) so it's a total of 30 or 40.
No only it's slow but it also shows tasks I haven't defined and do not directly use.
(type grunt --help to see what it shows).
Is there a way to only show aliases I have defined ?
What's the point of defining the task into the tasks.json file ?
Is there a way to dirrectly run a task without having to list all tasks ? (there are shortcuts for "build" & "test" tasks so you can type "run test" and it will run the test task but is there a way to define new tasks that will appear there too ?)
VSCODE V0.7.0 TASKS SHORTCUTS
Gulp, Grunt and Jake are autodetected only if the corresponding files are present in the root of the opened folder. With the Gulp tasks below, the sub-tasks optimize for serve-build, and inject for serve-dev, run additional sub-task and so forth and so on... This process makes two top-level tasks available for build and dev workflows.
gulpfile.js
//automate build node server start and restart on changes
gulp.task('serve-build', ['optimize'], function () {
serve(false /* is Build */);
});
//automate dev node server start and restart on changes
gulp.task('serve-dev', ['inject'], function () {
serve(true /* is Dev */);
});
The above Gulp tasks will be autodetected by VSCode as will many others.
However, you can manually define two keyboard shortcut tasks for TEST and BUILD in your tasks.json file. Subsequently, you can run TWO top-level tasks with CTRL-SHFT-T and CTRL-SHFT-B respectively.
tasks.json
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "serve-dev",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"args": []
},
{
"taskName": "serve-build",
"isBuildCommand": false,
"isTestCommand": true,
"showOutput": "always",
"args": []
}
Notice the two properties isTestCommand and isBuildCommand. These directly map to CTRL-SHFT-T and CTRL-SHFT-B. So you can map any task to these keyboard shortcuts depending on your needs. If you have more than one task with these properties set to true VSCode will use the first task in the tasks.json file.
With tasks structured and nested properly you should be able to build your workflows with two keyboard shortcuts and avoid having VSCode enumerate your tasks each time via the CTRL+SHFT+P menus.
suppressTaskname
There's a global property suppressTaskName that can be used in the tasks.json. This property controls whether the task name is added as an argument to the command.
I'm not sure if this can help but it's good to know about. It looks like this a way to pass built-in arguments to the task runner. More here Task Appendix. I haven't had a chance to test this to determine how if differs from the traditional "args:[]" property. I know that prior to v0.7.0 there were problems with args that when is was used the arguments and tasknames had to be reversed. See accept args the task name and args had to be reversed
The showOutput property can also be useful with and without the with problemMatcher property for display output in the VSCode Output window.
{
"version": "0.1.0",
"command": "gulp",
"showOutput": "silent"
"isShellCommand": true,
"args": [
"--no-color"
],
"tasks": [
{
"taskName": "gulp-argument",
"suppressTaskName": true,
...
},
{
"taskName": "test",
"args": [],
"isBuildCommand": true,
"showOutput": "always",
"problemMatcher": "$msCompile"
...
},
{
}....
]
}
Following are a couple of other StackOverFlow theads on VSCode tasks:
Define multiple tasks in VSCode
Configure VSCode to execute different task
links

Resources