"NVM#: Effective Environment Variables Manager"
Today's project isn't a Visual Studio Extension, isn't a language or service. But it's something that will help what ever Dev has to do one time or another, editing environment variables.
We've had environment for forever, but the UI to edit them has not really advanced. You have to remember which ones are where, what the delimiter is, and in pre-Windows 10, scroll and scroll to see the entire value (I'd always copy and paste into Notepad to see it all).
What if I were to tell you there's a new open source utility that looks great, has a number of cool features that make dealing with environment variables easier and written with WPF?
Ratish Philip has written and shared...
After a long hiatus, it feels good to be back with a new article. 8 years ago, I wrote my first CodeProject article. It was NVM - eNvironment Variables Manager. It was a Windows Forms application written in C# on the dot Net 3.0 Framework. It provided simple and user-friendly features which made management of Environment Variables relatively easier. However, at the time of writing that article, I had planned several new features for it. But I could not implement them and slowly they were put on the back burner only to fade into oblivion with the passage of time.
With the launch of Windows 10, Microsoft brought forward a new user experience which I am very excited about. I decided it was time to dust up those old ideas, bring in some new ones and rewrite NVM from scratch and give the developer community a new Environment Variables Manager written using WPF & C# 6.0 on the dot Net 4.6 framework.
As a result NVM# came into existence and I shall be talking about it in detail in this article.
You can view or modify the environment variables by selecting System from the Control Panel, selecting Advanced System Settings, and clicking Environment Variables.
The biggest problem with managing Windows Environment Variables is the User Experience. It is tedious, unintuitive & cumbersome and has remained unchanged since Windows XP!
NVM# redefines the user experience for managing Environment Variables by providing a UI similar to the one provided by the Settings app in Windows 10. In future, Microsoft aims at integrating all the Control Panel features into the Settings app. So I thought, why not Environment Variables too??
I had initially planned to create a Universal Windows Platform (UWP) app for NVM# so that it can be available through the Windows App Store. But UWP apps cannot access the Registry as the apps are executed in a sandbox to protect the system. So I decided to create NVM# as a WPF desktop application which can be run as an administrator while having the look and feel of the Windows 10 Settings App.
Another thing that was required in this app (though it is not present in the Windows 10 Settings App) is the SplitView Control for creating the Hamburger Menu. Now
SplitView Controlis not a WPF control. So I had to modify the RadioButton's ControlTemplate to emulate the look and feel of a Hamburger Menu.
The Hamburger Menu allows you to access 5 views of the application:
- User allows you to view and manipulate the User Environment Variables.
- System allows you to view and manipulate the System Environment Variables.
- Import allows you to import Environment Variables from an XML file.
- Export allows you to export Environment Variables to an XML file.
- About shows the About screen.
MVVM and IOC
NVM#, being a WPF application, employs the MVVM and IOC concepts to ensure that the code is effectively decoupled. The
CoreWindowclass encapsulates the main View, the
CoreViewModelclass represents the ViewModel and the Model is the Registry.
The View communicates to ViewModel through DataBinding, whereas the ViewModel interacts with the View (especially when there is user interaction required e.g. showing a MessageBox, selecting a file for saving or opening etc) through the various service interfaces defined. The service interfaces are:
Action Baroccupies the top most position in each view. It primarily consists of the View Title. For the
SystemViews, it additionally contains a set of buttons representing the common tasks that can be performed with Environment Variables and their values. The buttons can be divided into two groups - one group (on the left) consists of tasks targeted at the Environment Variable and the other group (on the right) contains tasks focused on the Environment Variable value(s).
Import & Export
In a production environment, normally it is required that all team members have the same environment variables to avoid potential issues and failures (I have experienced this scenario several times myself!). Or consider a scenario when a new member joins the team and s/he needs to set up the development machine, wouldn't it be easier to import all the necessary Environment Variables at the click of button (instead of manually entering each of them!)? NVM# allows you to do so, with its Export and Import features.
The source is available too;
Finally, what I love in a project is that after grabbing a quick clone, it compiled and ran the first time... :)