简体   繁体   中英

How do I compile a C# application on a Mac in Visual Studio?

Basically, my school only has Mac computers, however they're telling me to learn C# and to do so using Visual Studio. However, the school program is fairly new and the projects are self-guided. I've been coding in C# using Visual Studio and it's been working so far - it's run successfully and everything. However, I can't seem to find a way to export or publish my code into a standalone application. I've tried using WineBottler to convert the .exe into a .dmg, but I can't seem to make it work.

How should I do this? Moving to Windows or another IDE/compiler isn't an option. I've currently been creating my projects in a Console App, but I could change that if necessary.

After quite a bit of experimentation and research, I've found that while you can publish a .NET Core Console App within Visual Studio for Mac, the feature is not supported within the GUI of the program (for whatever reason). In order to publish, you have to Control-Click on the solution in the Solution Explorer and open the project in the command line by clicking Tools > Open In Terminal. Once there, type in the command: dotnet publish -c Release --framework netcoreapp2.1 --runtime osx-x64 This will create a self-contained program for 64-bit mac os on the v2.1 .NET Core framework. The runtime can be changed for different operating systems and the version number for netcoreapp can be changed based on which version you're using and what is compatible with any plugins for your program. The final product will be found in yourprojectfolder/yourprojectname/bin/Release/netcoreapp2.1/osx-x64/publish

You should have no issues creating and compiling .NET CORE console apps using a Mac. These apps will have limited .NET functionality, do not have .exe files, and are platform agnostic. Here is a quick guide you can reference to decide if .NET CORE is the right option for you.

If you are trying to create WinForm apps or something similar, you cannot do this on a Mac. There are "work arounds" using Wine or other tools, but my experience with those options has been suboptimal at best. If you need to create apps like this, then your best option is to program on a Windows machine. Perhaps ask your school to enable bootcamp and install Windows 10 OS on one of the Mac machines.

You can generate exe using the terminal if you are on OSX. You can follow this post

It requires :

  • Visual Studio For Mac
  • A .cs file
  • Few lines in terminal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM