Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,30 +78,40 @@ internal static class BuildCacheFileUtilities
</Project>
""";

internal static async Task<string> BuildAndCreateCacheFileAsync(string csprojFilePath)
internal static async Task BuildAndCreateCacheFileAsync(string csprojFilePath)
{
if (string.IsNullOrEmpty(csprojFilePath) || !File.Exists(csprojFilePath))
Comment thread
ocallesp marked this conversation as resolved.
Outdated
{
throw new ArgumentException($"The csproj file path is either null or does not exist: {csprojFilePath}");
}

DirectoryInfo directoryInfo = new DirectoryInfo(Path.GetDirectoryName(csprojFilePath));
FileInfo lastBuildErrorLogFile = new FileInfo(Path.Combine(directoryInfo.FullName, ".net-interactive-builderror"));

CleanObjFolder(directoryInfo);

string tempDirectoryBuildTarget =
Path.Combine(Path.GetDirectoryName(csprojFilePath), DirectoryBuildTargetFilename);
File.WriteAllText(tempDirectoryBuildTarget, DirectoryBuildTargetsContent);
string tempDirectoryBuildTarget = Path.Combine(Path.GetDirectoryName(csprojFilePath), DirectoryBuildTargetFilename);

var args = "";
if (Path.Exists(csprojFilePath))
try
{
File.WriteAllText(tempDirectoryBuildTarget, DirectoryBuildTargetsContent);
}
catch (Exception ex)
Comment thread
ocallesp marked this conversation as resolved.
Outdated
{
args = $@"""{csprojFilePath}"" {args}";
throw new IOException($"Failed to write to {tempDirectoryBuildTarget}.", ex);
}

var args = $@"{csprojFilePath}";

var result = await new Dotnet(directoryInfo).Build(args: args);

if (result.ExitCode != 0)
{
var errorMessage = $"Build failed with exit code {result.ExitCode}. See {lastBuildErrorLogFile.FullName} for details.";
File.WriteAllText(
lastBuildErrorLogFile.FullName,
string.Join(Environment.NewLine, result.Error));
throw new InvalidOperationException(errorMessage);
Comment thread
ocallesp marked this conversation as resolved.
Outdated
}
else if (lastBuildErrorLogFile.Exists)
{
Expand All @@ -111,9 +121,11 @@ internal static async Task<string> BuildAndCreateCacheFileAsync(string csprojFil
// Clean up the temp project file
File.Delete(tempDirectoryBuildTarget);

result.ThrowOnFailure();

return string.Empty;
var cacheFile = FindCacheFile(directoryInfo);
if (cacheFile == null || !cacheFile.Exists)
{
throw new FileNotFoundException($"Cache file not found after build completion in directory: {directoryInfo.FullName}");
}
}

private static void CleanObjFolder(DirectoryInfo directoryInfo)
Expand Down