How can I choose my own build file in vs code? - visual-studio-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

Related

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.

vNext build System.Activities.statements.writeline

I am tasked with writing a file to include with the source code after a build.
With xaml, I used System.Activities.statements.writeline so that I could bundle everything in the build template. I know that I can use PowerShell or a batch to achieve what I need however I do not have access to the build box and I do not want to force my developers to include files not associated with the application in source control.
Is there a way to create a file and add text with a build task and not be dependent on anything other than the build tasks?
Thanks,
Use the PowerShell task and choose "Inline Script". You can then write any script you want in there.
However, I'd make the case that it should be source controlled. Files required for your build and deployment processes are part of the application, if you think in terms of DevOps.
You can custom build task and do that in the build task script directly.
Add a build task

How to determine if a build is from the editor or command line?

I am building a C++ solution with Visual Studio 2005.
Sometimes I open the solution in Visual Studio and build it from within the development environment. Other times I build it from the command line using msbuild.exe. I'm wondering if there is a way that I can determine which of these two types of builds I'm using at compile time (for example, a macro or something like like that). I want to change the path of my output files based on this determination. So, if I'm building from within Visual Studio I would put my output files in FolderA but if I'm building from the command line I would put my output files in FolderB. Is this possible?
Perhaps you can pass in a command-line parameter when building from the command-line that would indicate you are building the solution from the command-line. Otherwise, you can assume you are building from within Visual Studio.
I don't have the answer to your general question, but in order to change the output path, have you thought of adding project configurations ? You could copy project configurations and update the output path of the new ones.

Copy file to the App Resources directory if debug configuration is selected

I need to copy a few files into the App's Resources directory during debug builds. I am thinking about using build rules but don't know how to determine if the build is a debug build. I do have a compiler option of "DEBUG" set.
You can use a Run Script build phase to do the copying. All build settings applied when building the target are available via environment variables in your script.
You can determine what configuration is being built via the CONFIGURATION environment variable; you can look at other environment variables like BUILT_PRODUCTS_DIR to determine where to put your resource. If you specify your Run Script build phase's output correctly, it will only be run when the output needs to be brought up to date, not every time you build.
More information on Run Script build phases is available here: Xcode Build System Guide: Build Phases: Run Script Build Phase
The same kind of thing can be done with script build rules, which is useful if you have multiple resources you want to apply this to: You can create a script build rule that matches your extension (e.g. *.myresource) and use the build settings and input files that are passed to your script via environment variables to do the actual copying. If you specify your build rule's output correctly, it will only be run when its input is newer than its output, not every time you build.
More information on script build rules is available here: Xcode Build System Guide: Build Phases: Build Rules