You want to run a C# app on your NAS ? read this!
Prerequisites:
– A computer with Visual studio (2019 or later) installed,
– A synology NAS which can run docker , and docker installed on it 🙂
Phase 1 : With Visual Studio, on your computer
First Create a new Console app dotnetcore project in Visual studio
Some sample code :
using System; namespace HelloWorld2 { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); if (args.Length > 0) { Console.WriteLine($" how are you {args[0]}?"); } } } }
Go to project properties
and change dotnetcore version to dotnetcore 2.1 (this version only is available on synology nas at the time I write this post)
Phase 2 : On your Synology NAS
Start Docker
In docker registry, search for “dotnet” and download latest microsoft/dotnet version (if not already installed)
After Image is downloaded, Run it (button “Run”)
Go to Docker “Container “Tab and stop Microsoft-dotnet1 container if it’s already running
Now we will update the docker container , click on modify /update button
Give access to an external NAS folder from the docker container, for example :
- Create a folder named “dotnetcore” in your NAS directory “Documents”
- Then Add this folder in docker container volume:
- File / Folder : Documents/dotnetcore –> access path: /dotnetcore
then click on “Apply” (blue button)
Phase 3: mix
Back on visual studio
Open the solution folder
copy .csproj file and Program.cs in computer clipboard (CTRL+C)
copy/paste these files onto your NAS folder : Documents/dotnetcore /HelloWorld2
(different methods are possible to copy files to your NAS, I won’t describe all of them here but it can be by FTP, SMB, SSH, SCP, via diskstation FileStation app on your browser directly ,etc…)
Here I use a network share
and I paste the 2 files here:
Back on the NAS:
Run microsoft-dotnet1 container
Click then on “Details” button
Click on “Terminal” Tab
A terminal appears, type dir if you want to list files, then cd dotnetcore/HelloWorld2
(dotnetcore is the name of the shared external folder described in Phase 2 and HelloWorld2 is the name of the folder cotaniner .csproj and Program.cs)
then type dotnet run YourName
where YourName is first argument of Main console
That’s it!