i want to write a TFS post build script to copy Folder and its contents to drop - visual-studio

I want to execute a post-build script from TFS which copies a folder in my TFS to the Build drop location.
I have very little knowledge of how to do this.
Kindly provide with the code.
I am using VS2015, tfs 2015.
i also have VS 2013, TFS 2013

TFS 2015 Build has an out of the box template 'Visual Studio' that already does this using the PublishBuildArtifacts task.
Look at leveraging this task in your build def in order to accomplish what you are looking for.
https://msdn.microsoft.com/en-us/Library/vs/alm/Build/steps/utility/publish-build-artifacts
https://github.com/Microsoft/vso-agent-tasks/tree/master/Tasks/PublishBuildArtifacts

In XAML build, you can check in your script, and specify a post-build script path in your XAML build definition.
This script gathers some of the typical binary types from the typical locations and copies them to the folder from which TFBuild copies and drops to your staging location. Check more information about Run a script in your XAML build process at website: https://msdn.microsoft.com/library/dn376353%28v=vs.120%29.aspx
In vNext build, you can simply add a PublishBuildArtifacts task as Mr. Kraus mentions. About how to use this task, check: http://www.codewrecks.com/blog/index.php/2015/06/30/manage-artifacts-with-tfs-build-vnext/

Related

Visual Studio 2015 - Finding out path to currently used workspace (C# / custom build steps)

I would like to add a custom build step to copy the executable from where it was built (in current active configuration, in current workspace, by currently logged in user) into a shared location.
Are there any predefined environment variables in VS (?) that would contain that information?
Or C# API to Visual Studio that would provide the same?
This might help:
https://msdn.microsoft.com/en-us/library/42x5kfw4.aspx
These did not help:
Visual Studio 2015 Extension - How to get workspace of current Solution
How to get the TFS workspace directory
VNext build
Seems you want to copy files from working folder on the agent computer.(The local path on the agent where your source code files are downloaded. For example: c:\agent\_work\1\s)
You can try to use Windows Machine File Copy task.
Source: You can use pre-defined system variables such as $(Build.Repository.LocalPath) (the working folder on the agent computer), which makes it easy to specify the location of the build
artifacts on the computer that hosts the automation agent.
Destination Folder: The folder on the Windows machine(s) to which the files will be copied. Example: C:\FabrikamFibre\Web
If your shared loaction is on the same machine. You can also try to use Copy Files.
XAML build
In XAML build, you can check in your script, and specify a post-build script path in your XAML build definition. This script gathers some of the typical binary types from the typical locations and copies them to the folder from which TFBuild copies and drops to your staging location. Check more information about Run a script in your XAML build process at website: https://msdn.microsoft.com/library/dn376353%28v=vs.120%29.aspx

TFS 2015 continues build only output changed assemblies

I have a solution in TFS 2015 that using continues integration build method, what i want is every check-in triggers a build that selectively only output changed dlls, exe, into the artifact folder. Is there a such configuration to do so?
Unfortunately, there is no this built-in configuration with vNext build in TFS2015.
However, a obvious solution is adding a Powershell Script on what to publish as artifacts. Using a PowerShell script to organize everything and pre-compressing in single files is the best approach for your situation.
Detail step and screenshot please take a look at this blog: Manage Artifacts with TFS Build vNext

How do I create a project in Visual Studio not meant to compile?

I've got a Visual Studio 2010 solution that I would like to add a project to that only contains some command-line scripts. This project isn't meant to actually compile/build anything, but I want to be able to edit my scripts with the rest of the solution, and have TFS integration etc.
Unfortunately, in searching I get a lot of results for errors where builds don't happen, or other conditions where specific build targets are implemented. I simply want a non-build project in VS as a visual repository for the editor. I don't want to one-by-one include individual files in a solution folder.
In the build configuration manager (On the Menu, "Build", "Configuration Manager"), there is a "build" checkbox for each project. Uncheck it for your script project.
Could you make a content project, add your scripts to it, then change their properties to "Do not compile"?

TFS 2010 Build Automation and post-build event

In the project I've inherited, the original developer used a number of post-build events in his Visual Studio projects to copy around DLL's and stuff when building inside VS.
This is causing some grief now that I'm trying to move these things to the TFS 2010 Build system.
I was hoping to be able to create a new "Continuous" project configuration, and exclude those post-build events from Visual Studio in that configuration - but it seems those calls aren't configurable based on your project configuration....
Any ideas? Is there something I could check for to know I'm running under TFS Build and then just skip those CMD files? Any ideas would be most welcome!
My approach is to guard the pre- or post-build code with this
IF "$(BuildingInsideVisualStudio)"=="true" (
…your code here…
)
That variable is automatically defined by Visual Studio and you do not need to change the build definition.
I use a similar approach to do this. I add the following to each project's post-build steps:
if '$(TeamBuild)'=='True' exit 0
Then when configuring the Build Definition I simply add:
/p:TeamBuild=True
...to the MSBuild Arguments.
This gives me the flexibility to keep all the configuration in the projects and the build definition.
What if you set an environment variable on your team build server, and then you could write a check into your post build steps to check for that environment variable. If the environment variable is set, you'd know to skip the command files that do the post build steps because you'd know you are running under TFS build.
You could combine all your post build steps into one script possibly, and then just check the environment variable at the beginning of that script.
Or you may be able to do it the opposite way and build the check into your TFS build script. You can refer here for how to check an environment variable in a TFS build.
So in your TFS build script you'd have something like:
<RunScripts Condition=" '$(RunScriptsServerVar)' != '' ">
the environment var is NOT set, so run your scripts since we aren't in
a TFS build
</RunScripts>

Integrating MSBuild into Visual Studio

I'm a solo developer running Visual Studio 2008 and looking into MSBuild to improve my build process.
Almost all of the tutorials I've found so far have plenty of information about writing a build file. However I'm having a lot of trouble finding out how to integrate MSBuild into Visual Studio. Maybe MSBuild is only used with something like CruiseControl but that's overkill for me as a single developer.
Where should the build file live in a Visual Studio project and how can I run it from within the IDE?
Visual Studio executes MSBuild automatically for projects it supports.
If you right click on a project and unload it, you can then edit it in Visual Studio. Reload (right click on project again), force a (re)build to test your changes. An alternative is to edit the project file in an external editor and Visual Studio will detect saves and offer to reload the project for you.
Sounds like you're on the right track, and if you are considering writing Targets or custom MSBuild Tasks, take the time to separate them from your current project so that you can re-use them. Don't re-invent the wheel though, the two main complementary MSBuild projects are MSBuild Community Tasks and MSBuild Extension Pack.
Update: Judging from your comment on Mitch's answer, you might also want to consider adding a new Configuration element or custom properties to a project. A new MSBuild Configuration (something other than the default Debug/Release) could run unit tests, build documentation, or whatever you want automated. A custom MSBuild property would allow you to use normal Debug/Release Configuration and extend it to automate more of your build process, just depends on what you want. Either approach could also be driven from the command line.
As others have noted, MSBuild is already available when you install Visual Studio.
If you want to integrate into VS2008: Running MSBuild from Visual Studio
MSBuild is the build engine used by Visual Studio to process the files included in a project.The Visual Studio project files themselves (**.csproj* for C#, and .vbproj for VB, for example) are in fact MSBuild scripts that are run every time you build a project.
Your .csproj file is a MSBuild file. So you are actually using it already.
You may of course wish to create a separate build file to have more control, especially within a continuous integration or nightly build say.
If you simply wish to edit your project build file then you can use the IDE to edit some settings such as pre and post build actions or edit the Xml itself by unloading project and right click and editing.
You can use your current .vcproj files to build your project with MSBuild. However, as MSBuild is not directly supported (at least for vc++) vcbuild is used instead (internally).
In VS2010 all project files are MSBuild based...
This is an older article about some simple extension points from the msbuild team
How To: Insert Custom Process at Specific Points During Build
Also, don't forget you can use the MSBuild SideKick for developing and debugging your (local) msbuilds, available for free at http://www.attrice.info/msbuild/
I'd suggest you call msbuild as a post build step. Then you can put your build script somewhere in your solution and call it.
<windowsdir>\Microsoft.NET\Framework\v3.5\MSBuild.exe c:\temp\MyProject\mybuildfile.proj
The easiest way is probably to invoke your custom build script using a post-build step. Right click project, choose "Build Events" and call msbuild with your custom msbuild file from there.
I use the msbuild template to intergrate with visual studio
http://msbuildtemplate.codeplex.com/

Resources