Я хотел бы создать пакет deb программно внутри метода C#.
Я создал метод создания zip-пакета с использованием 7z.
Вам просто нужно установить 7z и настроить переменную ENV.
Код: Выделить всё
private string GeneratePackageZip(string tempDirectory, string directoryPrefix, int presetId)
{
try
{
_logger.LogInformation("Creating zip archive");
string packageSavePath = Path.Combine(_storagePath, PackageDirectory, $"{directoryPrefix}{presetId}", _packageFileName);
if (File.Exists(packageSavePath))
{
File.Delete(packageSavePath);
}
// adds all files and subfolders from folder subdir to archive archive.zip.
// 7z a -t7z Files.7z *.txt -r
var process = new Process
{
StartInfo =
{
FileName = "7z",
Arguments = $"a -t7z \"{packageSavePath}\" \"{tempDirectory}/*\"",
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
if (Directory.Exists(tempDirectory))
{
Directory.Delete(tempDirectory, true);
}
return packageSavePath;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to generate 7zip archive");
Directory.Delete(_packageWorkingDirectory, true);
throw;
}
}
Но dpkg-deb не может быть установить на Windows.
Код: Выделить всё
private string GeneratePackageDeb(string tempDirectory, string directoryPrefix, int id)
{
try
{
_logger.LogInformation("Creating deb package");
string packageSavePath = Path.Combine(_storagePath, PackageDirectory, $"{directoryPrefix}{id}", _packageFileName);
if (File.Exists(packageSavePath))
{
File.Delete(packageSavePath);
}
var process = new Process
{
StartInfo =
{
FileName = "dpkg-deb",
Arguments = $"-b \"{packageSavePath}\" \"{tempDirectory}/*\"",
UseShellExecute = false,
CreateNoWindow = true
}
};
process.Start();
process.WaitForExit();
if (Directory.Exists(tempDirectory))
{
Directory.Delete(tempDirectory, true);
}
return packageSavePath;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to generate Deb");
Directory.Delete(_packageWorkingDirectory, true);
throw;
}
}
Я подумал о https://github.com/quamotion/dotnet-packaging, чтобы сделать это.
Создав файл .csproj, который будет содержать нужный мне двоичный файл.
Но мне нужен очень специфический двоичный файл Debian. Смогу ли я контролировать то, что у меня внутри?
Спасибо за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/792 ... rocess-net