MSBuild copy files to a single folder without file hierarchy - tfs

IN TFS 2017 on-premises site, I've put together a TFS build that generates several database builds and SSIS package builds. it produces the desired dacpac and ispac files. However, when created, these files are placed in a hierarchy, based on the particular project structure. It looks something like this:
Database1
\bin
\Release
\database1.dacpac
Database2
\bin
\Release
\database2.dacpac
ssisPackage
\bin
\Development
\ssispackage.ispac
I would like to copy all of these files (*.dacpac and *.ispac) to a single
directory (flattened) when pushing them out to my team. However, the Copy Files task is copying them and preserving the folder structure.
The Contents block of the "Copy Files" task is:
**\bin\$(BuildConfiguration)\**\*.dacpac
**\bin\Development\*.ispac
and the Target Folder is
$(build.artifactstagingdirectory)
Is there a way to move this files to the target folder without the folder hierarchy, resulting in:
OutputFolder
\database1.dacpac
\database2.dacpac
\ssispackage.ispac
Thanks for the advice

Refer to these steps to achieve your requirement:
Create a bat file with code below and add to your project, then check into source control (%1 means first argument, %2 means second argument)
Code:
pushd %1
for /r %%a in (*.pdb) do (
copy "%%a" %2
)
popd
Add Command Line build step to your build definition
Note: This code is used to copy pdb files, you need to modify it per to requirements.

Related

Azure Web App Referencing DLL in Windows Directory

We are looking to get out of a Virtual Machine and convert a C# MVC website into an Azure Web App. The only hurdle, is that our web application references a C++ project that uses a DLL that has to be stored in the OS's Windows directory. Anyone know how to get around this or any other options?
Use a post-build action in your project, and add the commands to copy the offending DLL. The post-build action are written as a batch script.
The output directory can be referenced as $(OutDir). The project directory is available as $(ProjDir). Try to use relative paths where applicable, so that you can copy or move your project folder without breaking the post-build action.
You needed to copy some dlls to target directory (the build directory) so used the following in a Post-Build event in my project settings:
xcopy $(ProjectDir)openal32.dll $(TargetDir) /Y /D
Here are some commonly used switches with xcopy:
/I - treat as a directory if copying multiple files
/Q - Do not display the files being copied.
/S - Copy subdirectories unless empty.
/E - Copy empty subdirectories.
/Y - Do not prompt for overwrite of existing files.
/R - Overwrite read only files.

TFS 2017 build Copy files from

In a build, we have Copy files from the task. The problem we have is the source folder itself is copied to the destination. We'd want the contents of the source folder to be copied to the destination folder, not the folder itself. Is there any way to do that?
I tried a wildcard but that doesn't work. It seems it needs a path itself. An issue of this could be that the source is named 'X' but the destination is named 'Y' (it was setup before this build and IIS is pointing to this folder). Can we have the source folder be renamed in the build maybe?
That would be name_of_sourcefolder\**\* for all files and subfolders of just name_of_sourcefolder\* for all files.
This has to be set in the Contents part of the task.

How to copy nupkg from build process to drop folder

TL/DR: In a release step, how do I find a .nupkg file that was definitely created in a build process and copy it to a drop folder for use in a release task?
Using TFS 2018, I am trying to copy a .nupkg file created in a prior Build task to the drop folder.
...In the Build Process...
From the log, I know that the file was created.
Successfully created package
'C:\agent_work\9\a\StaticHelpers.1.0.0.nupkg'.
What I am trying to figure out is how I can find this file and copy it to the drop folder. Using Build Variables for inspiration, I have tried the following. At first, I thought it was successful because of what the log said.
Source Folder: $(Agent.BuildDirectory)
Contents: *\*.nupkg
Target Folder: drop
Result:
found 1 files Copying C:\agent_work\9\a\StaticHelpers.1.0.0.nupkg to
drop\a\StaticHelpers.1.0.0.nupkg
All that means is that I can create a release process that takes that file and copies it in a copy release step, right?
...In the Release Process...
Not right. There is nothing in the drop folder when I created a copy file release task and tried to select the nuget package that was definitely created in the build. What I need to do is take that *.nupkg file created during the Build process and copy it to a network share.
So I tried to hard-code the folder based on what I copied from the build log.
Source Folder: drop\a
The release failed, showing this in the log:
[error]Unhandled: Not found SourceFolder: C:\agent_work\r4\a\drop
Either I am copying the file to the wrong location or I am reading from the wrong location. What folders do I need to use so that I can see the *.nupkg file in my release task?
In your build process, don't use a Copy Files task, use a Publish Artifacts task. That will publish an artifact "attached" to the build that a release will automatically pick up during deployment.

TFS 2017 Build Copy Files without folder structure?

In my TFS 2017 build definition, I am trying to copy a folder with a specific name (Package) towards my Artifacts directory. I am only interested in the specific folder itself, not in it's parent folders.
Can someone enlighten me on how I should make this work?
Current configuration for the Copy Files task:
Source: $(agent.builddirectory)
Contents: **\Package***
Target Folder: $(build.artifactstagingdirectory)\MyArtifact
This results in the following folderstructure while my only interest is the Package folder:
\MyArtifact\folderX\s\folderY\folderZ\folderA\Package
With TFS2017update1 and above, VSTS, you could simply check Flatten Folders under Advanced option in Copy Files Task. The easiest solution for now.
This will flatten the folder structure and copy all files into the
specified target folder.
Not sure if you are working on 2017 release version, and there is no Flatten Folders option. You need to specify the copy root if you want to copy files only without folder structure. You can use $(Build.StagingDirectory) as a target for this. Afterwards use the Publish task with $(Build.StagingDirectory) as copy root and publish everything from this root to the drop.
Detail step and screenshot please take a look at the answer from Eddie in this question: Copy one file in target directory on deploy from visual studio team services
If the relative path to "package" does not change, you can specify the detailed path in "Source" to achieve the feature you want.
For example, configure the Copy Files Task:
Source Folder to: $(agent.builddirectory)\folderY\folderZ\folderA\Package
Contents to: **
Target Folder to: $(build.artifactstagingdirectory)\MyArtifact\Package
You will get the folder structure you want.
While all answers were correct in some way, it was not what I intended to achieve.
I ended up creating my own PowerShell script to copy the package folder and it's contents to the Staging Directory:
$BasePath = [System.IO.Path]::GetDirectoryName("$(SolutionPath)")
$Search = "PackageTmp"
$Destination = "$(Build.StagingDirectory)"
Get-ChildItem -Path $BasePath -Filter $Search -Directory -Recurse | Copy-Item -Destination {Join-Path $Destination $(ArtifactName)} -Recurse -Force

Jenkins: Copying Artifact (directory) from one Job to another

in Jenkins, I have a job downloadAgents that is responsible of creating a folder and populating it with some files. Then the folder is saved as an artifact with the following folder structure
dev\downloadAgents\target\dependency\ios
Then I need to copy the contents of the ios folder into the workspace of another job (into a specific folder).
I have added the Copy artifacts from another project step. And it does copy the artifacts, but it copies the full path
\dev\downloadIosAgents\target\dependency\ios
How can I tell jenkins to copy only one folder ios and everything that is inside it and, do not copy all folders that are before ios.
Also if there are already files in the destination folder, will it merge the 2 folders?
You can use regex for your copy (under "Artifacts to copy")-
dev\downloadAgents\target\dependency\ios***.*
** - all folders under ios
*.* - all file types
You can also specify the target directory, and you also have a flag for "Flatten directories". This will move all the files without the hierarchy of the folders (flat to your target directory)
Feel free to look at the plugin's home page:
https://wiki.jenkins-ci.org/display/JENKINS/Copy+Artifact+Plugin
In CopyArtifacts plugin specify the pattern: \dev\downloadIosAgents\target\dependency\ios\*.* or \dev\downloadIosAgents\target\dependency\ios\** - I don't remember exactly.
That should do the job.

Resources