You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Visual Studio for Mac中基于C#创建跨平台桌面应用并在Windows端编译的实现方案问询

Cross-Platform Desktop Solutions for Your Mac → Windows VM Workflow

Hey there! I totally get wanting to code on your Mac (way nicer than a VM, right?) and then ship your app to run on Windows 10. Let's walk through the best options that fit your exact needs, including a clear path for .NET MAUI (the successor to Xamarin.Forms) which is perfect for this scenario:

This is Microsoft's official cross-platform framework for building desktop (Windows/Mac) and mobile apps with shared C#/XAML code—exactly what you were looking for with Xamarin.Forms, but updated and fully supported across both Visual Studio for Mac and Windows.

Steps to implement:

  1. Create the project on Visual Studio for Mac

    • Open VS for Mac, click "Create a new project"
    • Search for .NET MAUI App, select it, then click "Next"
    • Name your project, pick a save location, and choose a stable .NET version (7 or 8 work great)
    • Once created, you can edit code, test the Mac desktop version, and share 90%+ of your code with Windows
  2. Move the project to your Windows VM

    • Sync the entire project folder to your VM using a shared folder, cloud storage (OneDrive/Dropbox), or direct file transfer
    • Open Visual Studio for Windows, click "Open a project or solution", and select the .sln file from your synced folder
  3. Compile and run on Windows 10

    • First, make sure VS for Windows has the .NET Multi-platform App UI development workload installed (open the VS Installer, check this under "Desktop & Mobile")
    • In the VS toolbar, set the target platform to Windows Machine (or Windows (XAML))
    • Hit the run button—your app will compile and launch directly on Windows 10!

Option 2: WPF with .NET 5+

If you only need a Windows desktop app (no Mac desktop support), you can still write all your code on Mac and compile it on Windows. VS for Mac lets you edit WPF code (XAML and C#), even though you can't run it locally.

Steps to implement:

  1. Create a WPF project on Visual Studio for Mac
    • New project → search for WPF App (.NET)
    • Configure your project settings and create it—you can edit all your UI and logic code here
  2. Sync to Windows VM
    • Transfer the project folder to your VM as described above
  3. Compile on Windows
    • Open the solution in VS for Windows (make sure the .NET Desktop Development workload is installed)
    • Compile and run—WPF will natively run on Windows 10

Option 3: Electron (Web-Based)

If you prefer working with HTML/CSS/JS, Electron lets you build cross-platform desktop apps using web tech. You can edit code on Mac (VS for Mac or VS Code works great) and then run/pack it on Windows.

Steps to implement:

  1. Set up the Electron project on Mac
    • Open Terminal, create a new folder, run npm init to set up your project
    • Install Electron: npm install electron --save-dev
    • Write your main process code (main.js) and UI (index.html)—VS for Mac can open the folder for editing
    • Test locally on Mac with npx electron .
  2. Run on Windows VM
    • Sync the project folder to your VM, ensure Node.js and npm are installed on Windows
    • Run npm install to set up dependencies, then npx electron . to launch the app
    • To package it as a Windows executable, install electron-packager with npm install electron-packager --save-dev, then run npx electron-packager . --platform=win32

Quick Tips

  • Keep .NET versions aligned: Make sure both Mac and Windows have the same .NET SDK version installed to avoid compilation errors
  • Simplify file sync: Use a shared folder between your Mac and VM (most virtualization tools like Parallels/VirtualBox support this) for seamless project access
  • Skip VM coding entirely: Since you're only compiling/running on the VM, you can do all your development on Mac and just switch to the VM when you need to test Windows-specific behavior

内容的提问来源于stack exchange,提问作者dennis605

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 13:02:36