【发布时间】:2019-09-18 13:45:58
【问题描述】:
我正在研究 Azure DevOps Build Pipeline,其中一项任务是将我的 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 构建管道。
我将 Type 指定为 Inline。
在我下面给出的脚本中
$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)
【问题讨论】:
-
这是一个 XY 问题。为什么不重定向您的构建输出?如果您从 Visual Studio 构建某些东西,只需传递 MSBuild 参数
/p:OutDir=$(Build.ArtifactStagingDirectory)。 -
我已经在 TFS 中有生产代码。我们正在尝试将代码从 TFS 移动到 Azure DevOps,而不做任何更改。我只想要从 bin 文件夹到其他文件夹的 dll 和 pdb。我可以使用复制任务来做到这一点,但我有很多复制任务,因为我有很多 dll 需要移动。我想要一个运行内联脚本的 power shell 任务。我希望 shell 脚本从变量中读取值并将文件从 A 复制到 B
-
您刚才所说的与我的评论无关。我正在谈论对您的构建过程进行更改,这显然已经无法正常工作,以将您的构建输出重定向到您想要的位置。它会解决您的问题,而无需任何额外的复制。
标签: powershell azure-devops azure-pipelines azure-pipelines-build-task