def METHOD_NAME(run_tests: bool) -> BuildResult:
    output_dir = "output"
    paths = os.listdir(os.getcwd())
    sln = [p for p in paths if Path(p).suffix == ".sln"]
    csproj = [p for p in paths if Path(p).suffix == ".csproj"]
    if sln and csproj:
        return BuildResult.fail("Both .sln and .csproj file was found in the root directory.")
    if not sln and not csproj:
        return BuildResult.fail("No .sln or .csproj file was found in the root directory.")
    if len(sln) > 1:
        return BuildResult.fail("Multiple .sln files were found")
    if len(csproj) > 1:
        return BuildResult.fail("Multiple .csproj files were found")
    # build or build+run tests
    tests_path = "tests.xml"
    env = os.environ.copy()
    env["DOTNET_CLI_HOME"] = "/tmp/dotnet-cli-home"
    # workaround for https://github.com/dotnet/core/issues/7868
    env["XDG_DATA_HOME"] = "/tmp/dotnet-cli-home"
    env["DOTNET_NOLOGO"] = "1"
    # workaround for https://github.com/dotnet/sdk/issues/31457
    env["DOTNET_EnableWriteXorExecute"] = "0"
    cmd = ['dotnet']
    if run_tests:
        cmd += ['test', '-l', f'trx;LogFileName=../../{tests_path}']
    else:
        cmd += ['publish', '--use-current-runtime', '--self-contained', '-o', output_dir]
    process = subprocess.run(cmd, env=env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    # find an executable file in the output directory and create a symlink for the following tasks
    # in the pipeline
    exe_project_names = get_executable_project_names(Path(os.getcwd()))
    binaries = [Path(output_dir) / name for name in exe_project_names]
    if len(binaries) == 1:
        os.symlink(binaries[0], "main")
    elif len(binaries) > 1:
        return BuildResult.fail(
            f"Multiple executable projects found ({','.join(exe_project_names)}). "
            f"Only upload one executable project."
        )
    # parse compiler warnings / errors and add them as comments to the code
    comments = defaultdict(list)
    for line in process.stdout.decode().splitlines():
        # /work/Program.cs(82,32): warning CS8600: Converting null literal or possible null value to non-nullable type. [/work/Du1.csproj]
        match = re.match(r'^/work/(?P<path>[^(]+)\((?P<line>[0-9]+),[0-9]+\): [^ ]+ (?P<source>[^ :])+:\s*(?P<text>.*?)\s\[.*?\]$', line)
        if match:
            comment = match.groupdict()
            comments[comment['path']].append(comment)  
    tests = []
    if run_tests:
        tests = parse_tests_report(tests_path)
    return BuildResult(
        success=process.returncode == 0,
        output=process.stdout.decode(),
        comments=comments,
        tests=tests,
    )