Create tasks in Visual Studio Code per user - visual-studio-code

When I created a Node task for Visual Studio Code it created a tasks.json file inside the .settings folder for the folder that you have open (node-app in this case as shown in the image below). ie: it creates a task per folder.
{
"version": "0.1.0",
"command": "node",
"isShellCommand": true,
"args": ["${file}"]
}
My question is how do you create a task per user rather than a project based task so that I can execute the node code from any folder rather that having to create the same task for each folder you open in Visual Studio Code.
Also how do you execute individual files without opening a folder.

It looks like this will be in v1.42, the January 2020 release. See https://github.com/microsoft/vscode/issues/89343 (user level tasks). And https://github.com/microsoft/vscode/issues/1435.
In addition to having tasks in your .code-workspace file and in
tasks.json in your open folder, you can now have tasks in a user level
tasks.json next to your user settings.json.
Open a folder that has some tasks. The vscode project is a good
example.
Run the Open User Tasks command to create a tasks.json file next to
your user settings.json file.
Add a shell or process type task to the new tasks.json. Only those two
types of task are supported here.
Run the Run Task command and verify that you see your new user level
task. Verify that you can tell that it's a user level task in the task
quick pick. Verify that you can configure your user level task by
clicking the gear next to it in the quick pick. Verify that you can
run the user task.
It is in the Insiders' Build already so presumably v1.42.
------- From the 1.42 release notes:
User level tasks
Tasks declared in tasks.json are now supported at the User Settings
level. If you have a build script that you use across many projects,
or if you don't want your tasks in a project folder, you can add your
tasks in the user tasks.json file. You can run the Tasks: Open User
Tasks command to create user level tasks. These tasks will be
available across all folders and workspaces. Only the shell and
process task types are supported here.

Related

How can I choose my own build file in vs code?

It`s my first steps in Haxe)
I need to build task with my own build task in VS code. I know that I can choose build task to run by using Shift+Ctrl+B, but no drop down list opens... And when I did find the list, my assembly file was not there...
If you don't define a task in tasks.json then Shift+Ctrl+B will not show you anything.
If you have different configuration files you can use Command Variable and the command extension.commandvariable.file.pickFile to create a QuickPick list of files to choose from and use it as an argument to Haxe

Azure Pipelines: building a C++ project with outside "Include Directories"

I tried searching with as many different terms as I could and couldn't find exactly what I'm looking for.
I have a C++ Project developed in Visual Studio 2019 and I am trying to build and deploy it in Azure Pipelines. It uses Boost and OpenCV. I skipped trying to include these in Azure Artifacts because of a rabbit hole with Azure CLI errors that took me almost half a day.
So it seems that there is a task to publish pipeline artifacts in the .yml file. How do I do this when my project needs to reference a certain directory, instead of one specific file or .dll? Here are images for how this is configured in Visual Studio:
include directory for boost image
include directory settings for opencv image
Edit: Still trying, see my comment. Thinking about switching over to CircleCI.
I found out what to do. Hopefully no one else wastes as much time as I did.
The key was MSBuild. One needs to first find out the values of $(IncludePath) and $(LibraryPath) by doing the following first in Visual Studio:
Right-click on your project, choose "Properties"
Go to the Build Events tab, and click "Pre-Build Event"
Click on and expand the Command Line row, and click "Edit"
Now click the button that says "Macros>>"
You will see a bunch of different variables and their values. Find the values for LibraryPath and IncludePath, copy and past them into a text file.
Now, assuming you already set up a local agent, follow these steps:
Put the text file in the root folder of where your agent is installed. For me, this was "C:\agents"
Have the first line be "LibraryPath=value" and the other line be "IncludePath=value". Use double slashes for the directory paths.
Rename the file to .env. If the agent is currently running, restart it so it can read in the environment variables it will use during your build.
In the MSBuild task of your pipeline, specify arguments. For my case, it was simply this: /p:IncludePath="C:\Program Files\boost_1_77_0;$(IncludePath)" /p:LibraryPath="$(LibraryPath)"
Run the pipeline. You can check your completed build on the local machine. For me, the path it kept going to was "C:\agents_work\2\s"

VS Code User tasks.json

I've got a handful of custom tasks in VS Code that I want to share across multiple projects. The tasks are currently installed in $PROJECT_DIR/.vscode/tasks.json.
Where should I put my tasks file so that it is loaded by VS Code for all projects (I'm thinking something similar to User vs Workspace settings)?
I've tried ~/.vscode/tasks.json (I'm not sure if this is a location that VS Code uses or if it's something I created ages ago) and also $HOME/Library/Application \Support/Code/User/tasks.json (this is where custom settings.json and keybindings.json etc. are stored). Neither of these locations works.
At the moment, it seems like I can only have custom tasks defined in each workspace rather than globally. I couldn't see anything in the official documentation. Any pointers welcome?
To answer the specific question about the location of the "user tasks" tasks.json file:
In Ubuntu, it's in ~/.config/Code/User/tasks.json
In Windows WSL, it's in /mnt/c/Users/<username>/AppData/Roaming/Code/User/tasks.json
[feel free to edit if you know the location in Mac or other systems]
This question is a duplicate of Create tasks in Visual Studio Code per user but I cannot mark it as such as that has not been upvoted or accepted yet. Reproduced here:
It looks like this will be in v1.42, the January 2020 release. See https://github.com/microsoft/vscode/issues/89343 (user level tasks). And https://github.com/microsoft/vscode/issues/1435.
In addition to having tasks in your .code-workspace file and in
tasks.json in your open folder, you can now have tasks in a user level
tasks.json next to your user settings.json.
Open a folder that has some tasks. The vscode project is a good
example.
Run the Open User Tasks command to create a tasks.json file next to
your user settings.json file.
Add a shell or process type task to the new tasks.json. Only those two
types of task are supported here.
Run the Run Task command and verify that you see your new user level
task. Verify that you can tell that it's a user level task in the task
quick pick. Verify that you can configure your user level task by
clicking the gear next to it in the quick pick. Verify that you can
run the user task.
It is in the Insiders' Build already so presumably v1.42.
------- From the 1.42 release notes:
User level tasks
Tasks declared in tasks.json are now supported at the User Settings
level. If you have a build script that you use across many projects,
or if you don't want your tasks in a project folder, you can add your
tasks in the user tasks.json file. You can run the Tasks: Open User
Tasks command to create user level tasks. These tasks will be
available across all folders and workspaces. Only the shell and
process task types are supported here.

How to setup a task.json used by all folders (VS Code)

I don't want to set every time I start a project (Folder) a new ./.vscode/task.json.
Could this file be global as keybindings.json?
Or at least can I create my own template that would show up when I Configure Task Runner
Not possible at the moment.
There is an open issue at this purpose:
https://github.com/Microsoft/vscode/issues/2775

Custom action after ClickOnce deployment / publishing

How can I run custom script which will upload ClickOnce deployment files to a web-server (in my case Windows Azure Blog Storage) right after publishing? Is it possible to modify MSBuild file in some way so it would run custom script right after ClickOnce published files into a local folder?
Yes, you can hook to build process using various technics:
pre and post build actions ( from visual studio project properties menu). It's actually exec task hooked into your project file
you can override your DependsOn property for concrete target and append execution of your own target (pre-Msbuild 4.0 way)
you can declare your target and hook with AfterTarget\BeforeTarget attributes (Msbuild4.0 way).
As for uploading something to blob - you can use Exec task in your own target to upload or use whatever tool\script you usually use to uploading files to website\Blob storage.
NB: You could clarify your question with following points (if you need more concrete answer) :
what kind of build process you are using - build from VS, CI server with custom msbuild script, CI server that building your sln file etc
what kind of script\tool you want to execute to upload build result.
do you know the name of last executed msbuild target, after which you want to fire your tool.