GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

launching C# code

Sat Sep 15, 2018 1:33 am

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.

Heater
Posts: 9686
Joined: Tue Jul 17, 2012 3:02 pm

Re: launching code

Sat Sep 15, 2018 5:46 am

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.

ghans
Posts: 7784
Joined: Mon Dec 12, 2011 8:30 pm
Location: Germany

Re: launching code

Sat Sep 15, 2018 5:53 am

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
• Don't like the board ? Missing features ? Change to the prosilver theme ! You can find it in your settings.
• Don't like to search the forum BEFORE posting 'cos it's useless ? Try googling : yoursearchtermshere site:raspberrypi.org

Heater
Posts: 9686
Joined: Tue Jul 17, 2012 3:02 pm

Re: launching code

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

GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

Re: launching code

Sat Sep 15, 2018 8:25 am

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?

DirkS
Posts: 8823
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: launching code

Sat Sep 15, 2018 8:35 am

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

jahboater
Posts: 2851
Joined: Wed Feb 04, 2015 6:38 pm

Re: launching code

Sat Sep 15, 2018 8:37 am

As Heater said:

Code: Select all

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

GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

Re: launching code

Sat Sep 15, 2018 8:45 am

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.

Heater
Posts: 9686
Joined: Tue Jul 17, 2012 3:02 pm

Re: launching code

Sat Sep 15, 2018 12:01 pm

Why is this question in the C/C++ section of the forum?

GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

Re: launching code

Sat Sep 15, 2018 1:06 pm

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

jahboater
Posts: 2851
Joined: Wed Feb 04, 2015 6:38 pm

Re: launching code

Sat Sep 15, 2018 6:03 pm

The "Other programming languages" section would be more suitable.

GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

Re: launching code

Sat Sep 15, 2018 6:35 pm

Then flag it so they lock it if its thats much of an issue

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 10835
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: launching C# code

Sat Sep 15, 2018 8:42 pm

moved, added "C#" to subject.
carry on......

GIJojo
Posts: 7
Joined: Wed Sep 12, 2018 5:11 pm

Re: launching C# code

Tue Sep 18, 2018 1:27 am

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.

Return to “Other programming languages”

Who is online

Users browsing this forum: No registered users and 1 guest