3

Dots - the friendly .NET SDK manager

 1 year ago
source link: https://johnnys.news/2023/01/Dots-a-dotnet-SDK-manager
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Jan 5, 20231405 words in 9 min


Dots - the friendly .NET SDK manager

Finally found some time to write this post about Dots. It’s my holiday hack 2022/23 and i’m not sure if a post in the middle of January still counts as a “holiday” but here we go.

TL;DR

Dots is a GUI to manage .NET SDKs - it’s developed with .NET MAUI and is available for Windows and macOS (sorry Linux folks 👉 https://github.com/dotnet/maui/discussions/339).

You can get the app from the GitHub repository and from the website.

When it comes to trying out new releases of the dotnet SDK, I would consider myself an early adopter. I like to try out the latest previews of the SDK or even experiment with a custom build. I keep several different versions of the SDK installed on my machine to be able to switch between those. Usually i try to keep the current stable version, the latest preview bits and a LTS version installed. In addition to that it can happen that i need a specific SDK version for a specific project. There is of course the dotnet cli which allows me to check the installed versions - but i wanted something more visual with some special features. That’s what my holiday hack 2022/23 is about. Let’s welcome Dots - the friendly .NET SDK Manager and see how it works under the hood.

Uninstall the .NET SDK

It can happen that i forget about older versions of the SDK that are still installed on my machine. Especially on my MacBook where i usually run low on disk storage i want to quickly clean up unused versions of the SDK which just take up space.

For macOS and Linux there is this uninstall script to get rid of specific versions.

macOS

version="x.x.x"
sudo rm -rf /usr/local/share/dotnet/sdk/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.All/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/$version
sudo rm -rf /usr/local/share/dotnet/host/fxr/$version

the script is basically the same for Linux systems with slightly different paths.

Linux

version="x.x.x"
sudo rm -rf /usr/share/dotnet/sdk/$version
sudo rm -rf /usr/share/dotnet/shared/Microsoft.NETCore.App/$version
sudo rm -rf /usr/share/dotnet/shared/Microsoft.AspNetCore.All/$version
sudo rm -rf /usr/share/dotnet/shared/Microsoft.AspNetCore.App/$version
sudo rm -rf /usr/share/dotnet/host/fxr/$version

Windows

On Windows one can use the regular uninstall page in the settings app.

To check which versions are installed i usually use the dotnet cli dotnet --list-sdks which outputs all versions and the installation paths of the SDKs. This is a good start but i wanted to have a better overview of all installed versions with some details and also be able to quickly uninstall them.

The first version of Dots can already help with uninstalling in a cross-platform way. It shows which SDKs are installed - i do this by using CliWrap (great project BTW 👏) to check if dotnet cli is installed and call dotnet --list-sdks to parse its output. This approach works across Windows, macOS and Linux. For uninstallation on macOS and Linux i can just use CliWrap and run the scripts from above with the correct version. On Windows i search for the setup in the Package Cache directory and execute a silent uninstall in the background (msiexec /x setup.exe /uninstall /qn). There is probably a more elegant method to get the uninstaller (Windows Registry or msiexec by GUID) but this works for now.

Installation

In addition to uninstalling SDKs i also wanted to be able to install them. For this i needed a feed of available versions. I checked the dot.net website which holds all versions and found a json file in the dotnet repository on GitHub which contains the available versions with some metadata. I use this file to populate the list and compare the versions with the installed ones to tag already existing SDK versions. Installation on Windows is fairly easy - once the download of the setup is done i can execute the setup with msiexec to silently install the SDK (i may add a flag in the settings to toggle the quiet setup). For a sytem wide installation on macOS root privileges are required - i use Authorization from Security.framework to call the installation command with root privileges.

C# bindings for AuthorizationExecuteWithPrivileges

var flags = AuthorizationFlags.ExtendRights | AuthorizationFlags.InteractionAllowed | AuthorizationFlags.PreAuthorize;
using var auth = Authorization.Create(parameters, null, flags);
int result = auth.ExecuteWithPrivileges("/usr/sbin/installer -pkg ...", AuthorizationFlags.Defaults, args);

i noticed that this API is deprecated now so i may switch to an alternative implementation in the future - there is also an issue in the .NET for macOS SDK that causes the authorization tool to fail with an error code returned from the authorization dialog. https://github.com/xamarin/xamarin-macios/issues/13465.

I have added the option to directly download and install a specific version of a SDK. In addition to that you can also see all available files in the details panel with links to the installer if you want to download manually or for a specific platform. In the latest commits i have also added to option to quickly filter installed and non-installed SDK versions.

the underlying code is written in C# without any dependencies to a UI framework. I decided try .NET MAUI and see how ready the framework is for a cross-platform desktop application. What i really like about MAUI is the handling of assets and resources - it’s fully abstracted and you don’t need to worry about optimizing i.e. an image for the specific platforms. The main UI is not very complication - it’s a CollectionView with a DataTemplate for the items. There is a details panel with more info - this is just a Grid that animates it’s Width once an item is selected. One thing i noticed is that during development the CollectionView can be a bit laggy when filtering or fast scrolling is happening. This definitely works better in Release builds of the application. Similar to Resources MAUI also abstracts the Window handling. Implementing multi-window functionality in Dots was very easy and it worked great for my use case on Windows and macOS.

Future plans

So, UI wise i’m happy with the state of MAUI but trying to publish the app almost made me switch UI frameworks completely. Especially Windows publishing is a nightmare - i will write a separate post about that topic (not gonna be a fun one). The current experience is not great neither for users nor for developers. Since the business logic is separated from the UI i may experiment with other UI frameworks in the future - i’m thinking about Avalonia or Uno Platform. For now, this first version of Dots is a good start for me. I also want to explore more useful features in the future. One thing that i want to add is a way to manage dotnet workloads. The workloads concept is fairly new in .NET and i’m not really happy with the current state of the tooling which is mostly dependent on the Visual Studio installation. Maybe there is a better way - let’s see. I will also look into the structure of .NET runtime packages that are installed. As mentioned one critical thing that i need to explore is a better way of publishing the application. And of course some minor UI / UX fixes are already in my pipeline. That’s it for now from my holiday hack 2022/23. I’m very happy to hear your feedback - ideas and contributions are very welcome.

PS: the app icon is created by the StableDiffusion AI - here is a tutorial on how to set it up locally.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK