 public func buildInDirectory(directoryURL: NSURL, configuration: String = "Release") -> Promise<Result<()>> {
 	precondition(directoryURL.fileURL)
 
+	let result = locateProjectInDirectory(directoryURL)
+	if let error = result.error() {
+		return Promise { $0.put(failure(error)) }
+	}
+
+	let locator = result.value()!
+
+	var arguments = [ "xcodebuild" ]
+	arguments += locator.arguments
+	arguments.append("build")
+
 	let directoryPath = directoryURL.path
-	let desc = TaskDescription(launchPath: "/usr/bin/xcrun", arguments: [ "xcodebuild", "build" ], workingDirectoryPath: directoryPath)
+	let desc = TaskDescription(launchPath: "/usr/bin/xcrun", arguments: arguments, workingDirectoryPath: directoryPath)
 
 	return launchTask(desc).then { status in
 		return Promise { sink in

/// Attempts to locate a project or workspace within the given directory.
public func locateProjectInDirectory(directoryURL: NSURL) -> Result<ProjectLocator> {
	let enumerationOptions = NSDirectoryEnumerationOptions.SkipsHiddenFiles | NSDirectoryEnumerationOptions.SkipsPackageDescendants
	
	var enumerationError: NSError?
	let enumerator = NSFileManager.defaultManager().enumeratorAtURL(directoryURL, includingPropertiesForKeys: [ NSURLTypeIdentifierKey ], options: enumerationOptions) { (URL, error) in
		enumerationError = error
		return false
	}
	
	if let enumerator = enumerator {
		var matches: [ProjectEnumerationMatch] = []


		case let .ProjectFile(URL):
			assert(URL.fileURL)
			return URL
		}
	}

	/// The arguments that should be passed to `xcodebuild` to help it locate
	/// this project.
	private var arguments: [String] {
		switch (self) {
		case let .Workspace(URL):
			return [ "-workspace", URL.path! ]

		case let .ProjectFile(URL):
			return [ "-project", URL.path! ]
		}
	}
}
