Skip to content

Commit 976ddb3

Browse files
committed
Add workaround for Mono xbuild MSBuild errors on macOS/Linux
- Skip MSBuildVersion parameter on non-Windows platforms to avoid triggering Mono's broken xbuild - Add ignoreFailuresOnNonWindows option to NuGetRestore task - Allow build to continue on macOS/Linux when MSBuild errors occur (Mono limitation) - MSBuild errors are logged as warnings instead of failing the build This allows NuGet restore to work on macOS/Linux where Mono's xbuild has known limitations with NuGet restore operations.
1 parent ff38e47 commit 976ddb3

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/main/groovy/com/ullink/BaseNuGet.groovy

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,38 @@ class BaseNuGet extends Exec {
172172
execAction.setExecutable(executable)
173173
execAction.setArgs(getArgs())
174174
execAction.setWorkingDir(project.projectDir)
175-
execAction.execute()
175+
176+
// Check if we should ignore failures on non-Windows (for Mono xbuild issues)
177+
def shouldIgnoreFailures = false
178+
if (this.hasProperty('ignoreFailuresOnNonWindows') && this.ignoreFailuresOnNonWindows) {
179+
shouldIgnoreFailures = !isFamily(FAMILY_WINDOWS)
180+
}
181+
182+
try {
183+
execAction.execute()
184+
} catch (Exception e) {
185+
if (shouldIgnoreFailures) {
186+
project.logger.warn("NuGet restore failed on non-Windows platform (likely Mono xbuild issue), ignoring: ${e.message}")
187+
return
188+
}
189+
throw e
190+
}
176191
} else {
177192
// Fallback: try to call Exec.exec() via reflection
178193
try {
179194
def execMethod = Exec.class.getDeclaredMethod("exec")
180195
execMethod.setAccessible(true)
181196
execMethod.invoke(this)
182197
} catch (Exception e) {
198+
// Check if we should ignore failures on non-Windows
199+
def shouldIgnoreFailures = false
200+
if (this.hasProperty('ignoreFailuresOnNonWindows') && this.ignoreFailuresOnNonWindows) {
201+
shouldIgnoreFailures = !isFamily(FAMILY_WINDOWS)
202+
}
203+
if (shouldIgnoreFailures) {
204+
project.logger.warn("NuGet restore failed on non-Windows platform (likely Mono xbuild issue), ignoring: ${e.message}")
205+
return
206+
}
183207
throw new RuntimeException("Cannot execute NuGet command - no ExecActionFactory available", e)
184208
}
185209
}

src/main/groovy/com/ullink/NuGetRestore.groovy

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import org.gradle.api.tasks.InputFile
77
import org.gradle.api.tasks.Optional
88
import org.gradle.api.tasks.OutputDirectory
99

10+
import static org.apache.tools.ant.taskdefs.condition.Os.*
11+
1012
class NuGetRestore extends BaseNuGet {
1113

1214
@Optional
@@ -36,6 +38,8 @@ class NuGetRestore extends BaseNuGet {
3638
@Optional
3739
@Input
3840
def packagesDirectory
41+
@Input
42+
def ignoreFailuresOnNonWindows = false
3943

4044
NuGetRestore() {
4145
super('restore')
@@ -81,8 +85,15 @@ class NuGetRestore extends BaseNuGet {
8185
if (packagesDirectory) args '-PackagesDirectory', packagesDirectory
8286
if (solutionDirectory) args '-SolutionDirectory', solutionDirectory
8387
if (disableParallelProcessing) args '-DisableParallelProcessing'
84-
if (!msBuildVersion) msBuildVersion = GradleHelper.getPropertyFromTask(project, 'version', 'msbuild')
85-
if (msBuildVersion) args '-MsBuildVersion', msBuildVersion
88+
89+
// Skip MSBuildVersion on non-Windows platforms (macOS/Linux) because Mono's xbuild/MSBuild
90+
// doesn't work properly with NuGet restore and causes "Too many project files specified" errors
91+
if (!isFamily(FAMILY_WINDOWS)) {
92+
project.logger.debug("Skipping MSBuildVersion on non-Windows platform to avoid Mono xbuild issues")
93+
} else {
94+
if (!msBuildVersion) msBuildVersion = GradleHelper.getPropertyFromTask(project, 'version', 'msbuild')
95+
if (msBuildVersion) args '-MsBuildVersion', msBuildVersion
96+
}
8697

8798
project.logger.info "Restoring NuGet packages " +
8899
(sources ? "from $sources" : '') +

0 commit comments

Comments
 (0)