Die Veröffentlichung funktioniert die meiste Zeit, aber versagt intermittierend < /strong> mit dem folgenden Fehler: < /p>
Fehler MSB4018: Die "Generatebunty" -Tasksfehler.
Systems. /> 'C: \ user \ myComputer \ desktop \ veröffentlicht
profiles\Master\MyDesktopapp.exe', da es von einem anderen
-Prozess verwendet wird. [E: \ My Projects \ MyDesktopapp \ Winapp \ winapp.csproj]
Zuerst habe ich direkt das Veröffentlichen von Logo veröffentlicht, als es anfing zu versagen. />
Code: Select all
static async Task Main()
{
Setups = new List();
SetSetups();
foreach(var setup in Setups)
{
Console.WriteLine($"\n=== Building Setup with {setup.MSIName} ===");
UpdateCsprojIcon(setup.IconPath);
if(!CleanProject())
{
}
if (!ReBuildSolution("Release"))
{
Console.WriteLine("❌ Rebuilding solution failed.");
continue;
}
if (!DotnetPublish())
{
Console.WriteLine("❌ dotnet publish failed.");
continue;
}
if (!ReBuildProject(setup.SetupProjectPath, "Release"))
{
Console.WriteLine("❌ Setup project build failed.");
continue;
}
// Wait for .msi file to appear
await Task.Delay(5000);
if (File.Exists(setup.MSIOutputPath))
{
File.Copy(setup.MSIOutputPath, setup.CopyMSITo, overwrite: true);
Console.WriteLine($"✅ Copied MSI to: {setup.CopyMSITo}");
}
else
{
Console.WriteLine("❌ MSI file not found.");
}
}
Console.WriteLine("\n🎉 Done!");
}
< /code>
Die Methoden, die es verwendet, erwähne ich unten < /p>
static void UpdateCsprojIcon(string iconPath)
{
Console.WriteLine($"Updating icon to: {iconPath}");
string csproj = File.ReadAllText(csprojPath);
csproj = Regex.Replace(csproj, ".*?", $"{iconPath}");
File.WriteAllText(csprojPath, csproj);
}
static bool CleanProject()
{
Console.WriteLine("🚀 Running dotnet clean...");
var process = Process.Start(new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"clean \"{csprojPath}\" -c Release",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
});
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.WriteLine("[OUT] " + e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.Error.WriteLine("[ERR] " + e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
}
return process.ExitCode == 0;
}
static bool DotnetPublish()
{
Console.WriteLine("🚀 Running dotnet publish...");
var process = Process.Start(new ProcessStartInfo
{
FileName = "dotnet",
Arguments = $"publish \"{csprojPath}\" -c Release -p:PublishProfile={publishProfileName}",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
});
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.WriteLine("[OUT] " + e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.Error.WriteLine("[ERR] " + e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if(process.ExitCode != 0)
{
}
return process.ExitCode == 0;
}
static bool ReBuildProject(string projectPath, string configuration)
{
Console.WriteLine($"🔨 Re-Building: {projectPath}");
var process = Process.Start(new ProcessStartInfo
{
FileName = visualStudioDevenv,
Arguments = $"\"{solutionPath}\" /Project \"{projectPath}\" /ReBuild \"{configuration}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
});
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.WriteLine("[OUT] " + e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.Error.WriteLine("[ERR] " + e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
}
return process.ExitCode == 0;
}
static bool ReBuildSolution(string configuration)
{
Console.WriteLine($"🔨 Re-Building: Whole Solution");
var process = Process.Start(new ProcessStartInfo
{
FileName = visualStudioDevenv,
Arguments = $"\"{solutionPath}\" /ReBuild \"{configuration}\"",
RedirectStandardOutput = true,
RedirectStandardError = true,
UseShellExecute = false,
});
process.OutputDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.WriteLine("[OUT] " + e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (!string.IsNullOrEmpty(e.Data))
Console.Error.WriteLine("[ERR] " + e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
if (process.ExitCode != 0)
{
}
return process.ExitCode == 0;
}