Page 1 of 1

launching C# code

Posted: Sat Sep 15, 2018 1:33 am
by GIJojo
So I have a code that I made to run a Discord bot. I know several people have used a raspberry pi to self host their Discord bot. I can run it from my tower or laptop using a .bat file. However, I can't launch the .bat file and no idea how I'm to run the bot since I regularly have my tower off when I'm not using it.
I have `dotnet DigitalPhoenixBot.dll` in the bat file in the location of the .dll file.

Extra info: The program is all on a USB Flash drive to prevent issues with the OS installed. This is using the Raspbian OS since I couldn't get the windows core to work.

Any and all help would be great! Thank you in advance.

Re: launching code

Posted: Sat Sep 15, 2018 5:46 am
by Heater
As we are on the C/C++ section of this forum I presume your bot is written in C or C++.

If your bot is compiled and runs on a Windows machine then it will need recompiling on the Pi in order to run there. Your Windows machine is a Intel architecture processor so the binary executable will not run on the ARM processor of the Pi.

If your bot relies on Windows API's and DLLs then it will not run on Raspbian. It will need to be rewritten to use Linux libraries.

You could write your bot in a language that is more easily portable from machine to machine, C#, Python, Javascript, etc.

Re: launching code

Posted: Sat Sep 15, 2018 5:53 am
by ghans
If your program is written in C# instead of C or C++ recompilation might not be necessary.

Just like Java, the .NET program should run as-is on the Raspberry Pi. Instead of a Java Virtual Machine (JVM) "Mono" has to be installed on Raspbian for .NET programs to work.

ghans

Re: launching code

Posted: Sat Sep 15, 2018 7:28 am
by Heater
If your program is written in C# this is how I get C# projects from Windows running on Debian, should also work on Raspbian:

Copy the projects directory from Windows onto the Pi, the build it:

Code: Select all

$ sudo apt-get install mono-complete
$ cd myProject
$ xbuild myProject.csproj
That will produce the executable in myProject.exe in a bin subdirectory

Then run it with:

Code: Select all

$ mono myProject.exe

Re: launching code

Posted: Sat Sep 15, 2018 8:25 am
by GIJojo
Heater wrote:
Sat Sep 15, 2018 7:28 am
If your program is written in C# this is how I get C# projects from Windows running on Debian, should also work on Raspbian:

Copy the projects directory from Windows onto the Pi, the build it:

Code: Select all

$ sudo apt-get install mono-complete
$ cd myProject
$ xbuild myProject.csproj
That will produce the executable in myProject.exe in a bin subdirectory

Then run it with:

Code: Select all

$ mono myProject.exe
You talked about getting mono. Is there a specific place to get mono for the pi or no?

Re: launching code

Posted: Sat Sep 15, 2018 8:35 am
by DirkS
GIJojo wrote:
Sat Sep 15, 2018 8:25 am
You talked about getting mono. Is there a specific place to get mono for the pi or no?
It's the install command in @Heaters's post https://www.raspberrypi.org/forums/post ... #pr1365893

Re: launching code

Posted: Sat Sep 15, 2018 8:37 am
by jahboater
As Heater said:

Code: Select all

sudo apt-get install mono-complete
gets you mono for the Pi.

Re: launching code

Posted: Sat Sep 15, 2018 8:45 am
by GIJojo
That part wasn't clear that entering that in would get mono onto the pi. The one issue i do have is my bot won't be on the SD card. Well to be more accurate it will fill the sd card up easy. I do have some things stored. So i either need to change the code so that the file used to store data is on a flash drive while the rest is ran on the SD card.
If possible how do i get it to pull a program in other drives?
That brings me to this point. How do i figure out the Drives so i can direct my code to check for the file in the proper directory.

I doubt there is a BIOS screen to get drive info and the flash drive just comes up with the flash drive in a media folder.

Re: launching code

Posted: Sat Sep 15, 2018 12:01 pm
by Heater
Why is this question in the C/C++ section of the forum?

Re: launching code

Posted: Sat Sep 15, 2018 1:06 pm
by GIJojo
Heater wrote:
Sat Sep 15, 2018 12:01 pm
Why is this question in the C/C++ section of the forum?
Pretty sure I answered that but I will answer it again incase it was one I had issues sending at work. I did not see one for C# only C/C++.

Re: launching code

Posted: Sat Sep 15, 2018 6:03 pm
by jahboater
The "Other programming languages" section would be more suitable.

Re: launching code

Posted: Sat Sep 15, 2018 6:35 pm
by GIJojo
Then flag it so they lock it if its thats much of an issue

Re: launching C# code

Posted: Sat Sep 15, 2018 8:42 pm
by mahjongg
moved, added "C#" to subject.
carry on......

Re: launching C# code

Posted: Tue Sep 18, 2018 1:27 am
by GIJojo
So i got to the flashdrive but the issue is i cant build the program. It wants it in MSBuild 2003 format. And wants the default XML namespace of the project to be the MSBuild XML namespace.