从C#控制台应用程序将文件保存到Azure DevOps文件夹,如/home/vsts/work/1/s/

从C#控制台应用程序将文件保存到Azure DevOps文件夹,如/home/vsts/work/1/s/,azure,azure-devops,Azure,Azure Devops,我试图在C#控制台应用程序中进行一些处理,该文件必须保存: File.WriteAllText("C:\JSONOutput\output.md"), htmlResult); 我希望将其保存到Azure DevOps文件夹中,如“/home/vsts/work/1/s/”,以便在下一步中再次访问它,我将使用如下语句将文件上载到工件: Write-Host "##vso[artifact.upload containerfolder=testresult;arti

我试图在C#控制台应用程序中进行一些处理,该文件必须保存:

File.WriteAllText("C:\JSONOutput\output.md"), htmlResult);
我希望将其保存到Azure DevOps文件夹中,如“/home/vsts/work/1/s/”,以便在下一步中再次访问它,我将使用如下语句将文件上载到工件:

Write-Host "##vso[artifact.upload containerfolder=testresult;artifactname=worksoftHTML;]/home/vsts/work/1/s/output.html"
File.WriteAllText(Path.Combine(filePath, @"output.html"), finalHtml);
到目前为止,我已经试着写了以下内容,但不起作用:

File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"/home/vsts/work/1/s/output.md"), htmlResult);
这也是:

File.WriteAllText("../home/vsts/work/1/s/output.md", htmlResult);
它也不工作。请帮忙。 我在将文件路径作为参数传递给命令行中的程序的管道中也尝试了以下操作:

- task: CmdLine@2 
  env:     
      InputJSON: $(testJSON)  
  inputs:  
    script: 
        echo $(testJSON)               
        'jsonProcessor.exe $(Build.ArtifactStagingDirectory)\dropfile\,%INPUTJSON%'     
    workingDirectory: './jsonProcExe/'
在exe中,我编写的文件如下所示:

Write-Host "##vso[artifact.upload containerfolder=testresult;artifactname=worksoftHTML;]/home/vsts/work/1/s/output.html"
File.WriteAllText(Path.Combine(filePath, @"output.html"), finalHtml);
然后在下一步中,我将读取如下文件:

- task: PowerShell@2
  inputs:
    targetType: 'inline'
    script: |
      # Write your PowerShell commands here.      
      Write-Host "##vso[artifact.upload containerfolder=testresult;artifactname=worksoftHTML;]$(Build.ArtifactStagingDirectory)\dropfile\output.html"
但我还是得到了错误

Path does not exist: C:\agent\_work\1\a\dropfile\output.html

请注意,我使用的是自托管代理。

管道中的以下行不正确:

jsonProcessor.exe $(Build.ArtifactStagingDirectory)\dropfile\,%INPUTJSON%
因为这不是从命令行向控制台应用程序传递参数的方式。此外,我还试图将JSON作为上一行中的参数传递。那是行不通的。以下是我所做的: 我正在Build.stagingarifact文件夹中从powershell脚本保存JSON:

Write-Output $json | Out-File $env:BUILD_ARTIFACTSTAGINGDIRECTORY/results.json
然后在命令行任务中,我以以下方式传递上述文件夹位置:

task: CmdLine@2     
  inputs:  
    script:                                
        'jsonProcessor.exe $(Build.ArtifactStagingDirectory)\results.json $(Build.ArtifactStagingDirectory)'    
    workingDirectory: './jsonProcExe/'
此外,在.exe文件的c#代码中,最好通过将反斜杠替换为正斜杠来修改从命令行传递的文件路径。 然后,我可以使用以下代码行从C#exe编写文件:

//Create the HTML file.
File.WriteAllText(filePath + "/output.html", finalHtml);

伟大的感谢您在这里分享您的解决方案,您可以接受它作为答案,这样它就可以帮助其他遇到相同问题的社区成员。谢谢