C
C#10mo 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
Pobiega10mo ago
You'll want to publish your app as a self-contained single file application, with a MacOS RID $singlefile
MODiX
MODiX10mo 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
AadiOP10mo ago
sorry i'm completely lost, please can you break that down a bit for me thanks Pobiega
Pobiega
Pobiega10mo 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
AadiOP10mo 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
Angius10mo ago
I wouldn't say executing a single command is "doing something long"
Pobiega
Pobiega10mo ago
well you will need to republish every time but it is, as zzz said, a single command
Aadi
AadiOP10mo 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
Pobiega10mo 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
AadiOP10mo ago
what goes in the <runtime identifier>? what does runtime-dependent mean?
Pobiega
Pobiega10mo ago
and again, if they are on... what do Mac call it, Silicone? Silica? CPUs, they need another RID
Aadi
AadiOP10mo ago
apple silicon, yes
Pobiega
Pobiega10mo 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
AadiOP10mo 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
Pobiega10mo ago
you can publish for multiple RIDs if needed
Aadi
AadiOP10mo ago
meaning two formats, for M1 and intel-based macs
Pobiega
Pobiega10mo ago
yes so, to run a .NET project, you must have the .NET runtime
Aadi
AadiOP10mo ago
i feel incompetend but pasting that into terminal gives:
No description
Aadi
AadiOP10mo ago
my game is using the .NET frameowrk v4.8
Pobiega
Pobiega10mo ago
oh
Angius
Angius10mo ago
Oof
Pobiega
Pobiega10mo ago
you're fucked then
Angius
Angius10mo ago
No Mac for you
Pobiega
Pobiega10mo ago
no mac for you indeed
Angius
Angius10mo ago
.NET Framework is strictly Windows-only
Aadi
AadiOP10mo ago
and why's that? uhoh
Pobiega
Pobiega10mo ago
.NET fx is old and dead it died in 2016
Angius
Angius10mo ago
Only since .NET Core did it become cross-platform
Aadi
AadiOP10mo ago
i can copy pasta my code into a new form of project format?
Angius
Angius10mo ago
It's Winforms? Then no Winforms is Windows-only
Pobiega
Pobiega10mo ago
you said it was a console app no?
Angius
Angius10mo ago
Windows Forms
Pobiega
Pobiega10mo ago
if its a console app, you can migrate
Aadi
AadiOP10mo ago
i use jetbrains rider for macos here's the settings whenever i create a new solution
No description
Pobiega
Pobiega10mo ago
yeah you picked the wrong thing
Aadi
AadiOP10mo ago
no worries, i can copy pasta or migrate it over right?
Pobiega
Pobiega10mo ago
I'm on Rider EAP so my new solution window is different...
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
lets see if I have non-EAP installed
Angius
Angius10mo ago
You want the Console project without .NET Framework part
Aadi
AadiOP10mo ago
i feel like im meant to use one of these
No description
Pobiega
Pobiega10mo ago
No description
Pobiega
Pobiega10mo ago
there
Angius
Angius10mo ago
No description
Pobiega
Pobiega10mo ago
you want to use the ones from the .NET / .NET Core section pretend .NET framework doesnt exist
Aadi
AadiOP10mo ago
i feel like im making progress
No description
Aadi
AadiOP10mo ago
thanks
Angius
Angius10mo ago
Yeah, this will do the trick
Aadi
AadiOP10mo ago
done, thank you
Angius
Angius10mo ago
Just check the Create GIT repository box while you're at it
Aadi
AadiOP10mo ago
so create a new solution there, copy pasta everything over, then we're chilling?
Angius
Angius10mo ago
Yeah
Pobiega
Pobiega10mo ago
kinda
Angius
Angius10mo ago
Should work
Pobiega
Pobiega10mo 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
AadiOP10mo 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
Pobiega10mo 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
AadiOP10mo 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
Pobiega10mo ago
its the same command, just with 3 different RIDs
Aadi
AadiOP10mo 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
Angius10mo 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
Pobiega10mo ago
yeah you can just replace your .csproj file and some other stuff really either manually or via the upgrade assistant
Aadi
AadiOP10mo 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
Pobiega10mo ago
no well, yes or not :p
Aadi
AadiOP10mo ago
bruh
Pobiega
Pobiega10mo ago
if you name the file the same, its fine they should both be .csproj anyways it will just be a drastic change
Aadi
AadiOP10mo ago
wdym?
Pobiega
Pobiega10mo 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
AadiOP10mo ago
i'll move all my classes into one file before to simplify it
Pobiega
Pobiega10mo ago
you dont need to modern .NET apps dont list all cs files they are folder based thank god
Aadi
AadiOP10mo 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
Pobiega10mo 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
AadiOP10mo ago
(apologising in advance but im equally lost trying this)
Pobiega
Pobiega10mo ago
Microsoft
Upgrade Assistant | .NET
Upgrade your projects from .NET Framework to .NET.
Pobiega
Pobiega10mo ago
learn to help yourself its the single most important skill
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Aadi
AadiOP10mo 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
Angius10mo ago
Does it work?
Aadi
AadiOP10mo ago
wdym? the code runs, but i dont think thats what you mean currently retrying to do this
Angius
Angius10mo ago
If it runs, then congratulations, you succesfully updated to .NET 8
Aadi
AadiOP10mo ago
whoa that simple?
Angius
Angius10mo ago
If the code is simple enough, yeah
Aadi
AadiOP10mo ago
so im assuming migration assitanct just updates the .csproj (or at least in this case) for me
Angius
Angius10mo ago
For bigger and more complex projects it does more
Aadi
AadiOP10mo ago
so the previous 'dotnet public -c' etc. should work now?
Angius
Angius10mo ago
Yep
Aadi
AadiOP10mo 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
MODiX10mo ago
Sorry @Aadi your message contained blocked content and has been removed! Sorry @Aadi your message contained blocked content and has been removed!
Aadi
AadiOP10mo ago
No description
Aadi
AadiOP10mo 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
Angius10mo ago
You would need Docker installed, then 😛 And the whole overhead and complexity of it $singlefile
MODiX
MODiX10mo 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
Angius10mo ago
Ah This is your debug artifacts Look intio the release folder
Aadi
AadiOP10mo 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
Angius10mo ago
If it's self-contained, no
Aadi
AadiOP10mo 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
Angius10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
Aadi
AadiOP10mo 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 User10mo ago
Message Not Public
Sign In & Join Server To View
Aadi
AadiOP10mo ago
fair enough 🫡
Want results from more Discord servers?
Add your server