admin管理员组文章数量:1122832
I would like to create a deb package programmatically inside a c# method.
I did a method to create a zip package using 7z.
You just have to install 7z and setup a ENV variable.
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;
}
}
And I wanted to do the same with dpkg-deb
to create a deb package.
But dpkg-deb
cannot be install on 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;
}
}
How can I do that ? Is there a way to do it or is it a dead end ?
I thought of to do it.
By creating a .csproj that would contains the binary I need.
But I need a very specific debian-binary. Will I be able to control what I have inside of it?
Thanks for any help given.
I would like to create a deb package programmatically inside a c# method.
I did a method to create a zip package using 7z.
You just have to install 7z and setup a ENV variable.
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;
}
}
And I wanted to do the same with dpkg-deb
to create a deb package.
But dpkg-deb
cannot be install on 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;
}
}
How can I do that ? Is there a way to do it or is it a dead end ?
I thought of https://github.com/quamotion/dotnet-packaging to do it.
By creating a .csproj that would contains the binary I need.
But I need a very specific debian-binary. Will I be able to control what I have inside of it?
Thanks for any help given.
Share Improve this question edited Nov 21, 2024 at 17:10 Arnaud VDR asked Nov 21, 2024 at 17:08 Arnaud VDRArnaud VDR 133 bronze badges 2 |1 Answer
Reset to default 1My solution was to use wsl
.
private string GeneratePackageDeb(string tempDirectory, string packageDebName)
{
try
{
_logger.LogInformation("Creating deb package");
string packageSavePath = Path.Combine(tempDirectory, packageDebName + ".deb");
string directoryDebPath = Path.Combine(tempDirectory, packageDebName);
if (File.Exists(packageSavePath))
{
File.Delete(packageSavePath);
}
// Execute wsl command:
using (var proc = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = @"cmd.exe",
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardInput = true,
CreateNoWindow = true,
}
})
{
proc.Start();
// --nocheck because " dpkg-deb: error: control directory has bad permissions 777 (must be >=0755 and <=0775) "
proc.StandardInput.WriteLine("wsl " + "--cd " + tempDirectory + " dpkg-deb -b --nocheck " + packageDebName);
System.Threading.Thread.Sleep(500); // give some time for command to execute
proc.StandardInput.Flush();
proc.StandardInput.Close();
proc.WaitForExit(5000); // wait up to 5 seconds for command to execute
Console.WriteLine(proc.StandardOutput.ReadToEnd());
}
if (Directory.Exists(directoryDebPath))
{
Directory.Delete(directoryDebPath, true);
}
return packageSavePath;
}
catch (Exception ex)
{
_logger.LogError(ex, "Failed to generate Deb");
Directory.Delete(_packageWorkingDirectory, true);
throw;
}
}
本文标签: cHow to create a deb package with Process NETStack Overflow
版权声明:本文标题:c# - How to create a deb package with Process .NET? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736308631a1933732.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
dpkg-deb
is a linux lib to make debian package. I cannot use it on windows inside c# code (from my understanding) – Arnaud VDR Commented Nov 22, 2024 at 13:30