Nick B
Nick B

Reputation: 161

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

Upvotes: 2

Views: 5163

Answers (5)

adospace
adospace

Reputation: 2019

I was able to create .NET core (3.1 in my case) console app running under Windows 10 IoT:

  1. Create a .net core console app and publish it to a folder
  2. Connect to the device in windows explorer (or ftp) with 10.0...\c$
  3. Create a folder in c:\program files\dotnet
  4. 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)
  5. Unpack it inside the folder at point 3
  6. Open a powershell terminal to device (https://learn.microsoft.com/en-us/powershell/scripting/getting-started/getting-started-with-windows-powershell?view=powershell-7)
  7. In powershell add the dotnet path to path env variable:

$Env:Path += ";C:\Program Files\dotnet\"

  1. Check dotnet is available with:

dotnet --info

  1. Finally copy your application output (publish folder) over the device
  2. You should be able to run:

dotnet .\myapp.dll

Upvotes: 0

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

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.

Upvotes: 0

osexpert
osexpert

Reputation: 563

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).

Upvotes: 1

Paul DeCarlo
Paul DeCarlo

Reputation: 416

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.

Upvotes: 0

Konamiman
Konamiman

Reputation: 50273

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.

Upvotes: 2

Related Questions