docs
docs copied to clipboard
Programmatic way to check for newer installations of .net runtime
I was searching for a way to detect the installation of a newer version of the .net runtime.
All I found was this. https://docs.microsoft.com/en-us/dotnet/core/install/windows?tabs=net60
That is much more targeted at a human searching their machine but there's no good guide I can see on how a program should detect it.
Normally I'd use the upgradecode and productcode which doesn't work here. I've raised that as a separate issue.
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 1eeab451-820f-de42-983e-4d0d5764f6ab
- Version Independent ID: d11d0d14-8a03-50e4-5c00-9a4417ad4d0a
- Content: Install .NET on Windows - .NET
- Content Source: docs/core/install/windows.md
- Product: .net
- Technology: dotnet-installation
- GitHub Login: @adegeo
- Microsoft Alias: adegeo
Environment.Version gives you the version of the CLR.
That requires a version to be installed already. I was looking for a way to check at install time.
Seems such a thing isn't possible.
Hi @Saurbaum I just discovered this issue, sorry it's been lost. I don't think there really is a TRUE way besides checking if the folders exist, or checking if one of the environment variables is set that can help you locate the DOTNET folder root and then checking for the existence of some sub folders.
I would think the best way would be to see if the dotnet.exe command resolves to anything, if so, something is setup to be "the" .NET on the machine, then shell out to it with the --runtimes parameter and manually parse the results. There are probably some trail markers left behind depending on how the .NET runtime was installed, like when a user uses the install MSI/EXE, there's something there indicating it's installed so you can uninstall it via Add or remove programs.
.NET isn't installed globally, like .NET Framework was. You can install as many copies as you want as long as the dotnet.exe command is resolved and the executable finds child folders of runtimes/sdks (simplification of how it works, I assume). But if someone simply unzips the binaries, puts it in the %PATH% variable, .NET becomes alive and works, no trace as to how it was installed or what is actually installed.
I don't think there's anything we'll do at this moment to this article to add information on how to do that.