我想通过软件将tools\Install.ps1
添加到我的nuget
包中。这已经使用以下代码:
Zipper.AddItem(pathToNuGetFile, pathToToolsFolder);
当我安装nuget包时,只会跳过Install.ps1
脚本而不会调用它。但它存在!它也在packages
文件夹中解压缩。
当我打开 * .nupkg 文件(在NuGet-Sources文件夹中,并在packages文件夹中不是)并将Install.ps1
重命名为{{1 ,将其重命名为Install.ps
并保存" zip" / Install.ps1
文件,调用Install.ps1脚本!为什么呢?!
*.nupkg
答案 0 :(得分:1)
Microsoft的ZipArchive
类似乎存在问题。当我使用7zip
添加我的文件时,一切都按预期工作!
我已在解决方案中实施了7zip
并更改了AddItem
方法:
/// <summary>
/// is adding an item to an existing Archive
/// </summary>
/// <param name="pathZipFile"></param>
/// <param name="pathItem"></param>
public static void AddItem(string pathZipFile, string pathItem)
{
string appPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7zip", "7za.exe");
if (SystemInformation.Is64BitOperatingSystem())
{
appPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "7zip", "x64", "7za.exe");
}
//
// Setup the process with the ProcessStartInfo class.
//
ProcessStartInfo start = new ProcessStartInfo();
start.FileName = appPath;
start.UseShellExecute = false;
start.RedirectStandardOutput = true;
start.Arguments = $"a -r {pathZipFile} {pathItem}";
//
// Start the process.
//
using (Process process = Process.Start(start))
{
//
// Read in all the text from the process with the StreamReader.
//
if(process == null)
throw new Exception("Failed to start the 7zip Process!");
using (StreamReader reader = process.StandardOutput)
{
string result = reader.ReadToEnd();
Console.Write(result);
}
process.WaitForExit();
if (process.ExitCode != 0)
throw new Exception($"Fehlercode von 7zip: {process.ExitCode}");
}
}
希望这有助于其他人。