How to run DNX 'console app' as a background service on Linux? - c#

I've implemented a DNX (dnx451) 'console app' which is intended to run as a background service. On Windows I would just turn it into a Windows Service. What is the proper way to do this on Linux (for instance, Ubuntu)?
EDIT:
Found more info here: How to migrate a .NET Windows Service application to Linux using mono?

On Unix/Linux operating system you can turn any program into a background service like
dnx run &
The "&" turns the "dnx run" it into a background program (when I remember right for your current shell session). For real background services look at the startup scripts of common Unix daemons like mysql or apache httpd. They get started by the initd/systemd processes and then execute on their own.

Related

Automating installation process of a cross platform application

I've developed a console app in C# and the code is hosted on GitHub.
The app will be used on Windows and Linux.
I'll create a CI/CD process so when I push the changes to GitHub using a Tag with the following format "version x.x.x" the CI/CD creates an Installer/Package with the following format:
appName-1.0.0-windows.extension
appName-1.0.0-linux.extension
The question is:
What application/process can I use so the users of my app using one command on the Windows/Linux terminal can download the app from GitHub Releases and install/extract the app in a directory?
Ideally I would like to use the same tool on Windows and Linux

In Azure Devops, how can I deploy an exe file to as server as part of release (or something similar)

A solution consists of...:
Web app
Console app ("jobserver", which pulls jobs and processes them)
All is C#, .Net Core 5.
I have continuous deployment set up, so new versions of the web app are deployed to Azure Web App automatically.
However, the console app, I cannot figure out a good way to deploy to a Windows server (or pull). Right now, I go to the server, stop the app if it is not doing anything (otherwise I wait a bit). Then I copy the files over and start it up again. All manually.
I can think of several complicated workarounds, but I am thinking there must be easier way.
What are some ways the deployment of exe file could be handled? How are others handling this?
Ps. The console app cannot run on Azure Web App or as WebJob or similar, because it has requirements that means it has to run on a "real" windows server.
You can use the PowerShell on Target machines or SSH tasks to run commands on a remote machine. Similarly, to copy files, you can use Windows Machine File Copy or Copy Files Over SSH to copy your .exe to the server.

AppDomain missing or depricated in Windows 10 IoT Core and UWP

For an app for Windows 10 IoT Core on Raspberry Pi2, I need to use a launcher app or StartUp-Task, which creates a shadow copy of my app and launches it. I need to use this approach to be able to substitute DLLs during runtime, without having a lock on the DLLs and without disrupting running services. That's needed as the device running it, would be remote somewhere out of reach, deployed at a client's site and I need my app to be running to service the device. After updating my DLLs, I would restart it and it would run with the new libraries, start the launcher as default app, which then starts my app.
Before Windows 10 and UWP the approach was to use System.AppDomain from mscorlib.dll in the .NET Framework to create a new AppDomain in a cached directory. The config, executables and DLLs would be copied to a cache directory and run from there. That leaves the original DLL available for substitution and doesn't put a lock on them. This was also a very useful technique used in IIS and webapps, which needed to run without interruptions even if the code needs updating. The open threats keep servicing open requests until these are done and new requests will be serviced using the new updated versions.
Now in Windows 10 System.AppDomain is not available anymore. I tried Windows.System.ProcessLauncher but encountered several issues with it. First I have to register the EXE in the registry to allow launching it. Then it tells me I can only run it from an app container. I didn't get it to work as of now. It's just a tedious and messy approach IMHO.
Now to my question: What would you use as an alternative to the described old approach on Windows 10 IoT Core? Does anyone have a small snippet of sample code to share? Or perhaps a link pointing in the right direction? Any advice would be appreciated.
This approach is not compatible with the Universal Windows Platform app model.
You will have to push an updated package of your app.

Windows IoT console application written in c#?

I'm trying to make application that would take a picture using web-camera on Raspberry PI running Windows IoT. The problem is that I can't find console app template.Universal Windows blank app template provides me with GUI but I'm going to call this app from python script so it should be without one.
Windows IoT projects provide background task template but the output is .winmd file and I cant execute it from python neither.
What is the way to create simple console app in Windows IoT using c#?
Thanks
Console applications are supported in Windows IoT but apparently in C++ only. Perhaps you could try to create a solution that has a very simple C++ console application that just handles interaction with the user plus a C# class library with all the logic and hardware related code.
Seems to works with a standard c# console apps. How I found out?
I used Reflector and examined all exe files in c:\windows\system32 on the Pi, and one was a .NET assembly: netcmd.exe
When I look at netcmd.exe in Reflector, it says it's build with standard .NET 4.5, this can't be right? But I made a standard c# console app with framework 4.5, added this:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello world");
}
}
put the test.exe on the Pi, and voila:
C:>test
Hello world
Weirdest thing.
I haven't tested more than this, but I imagine You get into trouble with unimplemented API's since only a subset of .NET (same as in Background Application (IoT)?) exist on the Pi, so you must "manually" take care not use unimplemented stuff (or code most in Background Application "mode", and in the final stage, move to standard .NET 4.5 and add the console code).
If you still wish to move forward using C#, it may be sufficient to create the application as a blank Universal Windows Platform application as 1.) The UI will not be instantiated if the RPi2 is powered on without a connected HDMI cable 2.) You may find it useful to use the included UI as a means of live-debugging your application.
If you use your Win 10 device for a single (or multiple) app that all do not need a GUI, (eg for service apps only), you can boot the device with the headless option.
This boots without the whole UI with an extra resource bonus., buts still can be accessed over the network.
display the current state of your device, use the setbootoption utility:
[192.168.0.243]: PS C:\> setbootoption.exe
To modify the state of your device to enable headless mode, use the setbootoption utility with the headless arg:
[192.168.0.243]: PS C:\> setbootoption.exe headless
[192.168.0.243]: PS C:\> shutdown /r /t 0
To modify the state of your device to enable headed mode, use the setbootoption utility with the headed arg:
[192.168.0.243]: PS C:\> setbootoption.exe headed
[192.168.0.243]: PS C:\> shutdown /r /t 0
The device will start up with a black screen.
I was able to create .NET core (3.1 in my case) console app running under Windows 10 IoT:
Create a .net core console app and publish it to a folder
Connect to the device in windows explorer (or ftp) with 10.0...\c$
Create a folder in c:\program files\dotnet
Download an arm 32 dotnet core runtime (for example https://dotnet.microsoft.com/download/dotnet-core/thank-you/runtime-aspnetcore-
3.1.2-windows-arm32-binaries) (note I've used a raspberry pi 4)
Unpack it inside the folder at point 3
Open a powershell terminal to device (https://learn.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell?view=powershell-7)
In powershell add the dotnet path to path env variable:
$Env:Path += ";C:\Program Files\dotnet\"
Check dotnet is available with:
dotnet --info
Finally copy your application output (publish folder) over the device
You should be able to run:
dotnet .\myapp.dll

Run as Windows Service, Console App, or Wpf App in a single VS2010 project

I currently have 3 projects which produces 2 executables
Class library to do work
Windows Service project that uses library #1
WPF App that uses the library #1
The class library is used to perform some client-server interaction.
What I want is to only have 2 projects, the class library, and another that produces an executable that can be run as a Console, WPF, or a Windows Service. Is it possible (or advisable) to do it this way? What should the project output type be?
The main reason is that we have automated scripts to run that expect some fixed file paths. I want to avoid having to duplicate the scripts for the WPF executable and the Service/console executable.
I'm not sure about being able to do WPF, but TopShelf will allow you to run an executable as a console application or as a service.
http://topshelf-project.com/
There are two ways to use TopShelf - exe as a service or using shelving.
To run as a console application you just run yourprogram.exe.
To install as a service it's simply yourprogram.exe install.
I know this question is a bit old, but...
You can start a new project as a WPF project, then right-click it in the solution explorer and change "Start As" to console application. Your WPF app will still run exactly the same, but a console window will appear where you can use things like Console.WriteLine() calls.
You could then accept a command-line parameter that tells your application to suppress the rest of the UI, leaving only the console part. I don't think this will allow it to run as a service, though.
You have to go for Windows Communication Foundation aka WCF, Click link to learn basics
http://msdn.microsoft.com/en-us/netframework/dd939784

Categories