Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell Azure DevOps管道-Power shell脚本,使用变量复制文件_Powershell_Azure Devops_Azure Pipelines_Azure Pipelines Build Task - Fatal编程技术网

Powershell Azure DevOps管道-Power shell脚本,使用变量复制文件

Powershell Azure DevOps管道-Power shell脚本,使用变量复制文件,powershell,azure-devops,azure-pipelines,azure-pipelines-build-task,Powershell,Azure Devops,Azure Pipelines,Azure Pipelines Build Task,我正在开发Azure DevOps构建管道,其中一项任务就是将我的dll和pdb文件复制到一个临时文件夹中 Code MyProject Bin Debug MyProject.dll MyProject.pdb Staging Client Libraries 我想使用PowerShell脚本任务,我正在使用内联脚本。 当我在下面给出时,它不起作用 Copy-Item $(Build.Repository.

我正在开发Azure DevOps构建管道,其中一项任务就是将我的dll和pdb文件复制到一个临时文件夹中

Code
  MyProject
     Bin
       Debug
          MyProject.dll
          MyProject.pdb

Staging
   Client
     Libraries
我想使用PowerShell脚本任务,我正在使用内联脚本。 当我在下面给出时,它不起作用

Copy-Item $(Build.Repository.LocalPath)\Code\MyProject\Bin\$(DebugBuildConfiguration) 

-Destination $(ClientLibrariesFolder)
下面是我的变量

Variable Name                  Variable Value
StagingFolder              $(Build.Repository.LocalPath)\Staging
DebugBuildConfiguration           Debug
ClientLibrariesFolder        $(StagingFolder)\Client\Libraries
我没有得到任何错误。但什么也没发生

解决方案:

我在下面解决了我的问题

我添加了如下所示的新变量

CodeLocalPath : $(Build.Repository.LocalPath)
我将Powershell任务添加到我的Azure DevOps构建管道中

我给的类型是内联的

下面是我给你的剧本

$destination = "{0}" -f $env:ClientLibrariesFolder

# Copy MyProject.dll to Staging\Client\Libraries
$sourcefolder = "{0}\Code\MyProject\Bin\{1}\MyProject.dll" -f $env:CodeLocalPath, $env:DebugBuildConfiguration
"Source : {0} and Destination : {1} " -f $($sourcefolder), $($destination)
Copy-Item $($sourcefolder) -Destination $($destination)

# Copy MyProject.pdb to Staging\Client\Libraries
$sourcefolder = "{0}\Code\MyProject\Bin\{1}\MyProject.pdb" -f $env:CodeLocalPath, $env:DebugBuildConfiguration
"Source : {0} and Destination : {1} " -f $($sourcefolder), $($destination)
Copy-Item $($sourcefolder) -Destination $($destination)
我没有得到任何错误。但什么也没发生

“但什么都没发生”是什么意思?您的意思是没有文件被复制到您的回购协议中

如果是,这是Devops的正确行为。因为不建议将任何文件上载回您的回购协议

如果在变量选项卡中设置
system.debug=true
,您将发现如下日志:

##[debug]Copy-Item C:\VS2017Agent\_work\8\s\TestSample\TestSample\Bin\Debug\*.* -Destination C:\VS2017Agent\_work\8\s\TestSample\Staging\Client\Libraries'
它不会将文件复制到回购协议。这应该是你看到什么都没发生的原因

此外,请看以下描述:

$(Build.Repository.LocalPath)
代理上的本地路径其中 您的源代码文件已下载。例如:c:\agent\u work\1\s 默认情况下,新生成定义仅更新更改的文件。你 可以在“存储库”选项卡上修改文件的下载方式

因此,此变量的值指向代理而不是回购


注意:
Copy Item
在powershell中应该复制文件而不是文件夹,请尝试使用
*.
将所有文件包括在文件夹中。

这是一个XY问题。为什么不重定向构建输出?如果要从Visual Studio生成某些内容,只需传递MSBuild参数
/p:OutDir=$(Build.ArtifactStagingDirectory)
。我已经在TFS中有了生产代码。我们正在尝试在不改变任何内容的情况下将代码从TFS移动到Azure DevOps。我只想把DLL和PDB从bin文件夹转到其他文件夹。我可以使用复制任务来实现这一点,但我有许多复制任务,因为我有许多DLL要移动。我想要一个运行内联脚本的powershell任务。我希望shell脚本从变量中读取值,并将文件从A复制到B您刚才说的与我的评论相关的任何内容。我说的是对构建过程进行更改,这显然已经不起作用了,以将构建输出重定向到您想要的位置。它将解决您的问题,而不需要任何额外的复制。是的。。不发生任何事情意味着不复制文件。我的bin文件夹中有DLL和PDB。我想要一个shell脚本,它可以像powershell任务中的内联一样运行,将文件从A移动到B。我在变量中有A到B的值。。。