C
C#4mo ago
Aadi

✅ How to share my C# console application with MacOS friends?

hello. i made a very very basic c# console application game using jetbrains rider i want to share my game that i've made with my friends my teacher suggested to share the .exe file to my friends via a google drive link, and this works brilliantly for some of my friends however, those who use MacOS cannot run this how can i share my game to my MacOS friends i want it to be as simple as possible for them, so they just click a file and boom it works, just like it is with sharing the .exe file (edit, im a beginner and im clueless about a lot of programming stuff. i looked at docker and it was difficult to understand/get to work)
101 Replies
Pobiega
Pobiega4mo ago
You'll want to publish your app as a self-contained single file application, with a MacOS RID $singlefile
MODiX
MODiX4mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -p:PublishSingleFile=true implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples. Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
Aadi
Aadi4mo ago
sorry i'm completely lost, please can you break that down a bit for me thanks Pobiega
Pobiega
Pobiega4mo ago
Well, once your app is done and you want to "release" it, you publish it dotnet publish -c Release will do that, but you want it to work on a mac so we need to tell the publisher to turn it into a mac executable we can do that with -r osx-x64 (if they are using "normal" macs), or -r osx-arm64 for M1s etc
Aadi
Aadi4mo ago
right now i like how whenever i build my game, the .exe file is updated The game is still a work in progress and i've just began understand OOP so im adding in new features etc im making 3-4 new things / fixing old things per day, ideally i don't want to be doing something long every time i change something and want to 'publish' it
Angius
Angius4mo ago
I wouldn't say executing a single command is "doing something long"
Pobiega
Pobiega4mo ago
well you will need to republish every time but it is, as zzz said, a single command
Aadi
Aadi4mo ago
yeah, youre right; as i learn it'll become very easy i understand so far so i go into terminal within my IDE, type out dotnet publish -c Release -r osx-x64
Pobiega
Pobiega4mo ago
well, sorta you also need the other stuff from the tag I invoked dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=true
Aadi
Aadi4mo ago
what goes in the <runtime identifier>? what does runtime-dependent mean?
Pobiega
Pobiega4mo ago
and again, if they are on... what do Mac call it, Silicone? Silica? CPUs, they need another RID
Aadi
Aadi4mo ago
apple silicon, yes
Pobiega
Pobiega4mo ago
runtime identifier == RID a modern windows PC is most likely win-x64 macs are different from windows, they use different formats. the stuff after the dash is the processor architecture
Aadi
Aadi4mo ago
for windows PCs im happy to continue just sharing the google drive link because..well it works so far, but im willing to learn regardless
Pobiega
Pobiega4mo ago
you can publish for multiple RIDs if needed
Aadi
Aadi4mo ago
meaning two formats, for M1 and intel-based macs
Pobiega
Pobiega4mo ago
yes so, to run a .NET project, you must have the .NET runtime
Aadi
Aadi4mo ago
i feel incompetend but pasting that into terminal gives:
No description
Aadi
Aadi4mo ago
my game is using the .NET frameowrk v4.8
Pobiega
Pobiega4mo ago
oh
Angius
Angius4mo ago
Oof
Pobiega
Pobiega4mo ago
you're fucked then
Angius
Angius4mo ago
No Mac for you
Pobiega
Pobiega4mo ago
no mac for you indeed
Angius
Angius4mo ago
.NET Framework is strictly Windows-only
Aadi
Aadi4mo ago
and why's that? uhoh
Pobiega
Pobiega4mo ago
.NET fx is old and dead it died in 2016
Angius
Angius4mo ago
Only since .NET Core did it become cross-platform
Aadi
Aadi4mo ago
i can copy pasta my code into a new form of project format?
Angius
Angius4mo ago
It's Winforms? Then no Winforms is Windows-only
Pobiega
Pobiega4mo ago
you said it was a console app no?
Angius
Angius4mo ago
Windows Forms
Pobiega
Pobiega4mo ago
if its a console app, you can migrate
Aadi
Aadi4mo ago
i use jetbrains rider for macos here's the settings whenever i create a new solution
No description
Pobiega
Pobiega4mo ago
yeah you picked the wrong thing
Aadi
Aadi4mo ago
no worries, i can copy pasta or migrate it over right?
Pobiega
Pobiega4mo ago
I'm on Rider EAP so my new solution window is different...
Pobiega
Pobiega4mo ago
No description
Pobiega
Pobiega4mo ago
lets see if I have non-EAP installed
Angius
Angius4mo ago
You want the Console project without .NET Framework part
Aadi
Aadi4mo ago
i feel like im meant to use one of these
No description
Pobiega
Pobiega4mo ago
No description
Pobiega
Pobiega4mo ago
there
Angius
Angius4mo ago
No description
Pobiega
Pobiega4mo ago
you want to use the ones from the .NET / .NET Core section pretend .NET framework doesnt exist
Aadi
Aadi4mo ago
i feel like im making progress
No description
Aadi
Aadi4mo ago
thanks
Angius
Angius4mo ago
Yeah, this will do the trick
Aadi
Aadi4mo ago
done, thank you
Angius
Angius4mo ago
Just check the Create GIT repository box while you're at it
Aadi
Aadi4mo ago
so create a new solution there, copy pasta everything over, then we're chilling?
Angius
Angius4mo ago
Yeah
Pobiega
Pobiega4mo ago
kinda
Angius
Angius4mo ago
Should work
Pobiega
Pobiega4mo ago
you might need to tweak a few things, but mostly it should work also, you WILL need to change how you "publish" for windows
Aadi
Aadi4mo ago
yup my current project is in github (slightly concerned about creating a new project meaning losing all commit history etc. but thats for later) if you care then here's the link: https://github.com/aadityakalwani/Gold_Diggerzz
GitHub
GitHub - aadityakalwani/Gold_Diggerzz: a digging simulator game
a digging simulator game. Contribute to aadityakalwani/Gold_Diggerzz development by creating an account on GitHub.
Pobiega
Pobiega4mo ago
the modern .NET runtime isnt pre-installed on all windows computers so you'll need to do the dotnet publish -r win-x64 thing
Aadi
Aadi4mo ago
so one for windows, one for intel macs and one for apple silicon macs, sure thats only 3 commands i'll learn that
Pobiega
Pobiega4mo ago
its the same command, just with 3 different RIDs
Aadi
Aadi4mo ago
on a side note is there a way i can migrate to the .net core and run away from the .net framework without losing my current github history and stuff?
Angius
Angius4mo ago
You can always just make a quick script with something like Taskfile or Make, so you would just call task publish and it runs all 3 commands There's an Upgrade Assistant And a documentation page on migrating an existing Fx project to .NET
Pobiega
Pobiega4mo ago
yeah you can just replace your .csproj file and some other stuff really either manually or via the upgrade assistant
Aadi
Aadi4mo ago
remove one file, add in the new one ...but this will lose commit history on the file i just deleted? (i care about commit history because it shows my learning well imo)
Pobiega
Pobiega4mo ago
no well, yes or not :p
Aadi
Aadi4mo ago
bruh
Pobiega
Pobiega4mo ago
if you name the file the same, its fine they should both be .csproj anyways it will just be a drastic change
Aadi
Aadi4mo ago
wdym?
Pobiega
Pobiega4mo ago
well, the old csproj files had a different structure so "all of the file" might change or its not that old and then it will be a very small change
Aadi
Aadi4mo ago
i'll move all my classes into one file before to simplify it
Pobiega
Pobiega4mo ago
you dont need to modern .NET apps dont list all cs files they are folder based thank god
Aadi
Aadi4mo ago
so create a new file with the same name (using the .net core nor .net framework) delete the old .csproj add in the new one still chilling?
No description
Pobiega
Pobiega4mo ago
probably better to use the upgrade assistant safer atleast just randomly replacing files then asking us if its fine is... uh... not a good idea if you showed me the old and the new file, maybe but at that point.. just use the upgrade assistant
Aadi
Aadi4mo ago
(apologising in advance but im equally lost trying this)
Pobiega
Pobiega4mo ago
Microsoft
Upgrade Assistant | .NET
Upgrade your projects from .NET Framework to .NET.
Pobiega
Pobiega4mo ago
learn to help yourself its the single most important skill
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Aadi
Aadi3mo ago
i've done this but..what does this actually do? it seems its now a net 8.0 which is nice but i dont think this 'converted' my .net framework v4.8 to .net core v8.0?
Angius
Angius3mo ago
Does it work?
Aadi
Aadi3mo ago
wdym? the code runs, but i dont think thats what you mean currently retrying to do this
Angius
Angius3mo ago
If it runs, then congratulations, you succesfully updated to .NET 8
Aadi
Aadi3mo ago
whoa that simple?
Angius
Angius3mo ago
If the code is simple enough, yeah
Aadi
Aadi3mo ago
so im assuming migration assitanct just updates the .csproj (or at least in this case) for me
Angius
Angius3mo ago
For bigger and more complex projects it does more
Aadi
Aadi3mo ago
so the previous 'dotnet public -c' etc. should work now?
Angius
Angius3mo ago
Yep
Aadi
Aadi3mo ago
hey thanks for your help trying rn got somewhere and now ive got stuck at an error saying "reference assemblies for .net framework v4.8 were not found. isntall them with this link or retarget your application" SUCCESS by that, i mean running: dotnet publish -c Release -r osx-arm64 -p:PublishSingleFile=true didn't throw an error and said 'restored' its looking good, testing with a friend now to see if they can load it up (it works in my terminal)
MODiX
MODiX3mo ago
Sorry @Aadi your message contained blocked content and has been removed! Sorry @Aadi your message contained blocked content and has been removed!
Aadi
Aadi3mo ago
No description
Aadi
Aadi3mo ago
sending this over via an online sharing platform owned by alphabet inc doesnt work however through a macbook-to-macbook system called 'air' followed by 'drop' does make it work but i had to install .net on the other device is the ultimate solution to just get docker / dockerfile?
Angius
Angius3mo ago
You would need Docker installed, then 😛 And the whole overhead and complexity of it $singlefile
MODiX
MODiX3mo ago
dotnet publish -c Release -r <runtime identifier> -p:PublishSingleFile=true Use of -p:PublishSingleFile=true implies --self-contained true. Add --self-contained false to publish as runtime-dependent. -r RID and -p:PublishSingleFile=true can be moved to .csproj as the following properties:
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifier>RID</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
but to target multiple RIDs, you have to use dotnet publish with the -r option for each RID. You can also add -p:IncludeNativeLibrariesForSelfExtract=true to include native libraries (like Common Language Runtime dlls) in the output executable. You might want to instead publish your application compiled Ahead Of Time to native code, see $nativeaot for examples. Single file publishing | Runtime Identifier (RID) catalog | dotnet publish
Angius
Angius3mo ago
Ah This is your debug artifacts Look intio the release folder
Aadi
Aadi3mo ago
nooooo im an idiot lol before when sharing the .exe file it was in bin -> debug so i assumed the same to be true would the other device need to have .net installed? before sending just that file didnt work, it said it couldnt find the .dll file so i had to send over the whole folder
Angius
Angius3mo ago
If it's self-contained, no
Aadi
Aadi3mo ago
"this file is damaged" error when its tried to run google's file sharing called d r i v e doesnt seem to let it download generally speaking, how does the majority share their console apps with friends? do they do what i did and then from within the release folder, they share across the unix executable file and then run it like that? or is it like 99% docker or do people generally not share programs like this ++ ive spent some time trying to learn docker and so far i havent got a successful container and it seems like some more work, but if i have / if its the best option then i will
Angius
Angius3mo ago
Docker is more work for you, but also for whoever wants to run it Far as sharing the executable... I usually just use Github releases
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Aadi
Aadi3mo ago
https://drive.google.com/drive/folders/1SaYKFXTkizdvE6w_939p4VEB-2eJRy5q?usp=sharing i believe i've done it now and with the initial testing it seems to work! Pobiega, thanks for the initial 'dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true ' instructions, they worked brilliantly ZZZ, thanks for general help in...pretty much all of it lol TeBeCo, thanks for the help in updating the .csproj and also for the -o associated with dotnet publish the above link now works, shared it just in case anyone's curious Thank you all once more 🙏
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Aadi
Aadi3mo ago
fair enough 🫡