Monday, March 26, 2018

ASP.Net Core 2 with Postgresql on Linux Part 4: Sync Configuration Differences


In In Part I, I discussed the rationale for porting a ASP.Net Core 2 app to my Linux system replacing SQL Server with Postgresql and place it on Heroku. In Part II, we transferred the SQL Server data to Postgres.

In Part III, I create the ASP.Net MVC Core 2.x app, from which we will proceed, and get Entity Framework Core installed.

Next, in Part IV, I look at the configuration differences between the ASP.Net MVC app that uses SQL Server and the new app, in preparation of porting the old app to use Postgresql.

First, let's look at the existing app's project file and compare that to the one that we have in our new app that use Postgresql. Of course, in order to do that we will need the code from the app using SQL Server. To do that, I cloned my existing Windows based ASP.Net MVC .Net Core project onto my Linux system as I will be reusing a good deal of the code moving forward. Here is what I did (For more information see: https://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository):


 $mkdir WinCoreProject  
 $cd WinCoreProject  
 $git clone https://myUserName@bitbucket.org/myUserName/myASPNetCoreApp.git  

Now that we have the code from the existing app, let's compare the two project's config files, which are in the root directory of each projects' folder. 

One of my favorite tools for this task is a multi-platform, data comparison utility called Beyond Compare. Comparing the two project files, here is a look at the differences.


Note the text in red in the right side of the view. This shows that the old app's configuration includes three additional settings. The NetCore.MailKit entry is for a MailKit extension for asp.net core that I use to send a confirmation email to users who want to create a user account. Serilog is a logging library with many nice features. In addition, we see the Serilog.Sinks.RollingFile package setting that allows for a daily log file entries.

To sync the two files, let's continue with Beyond Compare. Select the yellow arrows in the right pane to move the text to the config file displayed in the left pane.




Then, to update the myApp.csproj file, select the disk icon to the right of the project file name.


Here is the view of the synced files:


Next, run the dotnet restore command at the command prompt to install the packages:

$dotnet restore   

Note that you can also install the packages at the command prompt in the application's root directory:  
 $dotnet add package NETCore.MailKit

Per the location here, "The dotnet add package command provides a convenient option to add a package reference to a project file. After running the command, there's a compatibility check to ensure the package is compatible with the frameworks in the project. If the check passes, a <PackageReference> element is added to the project file and dotnet restore is run." 

Visual Studio Code, with the C# extension, will also assist you when you update the project file. 


In the next post, Part V, we will start comparing the differences in both the projects' structures and porting the existing project code, starting with the data model layer, to the new project.


No comments: