How to execute code when user uninstalls your VSCode Extension? - vscode-extensions

I read the entire visual studio code extensibility documentation and didn't find something like that. I wanna do a clean up, not when extension is deactivated but when it is uninstalled. I also try using the "uninstall" and "postUninstall" scripts fields from package.json but it didn't execute the scripts. Is this even possible?

This was just added in v1.21: Extension uninstall hook
If your extension has some clean ups to be done when it is uninstalled from VS Code, you can now do that by registering a node script to the uninstall hook vscode:uninstall under scripts section in extension's package.json.
{
"scripts": {
"vscode:uninstall": "node ./out/src/lifecycle"
}
}
This script gets executed when the extension is completely uninstalled from VS Code which is when VS Code is restarted (shutdown and start) after the extension is uninstalled.
Note: Only Node.js scripts are supported.

Related

SignalR: Cannot get js libraries in Visual Studio 2017 project

Trying to following this tutorial to get basic SignalR working:
https://learn.microsoft.com/en-us/aspnet/core/tutorials/signalr?tabs=visual-studio&view=aspnetcore-2.2
I am using Visual Studio 15.9.7
the tutorial includes the instructions below, but when I follow them, the modal window disappears without any kind of message and I do not have the signalr javascript libraries anywhere. The lib/signalr folder isn't extracted into my application. Nothing.
I looked around to try and figure out where to download them manually. Nothing.
I tried running all the Package Console commands to try and get signalR. like this one: npm install #aspnet/signalr
Nothing.
Is there an easy and proven way to just get these js libraries?
In Solution Explorer, right-click the project, and select Add > Client-Side Library.
In the Add Client-Side Library dialog, for Provider select unpkg.
For Library, enter #aspnet/signalr#1, and select the latest version that isn't preview.
Add Client-Side Library dialog - select library
Select Choose specific files, expand the dist/browser folder, and select signalr.js and signalr.min.js.
Set Target Location to wwwroot/lib/signalr/, and select Install.
Add Client-Side Library dialog - select files and destination
LibMan creates a wwwroot/lib/signalr folder and copies the selected files to it.
Firstly, you can try to update your Visual Studio and check if it can help fix the issue.
Besides, to add the SignalR client library to the project, we can also use LibMan Cli command.
Run the following command to install LibMan (if not installed it before)
dotnet tool install -g Microsoft.Web.LibraryManager.Cli
Run the following command to get the SignalR client library
libman install #aspnet/signalr -p unpkg -d wwwroot/lib/signalr --files dist/browser/signalr.js --files dist/browser/signalr.min.js

npm hangs when called in Visual Studio prebuild events

Why when running the commands below in the cmd (and the current directory being the root of my visual studio project), everything is okay :
npm install
webpack --config webpack.config.vendor.js
webpack
But when asking to run that in my ASP.NET Core 2.0 with Visual Studio 2017 it hangs on the first line (while it does not require any user input).When I am saying it hangs, it hangs for about 3-5min (after executing the last line using call), like doing literally.
I managed to get a bit further by using call on each of them (which is suggested by the MS documentation for calling .bat scripts):
call npm install
call webpack --config webpack.config.vendor.js
call webpack
For some reasons it works and hangs only on the last line.
When trying out something simple like echo there everything is fine, I don't really get what is wrong with the lines above.
[EDIT]
ALready checked that out npm hangs on any command
But my issue seems to be different since it can run cmd and PowerShell (but hangs whenever it is run in an ISE PowerShell tab...)

Visual Studio 2017 not restoring packages on save

IN VS2017 I have a quick node.js "Hello world" project. The installed template for node.js includes using NPM via an included package.json I am editing the package.json file to include new dependencies. Upon saving package.json VS is supposed to install any new packages that are included.
I started with the project template: Other Languages\TypeScript\Node.js
I confirmed that the option is enabled for Restoring npm packages on save of package.json
But no matter what changes I make to package.json VS won't run npm and install the missing packages. Also if I build or run VS won't automatically install the missing packages. I can right click on npm and select Install Missing Packages which does work.
What am I missing?
Restore on Save for NPM packages currently doesn't work in NPM projects. I'm still tracking down the root issue, but I did come across a discussion where they (the NTVS folks) wanted to opt out of some behaviors for Web projects.
There are some context menu options on the npm or individual package nodes to restore/update/etc. You could also create new keyboard shortcuts for these context menu items, but I don't know of a way to make Ctrl+S work.
I'm following up internally to revisit these decisions, but in the meantime, send in feedback so that we have some customer data to point to!

Toolbar missing when running ASP.NET core from Visual Studio Code

Environment: Ubuntu 16.04, .NET Core 1.10 (1.0.0-preview2-1-003177), Visual Studio Code 1.8.1
I just generated a new ASP.NET Core app. When I run the app from a terminal window, the start up web page gets displayed as expected.
$ cd MyApp
$ dotnet run
However, the web page is slightly different when I load MyApp folder from VSC and press F5 to debug it. Specifically, the default top toolbar is missing. Toolbar items such as Home, About, Contact, etc. line up in a single column.
I have compared the generated html between the two. When run from the command line, the stylesheet links are:
href="https://ajax.aspnetcdn.com/ajax/bootstrap/3.3.6/css/bootstrap.min.css"
href="/css/site.min.css"
When run from VCS, the links are:
href="/lib/bootstrap/dist/css/bootstrap.css"
href="/css/site.css"
On examining local file structure, I see file css/site.css is present under folder wwwroot. However, I don't see any lib folder at all.
More information. Turns out _Layout.cshtml adds links based on environment names. When the names are Staging and Production, the generated bootstrap link is for ajax.aspnetcdn.com. For "Development," the link is "/lib/xxx."
Wondering how I force VCS to automatically populate bootstrap.css into lib directory.
Problem solved. When the website is generated, a file, bower.json, is created. This file has information about the bootstrap package. However, for some reason, this package is not automatically downloaded. You need to do the following:
From VSC, install the bower plugin by running "ext install bower."
Press F1 and type Bower. Next type, "Bower Update."
This is it. The plugin will download the bootstrap package and populate it in wwwroot/lib directory. Now, the website would work as expected from within VSC.
Hope the next version of VSC will have bower integrated.
It seems like when your app runs from VS Code, it is not serving the CSS files.
To troubleshoot further, looking at the launch.json, project.json, and Startup.cs files is necessary. My guess is that your launch.json is setup to run under a slightly different configuration than your dotnet run command is from the terminal. That is resulting in...
not serving static files at all, or
not including CSS files in the app's build output.
From your question update, the problem is that your launch.json is running under in the Development environment and your terminal is running under the Staging or Production environment. The former serves bootstrap locally; the latter serves it from a content delivery network.
When running in the "Development" environment, you need to install bootstrap locally and ensure it's in the /lib directory at runtime. That means installing the client-side packages. How to do that depends on the ASP.NET Core application template your using. For instance, if you generated your app with Yeoman, then you need to restore with Bower. Check for a gulpfile.js, a bower.json file, or a package.json that downloads, installs, and builds client-side dependencies, which likely include bootstrap.

npm/bower - Basic questions(Why it requires for just AngularJS then?)

I read about npm and bower, differences, usage, how it works, purpose as well. All explanation says that to work in NodeJs. But when I searched for AngularJS2, the tutorial says use npm. I have some basic questions based upon the understanding that npm basically for dependency management or packages to be installed.
How my Java/Eclipse workspace knows that npm installed the particular JS library/file, what path should be given in the html/web page for including those files/libraries?
If I move the web application to production, how will the server gets those dependent libraries? Even if server gets it, it might be installed in different folder. Basically how it can be managed with a web applications in different environments for just AngularJS app?
Can anyone please help me to have better understanding?
Finally found the answer. NPM is node package manager which helps basically to download the dependencies (almost like maven, gradle in java).
npm software needs to be installed in developer's machine.
Add the required dependencies in the package.json in the root folder of AngularJS application.
Open the DOS command line and navigate to project root folder(workspace/project in eclipse), then type npm install which will download all the dependencies mentioned in the package.json to a folder called npm_modules inside project folder.
The other and important advantage is npm can be used to install browser agent as well. So npm start command will open the browser and will load the application automatically in browser. Developer does not need to be aware about NodeJs. One more benefit of using this approach is the browser will get refreshed automatically when any update in the JS file gets saved.