@@ -13,21 +13,33 @@ if [ -z "$PROJECT_OR_SLN" ]; then
1313 PROJECT_OR_SLN=" ."
1414fi
1515
16- echo " --- Building $PROJECT_OR_SLN (Framework-Dependent) ---"
16+ echo " --- Building $PROJECT_OR_SLN ---"
17+ # Build natively on Linux to maintain ergonomics and lock file compatibility.
1718dotnet build " $PROJECT_OR_SLN "
1819
19- # Get the project name to look for the matching executable
20- # If the input contains a path, take the filename. Then strip any C# project/solution extension.
20+ # Get the project name to look for the matching binary
21+ # If the input contains a path, take the filename and strip any C# project/solution extension.
2122PROJECT_NAME=$( basename " $PROJECT_OR_SLN " | sed -E ' s/\.(csproj|sln|fsproj|vbproj)$//' )
2223
23- # Search for the executable in the most common output paths
24- if [ -d " bin" ]; then
25- # Prioritize exact matches for .exe or .dll (for tests)
26- EXE_PATH=$( find bin -name " ${PROJECT_NAME} .exe" -o -name " ${PROJECT_NAME} .dll" | head -n 1)
27- # Fallback to any executable if the exact match wasn't found
28- if [ -z " $EXE_PATH " ]; then
29- EXE_PATH=$( find bin -name " *.exe" | head -n 1)
24+ # Search for the binary in common output paths
25+ find_binary () {
26+ local base=" $1 "
27+ # Prioritize exact matches for .exe (if built with RID)
28+ local found=$( find " $base " -name " ${PROJECT_NAME} .exe" | head -n 1)
29+ if [ -z " $found " ]; then
30+ # Fallback to .dll (portable app built without RID)
31+ found=$( find " $base " -name " ${PROJECT_NAME} .dll" | head -n 1)
32+ fi
33+ # Secondary fallback to any executable in the tree
34+ if [ -z " $found " ]; then
35+ found=$( find " $base " -maxdepth 5 -name " *.exe" | head -n 1)
3036 fi
37+ echo " $found "
38+ }
39+
40+ EXE_PATH=" "
41+ if [ -d " bin" ]; then
42+ EXE_PATH=$( find_binary " bin" )
3143fi
3244
3345if [ -z " $EXE_PATH " ]; then
@@ -39,22 +51,29 @@ if [ -z "$EXE_PATH" ]; then
3951 fi
4052
4153 if [ -n " $BASE_DIR " ] && [ -d " $BASE_DIR /bin" ]; then
42- # Prioritize exact matches for .exe or .dll (for tests)
43- EXE_PATH=$( find " $BASE_DIR /bin" -name " ${PROJECT_NAME} .exe" -o -name " ${PROJECT_NAME} .dll" | head -n 1)
44- # Fallback to any executable if the exact match wasn't found
45- if [ -z " $EXE_PATH " ]; then
46- EXE_PATH=$( find " $BASE_DIR /bin" -name " *.exe" | head -n 1)
47- fi
54+ EXE_PATH=$( find_binary " $BASE_DIR /bin" )
4855 fi
4956fi
5057
5158if [ -f " $EXE_PATH " ]; then
52- echo " --- Running $EXE_PATH via Wine ---"
53- # If it's a DLL, we run it via the windows dotnet host
54- if [[ " $EXE_PATH " == * .dll ]]; then
55- wine " C:\\ dotnet\\ dotnet.exe" " $EXE_PATH " " $@ "
59+ # Ensure we use an absolute Unix path first
60+ ABS_EXE_PATH=$( realpath " $EXE_PATH " )
61+ DIR_NAME=$( dirname " $ABS_EXE_PATH " )
62+
63+ # Convert Unix paths to Windows paths for Wine
64+ WIN_EXE_PATH=$( winepath -w " $ABS_EXE_PATH " )
65+ WIN_DIR_NAME=$( winepath -w " $DIR_NAME " )
66+
67+ echo " --- Running $ABS_EXE_PATH via Wine ---"
68+
69+ # Use 'wine cmd /c' to ensure environment variables like PATH and DOTNET_ROOT are handled correctly
70+ # We also 'cd' into the directory to help the host resolve dependencies.
71+ if [[ " $ABS_EXE_PATH " == * .dll ]]; then
72+ # For DLLs, run via the Windows .NET host
73+ wine cmd /c " cd /d $WIN_DIR_NAME && C:\\ dotnet\\ dotnet.exe $WIN_EXE_PATH " " $@ "
5674 else
57- wine " $EXE_PATH " " $@ "
75+ # For native .exes, run directly
76+ wine cmd /c " cd /d $WIN_DIR_NAME && $WIN_EXE_PATH " " $@ "
5877 fi
5978else
6079 echo " Error: Could not find executable for $PROJECT_OR_SLN "
0 commit comments