Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should be able to compile on macOS with 'dotnet build' #222

Closed
pardeike opened this issue Jul 22, 2023 · 12 comments
Closed

Should be able to compile on macOS with 'dotnet build' #222

pardeike opened this issue Jul 22, 2023 · 12 comments
Labels
enhancement New feature or request

Comments

@pardeike
Copy link

dnSpyEx version

master

Describe the Bug

By adding

<EnableWindowsTargeting>true</EnableWindowsTargeting>

as described in NETSDK1100: Set the EnableWindowsTargeting property to true you are enabling macOS users to build the project too.

Motivation: I use Visual Studio on my MacBook to compile my projects because it is running native. I also use Parallels to run windows applications (especially dnSpy because I am a modder). If I want to do small changes to the source of dnSpy I would need to build it in Parallels which is slow.

How To Reproduce

Rundotnet build on macOS with the proper .NET SDk installed. It will tell you the link I posted above.

Expected Behavior

It should build

Actual Behavior

It does not build

Additional Context

Maybe it should even run native on macOS - that would make my day because I do mod development at home with my stationary PC and when on the go, I prefer my lightweight MacBook Air.

@pardeike pardeike added the bug Something isn't working label Jul 22, 2023
@ElektroKill
Copy link
Member

Hi, I've never heard of this properly before. Does adding this option allow at least one of the dnSpy frontends (CLI or GUI) to compile without issues on Linux or MacOS? Asking this since I don't have a MacOS or Linux computer handy at the moment. If this option does indeed allow dnSpy to compile on other platforms without having any impact on the windows compilation/output binaries, I'd be willing to do this change, perhaps, if you want to you can even PR it as part of DnSpyCommon.props for example.

As for running natively on other platforms, the possibility of this is rather slim since dnSpy runs on WPF, a non-cross-platform Windows UI framework, and porting it to a different UI framework would be an enormous undertaking. As for the CLI, there is a chance it could run on Linux since I don't remember there being anything Windows specific there. I would have to look into that further.

@ElektroKill ElektroKill added enhancement New feature or request and removed bug Something isn't working labels Jul 23, 2023
@pardeike
Copy link
Author

Yes, I added the property to a few places (probably a few too many but who cares) and did build an net48 exe that I then ran via Parallels emulation. Pretty sure it's the real deal. If I get the time I do a PR.

Regarding WPF, yeah I know. We have the same question at work and no good solution.

I did waste a few hours and tried to run it under Wine and/or Mono but without success. Such a shame, I miss dnSpy on the macOS platform a lot.

@ElektroKill
Copy link
Member

Yes, I added the property to a few places (probably a few too many but who cares) and did build an net48 exe that I then ran via Parallels emulation. Pretty sure it's the real deal. If I get the time I do a PR.

Just adding to DnSpyCommon.props should be enough as all projects in the solution import that file.

Regarding WPF, yeah I know. We have the same question at work and no good solution.

Avalonia (the cross platform UI framework for .NET) offers a solution for WPF apps to run without rewrites on top of Avalonia. Its called XPF, however it’s only a commercial solution and not designed for open source projects :/

Here is a link if you are perhaps interested: https://avaloniaui.net/XPF

I did waste a few hours and tried to run it under Wine and/or Mono but without success. Such a shame, I miss dnSpy on the macOS platform a lot.

Interesting, I heard some people had some degree of success with running it under Wine on Linux.

@benediktwerner
Copy link

I did waste a few hours and tried to run it under Wine and/or Mono but without success. Such a shame, I miss dnSpy on the macOS platform a lot.

For what it's worth, I was able to get the .NET Framework version to work using winetricks -q dotnet48. Though unfortunately, it's not fast and the text is a bit blurry.

@pardeike
Copy link
Author

On Apple Silicon? Could you walk me through it?

@ElektroKill
Copy link
Member

@pardeike Could you verify if the changes done in #223 allow you to compile dnSpy on macOS as expected?

@pardeike
Copy link
Author

I'll try tonight

@benediktwerner
Copy link

benediktwerner commented Jul 29, 2023

On Apple Silicon? Could you walk me through it?

Yeah, on Apple Silicon and MacOS Ventura. I think all I really did was brew install winetricks, winetricks -q dotnet48, and then wine64 dnSpy.exe from https://github.com/dnSpyEx/dnSpy/releases/download/v6.4.0/dnSpy-netframework.zip worked.

To be specific, I'm using the wine version from the Apple Game Porting Toolkit (following https://www.applegamingwiki.com/wiki/Game_Porting_Toolkit) and I installed winetricks from x86_64 brew and ran it from an x86_64 shell but not sure whether that matters.

But maybe it helps, here should be more or less the exact equivalent of what I did originally (i didn't have wine installed before this):

  • softwareupdate --install-rosetta to make sure rosetta is installed
  • Visit Apple Developer Downloads site
    • Search for Command Line Tools for Xcode 15 beta, download the dmg file, and run the contained pkg file. "If you have an old version Xcode installed, remove it." (i didn't)
    • Search for Game Porting Toolkit, download it and open/mount the dmg file. I used the Beta 1.02 version which was the newest at the time.
  • arch -x86_64 zsh to start an x86_64 shell (i used this for all further commands)
  • /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" to install the x86_64 version of homebrew

I then adjusted my ~/.zshrc to have

if [ "$(arch)" = "arm64" ]; then
    eval "$(/opt/homebrew/bin/brew shellenv)"
else
    eval "$(/usr/local/bin/brew shellenv)"
fi

so it selects the right homebrew depending on the arch configuration of the shell and then restarted my shell and ran arch -x86_64 zsh again. which brew should now give /usr/local/bin/brew (which is the x86 version, the arm version is in /opt/homebrew/bin/brew).

  • brew tap apple/apple http://github.com/apple/homebrew-apple
  • brew -v install apple/apple/game-porting-toolkit (takes a very long time, like 1-2h)
  • at this point, wine should be installed and accessible via wine64
  • ditto /Volumes/Game\ Porting\ Toolkit-1.0/lib/ `brew --prefix game-porting-toolkit`/lib/ this is where the game porting toolkit dmg mount is needed, it adds some libs to wine, maybe that helped?
  • brew install winetricks
  • export WINEPREFIX=~/.wine-dontnet48
  • export WINE=wine64
  • export WINEESYNC=1 i don't think this is necessary but this is how the gameportingtoolkit always runs wine and once the wineserver started with it, you always need to use it or restart the server
  • wine64 winecfg to create the wineprefix. i selected windows 10 in the window that opened and pressed ok
  • winetricks -q dotnet48 to install .NET Framework 4.8 into the wineprefix
  • and then wine64 dnSpy.exe (make sure it's the .NET framework dnSpy version)

I might have started it via the game porting toolkit but that also just starts wine:

  • cp /Volumes/Game\ Porting\ Toolkit*/gameportingtoolkit* /usr/local/bin copies the gameportingtoolkit scripts from the dmg and then:
  • gameportingtoolkit ~/.wine-dontnet48 dnSpy.exe is WINEESYNC=1 WINEPREFIX="~/.wine-dotnet48" wine64 dnSpy.ex

And I then also created a dnSpy "application" using Automator following the Apple Gaming Wiki Guide:

#!/bin/zsh

export PATH="/usr/local/bin:${PATH}"

arch -x86_64 gameportingtoolkit ~/.wine-dotnet48 /path/to/dnSpy/dnSpy.exe

Though just WINEESYNC=1 WINEPREFIX=~/.wine-dotnet48 wine64 dnSpy.exe even without using arch -x86_64 also works for me. My Wine is an x86 version anyways (idk if an ARM version exists?) so it goes through Rosetta anyways.

@pardeike
Copy link
Author

@pardeike Could you verify if the changes done in #223 allow you to compile dnSpy on macOS as expected?

Build succeeded.
    0 Warning(s)
    0 Error(s)

The branch feature/windowstargeting builds fine.

@pardeike
Copy link
Author

@benediktwerner my first naive approach gives me

ap@Andreass-MacBook-Air net48 % wine64 dnSpy.exe
0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
0084:fixme:hid:handle_IRP_MN_QUERY_ID Unhandled type 00000005
0024:err:module:fixup_imports_ilonly mscoree.dll not found, IL-only binary L"dnSpy.exe" cannot be loaded
0024:err:module:LdrInitializeThunk Importing dlls for L"\\\\?\\unix\\tmp\\dnSpy\\dnSpy\\dnSpy\\bin\\Debug\\net48\\dnSpy.exe" failed, status c0000135

I am going to try follow all your detailed steps and see if that helps. My current installation is kind of frankensteined...

@ElektroKill
Copy link
Member

@pardeike Could you verify if the changes done in #223 allow you to compile dnSpy on macOS as expected?

Build succeeded.
    0 Warning(s)
    0 Error(s)

The branch feature/windowstargeting builds fine.

Great to hear that, the changes there have been merged into master! dnSpy should be compilable on macOS and Linux now but with some limitations like missing file icon, file properties, and an invalid subsystem set in the PE as mentioned in PR #223. The limitations will probably be resolved in a future version of .NET (hopefully .NET 8).

@pardeike
Copy link
Author

Great that I could help. Let's close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants