Amazon web services 在.NET中以编程方式生成测试zip包时,找不到测试文件夹

Amazon web services 在.NET中以编程方式生成测试zip包时,找不到测试文件夹,amazon-web-services,zip,zipfile,aws-device-farm,Amazon Web Services,Zip,Zipfile,Aws Device Farm,我正在使用AWS Appium for Python。由于我们的项目需求,测试将使用Python,但我们需要使用.NET以编程方式在AWS中构建、上载和安排测试 根据AWS文档,测试包zip文件的根目录中应包含以下项目:tests文件夹、wheelhouse文件夹和requirements.txt文件 当我在Windows机器上手动构建包时,只需选择文件和文件夹,右键单击并添加到zip存档,AWS就会接受该包,测试也会正确运行 但是,当我在.NET中以编程方式构建包时,即使输出zip文件与手动构

我正在使用AWS Appium for Python。由于我们的项目需求,测试将使用Python,但我们需要使用.NET以编程方式在AWS中构建、上载和安排测试

根据AWS文档,测试包zip文件的根目录中应包含以下项目:tests文件夹、wheelhouse文件夹和requirements.txt文件

当我在Windows机器上手动构建包时,只需选择文件和文件夹,右键单击并添加到zip存档,AWS就会接受该包,测试也会正确运行

但是,当我在.NET中以编程方式构建包时,即使输出zip文件与手动构建的zip文件具有相同的文件夹结构,AWS仍会拒绝该文件,并显示以下错误消息:

在测试包的根目录中找不到测试目录

我尝试了3种不同的方法在.NET中以编程方式构建包。两种方法都会导致相同的错误。简而言之,方法如下:

1/创建一个TestPackage文件夹,其中包含tests文件夹、wheelhouse文件夹和requirements.txt文件。使用以下代码压缩整个TestPackage文件夹:

ZipFile.CreateFromDirectory("TestPackage", zipPath, CompressionLevel.Optimal, includeBaseDirectory: false);
includeBaseDirectory标志设置为false,以便所有文件夹和文件都位于zip文件的根目录中

2/创建一个空的zip文件。然后使用下面的伪代码将所有文件requirements.txt和文件夹中的所有文件添加到zip文件中:

using (var zipStream = File.Create(zipPath))
{
  using (var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Update))
  {
    // entryName is the relative path to the file
    // For eg., a file in the tests folder will have this path:
    // @"\tests\test_sample.py"
    zipArchive.CreateEntryFromFile(sourceFileName, entryName)
  }
}
3/使用以下PowerShell脚本:

# Get the path to the AWSDeviceTests folder
# Assumption: the script file is in this folder
$ProjectDir = Split-Path -Path $MyInvocation.MyCommand.Path

# Get the paths of the test folders and file
$RequirementsFileDir = Join-Path -Path $ProjectDir -ChildPath "requirements.txt"
$TestsFolderDir = Join-Path -Path $ProjectDir -ChildPath "tests"
$WheelhouseFolderDir = Join-Path -Path $ProjectDir -ChildPath "wheelhouse"

# Zip the test folders and file
$ZipDestination = Join-Path -Path $ProjectDir -ChildPath "TestPackage.zip"
Compress-Archive -LiteralPath $RequirementsFileDir, $TestsFolderDir, $WheelhouseFolderDir -CompressionLevel Optimal -DestinationPath $ZipDestination
以上所有方法都失败了。ZipFile和ZipArchive来自.NET中的System.IO.Compression

我想再次强调,所有方法的输出zip文件与我手动构建的zip文件具有完全相同的文件夹结构,即所有必需的文件夹和文件都位于zip文件的根目录中。虽然手动生成的文件可以工作,但以编程方式生成的文件不能工作

我做错什么了吗?在.NET或Windows中构建AWS设备测试包是否存在已知问题?或者不可能以编程方式构建测试包并将其上载到AWS设备场?在AWS设备场中,zip文件的解析/验证准确程度如何


任何帮助或建议都将不胜感激。提前谢谢。

过了一会儿,我注意到一些有趣的事情。每次手动构建zip文件时,我都使用7zip:选择文件和文件夹=>右键单击=>7zip=>添加到archiveName.zip

相反,在我用来自动化构建过程的所有方法中,我使用的似乎是Windows内置的zip功能,不管是什么;也许是WinZip

所以我决定再试一次,但在我的代码中使用7zip,它成功了。代码如下:

// Execute command line to zip the build file and folder using 7-zip
// Assumption: 7zip.exe is installed in this directory
Directory.SetCurrentDirectory(@"C:\Program Files\7-Zip");
string sevenZipExecutable = @"7z.exe";
string requirementsFile = projectDirectory + @"\requirements.txt";
string testsFolder = projectDirectory + @"\tests";
string wheelhouseFolder = projectDirectory + @"\wheelhouse";
string arguments = $"/C {sevenZipExecutable} a -tzip \"{zipPath}\" \"{requirementsFile}\" \"{testsFolder}\" \"{wheelhouseFolder}\"";
var startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
startInfo.Arguments = arguments;
startInfo.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(startInfo);

由此看来,我想问题一定是7zip和Windows内置zip如何构建zip文件之间的一些模糊差异造成的。我想我的回答并没有真正解释这是如何发生的或为什么发生的,但至少现在有了一个有效的解决方案,可以帮助其他可能遇到这个问题的人。

我曾经在Mac电脑中遇到过类似的问题。在这种情况下,我发现如果我没有删除之前的压缩文件,压缩文件将不会更新。所以我必须先把它删除,然后再把所有的东西都压缩起来。不确定这是否正确&;39;这是什么&;39;这里发生了什么,但我希望这能有所帮助。听起来.NET SDK有一个非常细微的问题。@jmp谢谢你的建议。在我的代码中,我确实检查了zip文件是否已经存在,如果已经存在,我会在从头开始创建新的zip文件之前将其删除。