1
votes

I am working on Azure DevOps Build Pipeline and one of the task is to copy my dll and pdb files into a staging folder for example

Code
  MyProject
     Bin
       Debug
          MyProject.dll
          MyProject.pdb

Staging
   Client
     Libraries

I want to use PowerShell script task and I am using inline script. When I give below it is not working

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

-Destination $(ClientLibrariesFolder)

Below are my variables

Variable Name                  Variable Value
StagingFolder              $(Build.Repository.LocalPath)\Staging
DebugBuildConfiguration           Debug
ClientLibrariesFolder        $(StagingFolder)\Client\Libraries

I donot get any error. But nothing happens.

SOLUTION:

I solved my issue following below

I added new variable like below

CodeLocalPath : $(Build.Repository.LocalPath)

I added Powershell task to my Azure DevOps build pipeline.

I gave Type as Inline.

In Script I gave below

$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)
1
This is an XY problem. Why not redirect your build outputs? If you're building something from Visual Studio, just pass the MSBuild argument /p:OutDir=$(Build.ArtifactStagingDirectory).Daniel Mann
I already have production code in TFS. We are trying to move code from TFS to Azure DevOps without changing anything. I just want dlls and pdbs from bin folder to some other folder. I can do that using Copy Tasks but I have many copy tasks since I have many dlls to move. I want to have one power shell task that runs inline script. I want shell script to read values from Variables and copy the files from A to BZiggler
Nothing you just said pertained to my comment. I'm talking about making a change to your build process, which is already clearly not working, to redirect your build output to the location you want. It will solve your problem without requiring any additional copying.Daniel Mann

1 Answers

1
votes

I donot get any error. But nothing happens.

What do you mean "But nothing happens"? Do you mean that no files have been copied into your Repos?

If yes, that is the correct behavior of Devops. Because this is not recommended to upload any file back to your repo.

If you set the system.debug=true in the variables tab, you will find the log like:

##[debug]Copy-Item C:\VS2017Agent\_work\8\s\TestSample\TestSample\Bin\Debug\*.* -Destination C:\VS2017Agent\_work\8\s\TestSample\Staging\Client\Libraries'

It will not copy the file to the repos. That should be the reason why you see nothing happens.

Besides, Looking at Microsoft's documentation the descriptions are as follows:

$(Build.Repository.LocalPath): The local path on the agent where your source code files are downloaded. For example: c:\agent_work\1\s By default, new build definitions update only the changed files. You can modify how files are downloaded on the Repository tab.

So, the value of this variable is pointing to the agent instead of repos.

Note: Copy-Item in powershell should copy the files instead of a folder, try to use *.* to include all file in the folder.