How can I copy additional files to drop location with MsBuild 2013 - msbuild-task

I'm part of a large developmentteam with a big project that is built with TFS 2013. We have gotten the build to work with automatic tests and web transformations as well as deployment to correct folders. The last part we need is a way to copy additional files to the drop location with regards to different environment.
We have a folder in the solution that contains several deployment files for different environments. We build for several environment with each build.
The folder looks like the following:
A folder named contains several powershell scriptfiles
(Deploy.ps1, RunDeploy.ps1, StartService.ps1)
The first file should be copied to the root of the drop folder location for each configuration/environment.
The last two files should be copied to a new folder named Deploy under each configuration in the drop folder.
Additional to this we have several settings files in the same sourcefolder. One file for each environment named settings-.txt
These files should be copied to the Deploy folder for the correct configuration under the drop location.
We are using TFS 2013 so preferable using a custom workflow but we can use a target-file if needed.
Any idea how this can be created?
Where should I start?
I have been unable to locate a variable in a custom task in the build process that contains the location of the dropfolder for each configuration.

I managed to create a custom task in the build template after some searching for the variables I finally could create a custom task that created the correct folders and located the files that needed to be brought along in the build.
To find the variables I used the common task GetEnvironmentVariable with the specified variables. To see what each variable contained I added a print line just afterwards and tried the build and then when I had found the needed sources of information the task to create a custom build task was fairly easy.

Related

auto exclude folders / files with a certain name from vs2017 solution

Not sure if this is the correct place to ask this but there have been a lot of visual studio questions in the past here.
I am currently creating a lot of npm packages in a solution and as part of the package, I have to create a package.json file.
Once I save the file, it creates a node_modules folder and downloads all the dependent npm packages to it. Now I have got azure dev ops to ignore these files so they aren't checked in by adding the node modules folder to the list of ignored folder names, but I also want to exclude them from my project so that it doesn't lock my computer every time it tries to write all the file names in to the .proj file.
Is there a way to automatically tell the project or solution to auto exclude this folder - like a solution ignore file I can add the name to?
Or is there an option somewhere that folders that aren't created through vs, aren't automatically added to the project - this is how my earlier versions of vs worked - new folders not created through vs would have to be manually included if you wanted them in the project / solution
Ok this is due to the project type that I used when creating the project - I created it as a .net core project and that seems to add files by default and only exclude them if you tell it to, if I change this back to a .net standard project, it works as I would expect - only includes files you drag into the project or tell it to include

Where is the DropLocation variable in TFS build 2013?

TFS 2013 using the DefaultTemplate11.1.xaml.
Inside the BeforeCompile Target.
I'm trying to copy files in my .proj file to the droplocation but the variable, $(TF_BUILD_DROPLOCATION) does not seem to work.
I've tried evaluation it from inside the .proj but it with $(TF_BUILD_DROPLOCATION) but it evaluated to empty.
I've tried passing it in as a parameter from the msbuild arguments with DropLocation=$(TF_BUILD_DROPLOCATION); but it doesnt evaluate and appears in the script as $(TF_BUILD_DROPLOCATION).
The drop location should be our share with the build number appended.
I don't think it is possible to use the TF_BUILD_DROPLOCATION variable in the .proj file.
For your requirement to copy files to TFS build drop location, here are some options:
Just as Dave mentioned above, you can first use Copy task to copy files to one specific folder, then customize the TFS build process template via adding the CopyDirectory build activity to copy contents in source folder to destination folder. You can set the Destination to be: Microsoft.TeamFoundation.Build.Activities.Extensions.WellKnownEnvironmentVariables.DropLocation
Customize your build process template via adding InvokeProcess activity to call xcopy command to copy files. Please check Ewald's blog. (The blog was written for TFS2010, it applies to TFS2013 as well)
I should have been more specific. We're working with VSO, hence the process can not be edited.
So the answer is no, the drop location is not available.
I've had to construct the droplocation myself using $(MyDropLocationRootParam)\$(BuildDefinition)\$(BuildNumber)

Creating a build process template which does nothing but copy all files to another directory

I would like to create a Build Definition inside TFS 2012 Express which will simply copy all files within my project source tree to another folder on my drive. Just to underline - I do not want the build output to go to another directory - I want the source files themselves to. The reason for this is I have IIS pointed at a specific folder, and I want the build to copy the latest asp and aspx files to the IIS hosted folder.
I am not sure of the intricacies of doing this, I did find : http://toadcode.blogspot.co.uk/2008/06/copy-multiple-files-via-tfs-build.html articles like this but I simply need a more direct list of what I need to do from somebody who understands this area.
Basically - when the build is queued, all I want is to copy my project source files to another directory :). I think this can be done by editing some Build.xml file...but when making a build definition I dont seem to be given the freedom to do what I would like to!
I think what I am looking for to alter my DefaultTemplate.11.1.xaml file to alter the build process which will let me run this / or a batch file after the build process completes?
My TFS build process edit screen looks like this:
Using this post as a guide on how to start editing TFS Build Templates (or the Wrox TFS 2012 book), you need to make the following changes:
Locate the Copy to Drop Folder Activity:
Drag in a "CopyDirectory" activity under the "Drop Files to Drop Location" (from the Toolbox under Team Foundation Build Activities):
Goto the Properties Window for the new Activity and set Source and Destination as follows:
Destination: Path.Combine(BuildDetail.DropLocation, "MyOutputFolder")
Source: Path.Combine(SourcesDirectory, "MyFileFolder")
You may need to repeat this if you don't have all your files in one folder.
I actually put something together for TFS2010 and 2013 (not 2012, unfortunately) a few weeks ago that does exactly that. Basically, anything in the workspace you define for your build just gets shoved over to the drop location.
Here's a link to the blog post where you can download them:
http://www.incyclesoftware.com/2014/06/deploying-uncompiled-resources-release-management/
For the record, I strongly recommend against using a build process template to deploy software. Don't try to overextend the build... its job is taking stuff from source control and compiling/packaging it for deployment. Use a real release management solution to actually handle deploying software.
Add a bat file to your source folder. within the batch file add an xcopy %1*.* TargetLocation.
Add an invoke process activity to your workflow, somewhere near the end. call the bat file and pass it the SourcesDirectory.

TFS 2010 Build Automation for a Web Site: Delete a file in the publish folder after build

We are trying to adapt a build automation strategy for our ASP.NET web site (not a web project) in vs 2010 ultimate & tfs 2010.
Build definition makes the build and publishes the web site into folders like
<drop_folder>\<defn_name>\<defn_name>_<year><month><day>.<build no>\Release_PublishedWebsites
Now we try to delete particular files and folders from that folder. For instance the "images" or "files" folders, that we need to exclude before packaging. I know that if it were a web project, there exists a straightforward solution. We also tried to modify the build process template (xaml) file. There is a "DeleteDirectory" component but we couldn't figure out what to write to the Directory variable.
Thank you.
If you follow the XAML way, you would just have to feed the Directory argument of DeleteDirectory with the physical UNC path to the folder you 're trying to get rid of.Something along the lines of String.Format("{0}\\{1}\\{2}\\Release_PublishedWebsites", BuildDetail.DropLocation, BuildDetail.BuildNumber, Date.Now.Year)
should get you near to your target. Since the drop location of the build might be on a different machine, also ensure that the account conducting the build (by default = NetworkService) has the rights to delete folders on the target.

Store developer-defined build parameters in Visual Studio user files?

We have different dev environments between developers here. When I build, I want my compiled files to be copied to a bin folder located in C:\Web\bin\. Another developer may want those files dropped in C:\Web_2011\bin\.
Using Visual Studio 2010, the way we work this now is to run a BAT file with the directories defined as parameters that need to be changed if pulling from another developer's branch.
Is it possible to store a solution-wide parameter, (in a .user or .suo file maybe,) to define where a developer wants to drop his builds?
You could do it through the project file (.vcxproj for C++ project for example).
The simplest solution would be to add a Custom Build Step that runs some batch file. This batch file could check the current user name and copy the files based on that.
(An even simpler solution would be to run a user specific batch file from his local disk)
If you really want the fully fledged solution that will allow you to save this data to the user file, you can do it by editing the project file and adding a PropertyPageSchema element that extends VS property pages with another parameter (your destination directory). You can define the Persistence attribute of DataSource element as "UserFile" and the data will be saved on your .user file. You will need to add some target that actually uses this data (copies files to the directory specified).
For more information, read about msbuild and PropertyPageSchema.

Resources