dotnet / vscode-dotnet-runtime

VSCode Extension for Installing .NET via VS Code
MIT License
128 stars 230 forks source link

Track which Extensions Own Which Installs #1748

Closed nagilson closed 4 weeks ago

nagilson commented 2 months ago

Summary

The initial design years ago did not keep track of which extensions installed which versions of .NET, and it has not been updated since. This makes it hard for us to responsibly uninstall .NET without breaking other extensions.

This PR is meant to add that tracking information. We will change the extension state keys that used to store strings into an InstallRecord object, which holds more info about the install.

We also used to store the extension install data with a 'Install Key' which was just a string which held all of the information. This is a volatile pattern. Instead, we introduce dotnetInstall as a type to hold the install data. We introduce the installMode concept as well to allow for considering aspnet, windowsdesktop, and other installs and not just runtime or sdk installs.

Assumptions in the change

This is a bit tricky to do because there will be pre-existing keys of just string type (for old versions, just a string of the version, for newer ones, a string with -global and the architecture) inside the extension state for most users.

I went with a philosophy of 'protected access' -- I.E. work under the assumption that there are no longer any 'string' types stored in the extension by ensuring that any time we access the extension state, we update it before allowing any use of it. That is the job of the InstallerTracker -- of which much of the code is ported from the AcquisitionWorker class.

More info on the old concept of InstallKey

The 'InstallKey' is meant to represent a single install of .NET and used to just be a 'version' string. Then we introduced '-global' and the architecture to it. I also updated this to become a type, DotnetInstall which contains this information to a - get us out of the business of string parsing b - allows us to auto update an install in the future, so the path of the install is not directly correlated to the version.

More Changes

This also includes some bug fixes I noticed in the code, for example:

Before when we found a 'partial install' we would delete ALL local runtimes. I am astounded this exists. There are other extensions that might depend on those other runtimes and this just deletes it from underneath them. A partial install is rare, I think you need to pkill vscode or something since the install script runs out of proc. We consider an install partial if our code never got to mark it as installed after calling the install script. Its rare but does happen, at 2010 occurrences out of 470k in recent days.