Introduction:
We as an X++ developer often have to connect to sandbox for debugging which involves to get the access credentials from lcs and then whitelisting our VM's IP addresses.
And then we need to open the Web configuration file where the original dev file has to be preserved in some known location and then the file has to be updated with sandbox credentials from LCS and the updated config file has to updated in web root followed by IIS reset.
These all requires to navigate through multiple applications and some tabs and pages. Kind of exhaustive too.
To resolve this copy pasting of connection string manually, earlier I have written a blog where a Form is used within D365FO to update the file. Here is the article for the same.
The Problem:
Everything seems fine. However again the troublesome issue is we need to locate this Menu item in FO UI if its not set in favourites and we all know the general loading time of FO UI :(
For all these issues, I felt there should be a better way which should make the developers tasks easier and it should be independent.
The Solution:
Then came this Idea of Console application in which from updating the web config file to resetting of IIS, restoring the original file of web configuration… everything is added within this application. With this we can limit our problem into going from multiple different applications to a single console application.
Lets delve deep to see how this works!
A Console application is a program that runs within Command-line interface which is independent of any other application and always up.
For connecting to Sandbox, based on respective organization traditions, developers either create separate folders to preserve the original file or will keep original within web root path itself. I generally prefer to keep 2 paths somewhere on VM desktop or may be in Temp folder in C drive one called as Original where the actual original file is stored and other is Running folder where I make changes for that file timely. As in, this is the folder where I actually update the web config file and then will move to the original actual location. If I need the original(dev) config file, I will copy it from the Original folder. And then this follows by resetting of IIS.
All the above manual tasks are now integrated into a single application.
So once this application is loaded, we get all the tasks it can perform. It just need a particular key press and sometimes text input to accomplish a task.
The Approach:
Lets understand it visually.
To open a Console application, we can navigate to the bin > Debug folder or to the Application or exe location if its kept somewhere locally. Also this can be directly opened from Command Prompt.
Type Cd <application path> In my case at project root Bin folder.
Then type the application name. In my Case WebRootAutomate. And boom!
This is the UI or the main menu of my console application.
All the tasks have been listed.
Lets say if I want to update web file.
Before running this, we need to make sure, the web root original file is available in C drive temp folder in both Running and Original paths and this is one time setup.
To update web config, press 1.
As said earlier, I keep the web config file which has to be updated in the Running folder which is a default for me. If the path is okay, press Enter simply. Else path should be specified. Its generic like if path is specified it takes path else the default one.
Then it asks for the credentials one by one. Provide the same.
On providing all details and hitting on enter, the file gets successfully updated and a feedback message will be shown to user.
It asks for the next task or to move to next action or to main menu.
If I chose 3, it again asks for the source path. If the path is ok, then it can be left blank.
If the default path is not okay and want to give a new path from console, press 'n' or 'N' and provide the details like below.
Choose 4 to reset IIS.
Now if I choose simply any other key, application gets closed with message Closing....
Lets say if, I got some schema error after connecting with sandbox (as we need to have same schema like sandbox), we need to reupdate the web config to original and then IIS will be reset. Right!?
So for this, no need to rerun all steps. A simple press on 3 will perform the activity for us.
If we need just an IIS reset, 4 can be provided as input.
This way, this is a one stop solution for the web config file updation process.
Error Handling:
Lets say if I want to copy file from Running folder to WebRoot and I somehow wrongly entered the path address, then we get the error like below.
The human errors are also handled and on any key press, the console again navigates back to main menu.
​​​​​​​Lets not wait and check here for the complete code here in my Github repo.
With this most of the hurdles when updating file and restarting things will make their way out:):)
PS: Currently for demo purpose, I have explained directly from the debug folder. Uploading of self-contained deployment in release is awaited soon.
Happy Learning!​​​​​​​
​​​​​​​