I have a powershell file (script.ps1) that is in some of my visual studio solutions. The script contains utility functions for the project.
At the moment, I just open the nugget package manager and copy and paste the content of the script and it runs fine. I can run the functions correctly from the nugget package manager. But this has to be done, each time I open the solution.
Is there a way to get this handle automatically each time I open the solutions?
Rather than copy pasting the entire thing, you can dot source the file
. ".\script.ps1"
Related
I am trying to use PowerShell to install a VSCode extension from a local file (not from the internet).
When I use Start-Process and give the appropriate file path, it opens VSCode, stalls the script, and does not install the extension. When I close VSCode, the script terminates without error, but still the extensions is not installed.
I need the exact syntax to install a VSCode extension from PowerShell silently (no new window).
I've tried just about every syntax variation.
Thanks
Instead of using Start-Process, call the default name for VS Code: code. VS Code has some nice CLI options when you call this, one of which is --install-extension. Heres an example of what you can call in powershell or in a .ps1 script that would do this:
code --install-extension path/to/extension.ts
or if you have made an extension pack to help automate the install of multiple extensions at once:
code --install-extension path/to/extensionPack.vsix
I have installed visual studio 2019 which works fine for c++ but unable to create folders and sections to store multiple code files. So thought of switching to visual studio code and followed all tutorials available on youtube and documentation. But Visual studio IDE has got nothing showing up when Run Build task is initiated, which is expected to show the c++ extension downloaded. Mingw64 is installed and checked in the terminal too.
no output or terminal opened on Run
compiler installation checked
From the image attached regarding no output in the terminal or terminal opened, it looks like the exe is made because it says 'Build finsihed succesfully'. You'll need to run this executable from the terminal.
For this, if youre in the same directory all you have to do is type the filename. helloworld.exe in the cmd, if its powershell, then ./helloworld.exe. (Also note that for exe files you dont need to explicitly mention .exe at the end of the file name)
The powershell method should work on cmd too.
And if youre not in the same directory as the executable, you can either change directory by typing cd path/to/file and proceed as above, or run directly by typing path/to/file/helloworld.exe. where path/to/file is the directory of your helloworld.exe file
I was given a PowerShell script, that when opened in a text editor, is one very long line of code. Is there any kind of auto-format tool for PowerShell syntax? I use Notepad++ and read a thread here (https://superuser.com/questions/58884/auto-format-document-with-notepad)and here (PowerShell Code Tidy or Reformat?) about certain plugins that can help with indentation and other code cleanup, but nothing that I've seen that can take one long line and tidy it.
Thanks.
I'd suggest using Visual Studio Code with the PowerShell extension. From there, you can utilize the Format Document tool (default keybind: SHIFT+ALT+F). This will look at your settings file and uses PSScriptAnalyzer to perform the formatting rules.
With the newest update (June2018), Visual Studio Code supports fully portable downloads by downloading the .zip option and creating the /data/tmp/ directory in the root where code.exe lives.
Visual Studio Code
PowerShell extension releases
Microsoft recommendations
I have Powershell files in the same folder with a number of helper functions. Unfortunately the Visual Studio Code editor does not recognize those functions when using intellisense. How do I import reference libraries and get VSCode to search those files ?
If you want the code available to intellisense you have to load it into one of two places, either the PowerShell Integrated Terminal or your editor. In your case though, if you need it loaded all the time I would simply dot source those files in the VS Code PS Profile. You can create this simply by going to the PS Integrated Terminal and using New-Item $PROFILE -ItemType File -Force and it will create a Microsoft.VSCode_profile.ps1. Anything you add in that file will get loaded into the editor and PS Integrated Terminal upload startup.
More details on the whole engine and how intellisense works in VS Code...
The reason this works is that the main engine in the PowerShell extension is the PowerShellEditorService. This is the engine that creates the host behind the PS Integrated Terminal, and the PS features you have in the editor itself (e.g intellisense, script analyzer, etc.).
You can see an example of this by adding Import-Module somemodule to a new file in VS Code that has not been loaded into the PS Terminal. It can take a few seconds but after the engine loads the module you will have intellisense for that module. Just like you will your code.
Prior to adding the commands in that editor I verified that the module was not loaded. After adding the import command and then using a command from that module the module gets loaded in the background. You can then see the module was loaded:
I'm currently evaluating using VS2013 for a HTML5 project.
In this project I would like to be able to run a command line tool every time a file is saved (and have the file path passed as argument to the command line tool), and then have the output displayed in the console in VS. It's also important that this setup can be part of the project file, so that when a developer opens the project it's already setup correctly and ready to go without any additional configuring in VS.
In both Sublime Text and Webstorm projects all this is easy to achieve, but I haven't been able to find anything similar in Visual Studio. Any tips would be much appreciated!
You can set a DocumentSaved handler with Visual Commander and run a tool. See the "2. Run Cppcheck on the saved file and show results in the Output window" extension sample.