TFS programatically find and use files from last build - tfs

I am new to TFS. I have two builds on TFS, one is the main solution which spills out .exe files, the other a Wix installer solution that grabs files from the main solution. Right now I use a temp file folder and post/pre build events to receive/feed these .exe files.
Can I streamline this process on TFS? I'd like the installer to
Main solution generates a meaningful file path for each build, ideally related to build number.
Installer solution can find file path of the last successful build of main solution programmatically.
Make this file path available as a build variable or something so it knows where to grab files when building.

Related

VSTS Build not generating latest bin binaries

I am using TFS 2018 CI pipeline for MVC project, also I added the project's bin files into the TFS, there is no problem with the pipeline, its getting succeeded and artifact is generated successfully but the main problem is that if I made any changes in code related to project's DLL,
the CI pipeline's build solution not generating its own latest bin file
Until or unless I manually check Out the project.dll file and than check In the file than pipeline will pick the changes, what I am missing, same result by using 'MSBUILD' tasks, I also TICK clean the 'all directories' but same result
After spending whole day I came to the solution that, bin folder should not be added/included into the Source Control (TFS/Azure),
bin folder or project's binaries should not be added in to TFS
bin folder should be excluded in the project, after doing this operation, when I run the same build pipeline and inspect the artifact found that TFS builds added the bin folder and files accordingly, thats shocked me.
One thing should be remember in this case that what about external dlls reference, create a CommonDLLs folder at the same level of the src folder and put all external DLLs there. They are referenced through a relative path

Can we create TFS build definition of website without .proj file

I am using TFS 2015 for creating builds of application. I am able to create build template for web application as web application have both .sln and .proj.
But for Websites, I only have .sln file and no .proj.
How can I create Build definition in TFS 2015 for website having only .sln file?
As #Cece said, the answer is yes, you can run the MSBuild on the server without a .csproj.
I am assuming that your project is not running on the final version of the .Net Framework. In your case I suggest you to make this change
https://stackoverflow.com/a/42493822/819153
Then you should copy all the files from the PrecompiledWeb folder, and there you should find your .sln
Sometimes there are vb/cs projects that I have seen that they do not come with a project file, csproj or vbproject. They run with the .NET Framework 2.0. For those, you can create a build definition just to compile the .sln, but when you deploy the application, you need to copy the entire PrecompiledWeb folder to the IIS folder on your server. Try to add the task that has the option copy and publish and put all the changes to your server.
Check the privilege of the folder where you want to put the files, and be sure that the agent that is running the builds on the TFS has access READ/WRITE access to the server folder.
In your case, please check the .sln file, inside of it you should have a TargetPath, by default is PrecompiledWeb, but sometimes when you run the msbuild on the tfs you end with an error saying that the PrecompiledWeb can't be on the same tree of your solution, what you need to do then is putting a level up of your solution folder
Debug.AspNetCompiler.TargetPath = "..\..\PrecompiledWeb\YourProject"
Then on your CopyTask you need to change the CopyRoot directory, if you made any transformation before your build step to the webconfig, those transformations will be reflected on the PrecomiledWeb\YourProject. All the files in that folder should be deployed to the server folder path.
Lets say that you have this structure in your Branch
Branch/MyProject, then after you compile the source code on the TFS, your precompiled folder will be stored at the same level of your project on the agents folder. Please see the picture below to get the idea how to copy the files from the PrecompiledWeb.
The answer is Yes. You can create a build definition for a WebSite project by specifying the .sln file.

Choose what goes to drop folder of TFS build

I have a drop folder created by TFS build which contains all the produced artifacts:
.dll \ .config \ .pdb files from all projects
_PublishedWebsites folder
*.msi files produces by Wix projects
All I really care about is *.msi files as everything I deploy is in them.
How can I specify for the TFS build not to bother with all the other files in the Drop folder?
I know I can customize the build to delete files after the solution build, but maybe there is a clever way of disabling them at all?
Personally I use named platforms such as Application and Setup in my SLNs so that when TFS archives the drop folder one class of files goes into one directory structure and another class of files goes into another. This way it's easy to find the MSI and it's also easy to see what the application code looked like before then. (Perhaps the contents of a web.config or an HTML that was added to the application sln but not the installer sln.
IF you want to suppress the application sln from archiving you have to look at that. It's not an MSI / WiX thing.
If you are using TFS 2013 (or VSO) you can easily have a PowerShell executed post build to do whatever clean up and rearranging you need.
Note: The build used the files in the root to do testing, code analysis, test impact analysis, and other automatic actions. Make sure that you only remove files after all of the checks. A better idea is to leave the files be and just push theb*.msi files to a "/_PublishedApplications/* folder.
There is a PublishedApplication Nuget package that can make this easyer. Take a look...
If you are using TFS 2010/2012 you can use the "TFS Community Build Tools" to call PowerShell and do other things.

Adding files via the build server to TFS in a deployment area which is in another location on TFS

I have an application which compiles and runs all okay on our TFS build server.
Now I need to place the files in a deployment area in TFS, as part of the build process on our build server, which is not a workspace that is being used by the build.
I have tried using MSBuild.ExtensionPack.VisualStudio.TfsSource and the Working Directory but this does not work and I need an alternative
We've done something similar by adding an msbuild proj to our source control and then after building our solution, we build this proj which then calls a copy task which moves some files to another folder. Think you can do something similar by editing the default template too (which we didn't want to do)

How to keep the subfolder in DropLocation constant in TFS build

I have a build definition setup with a drop location. The binaries are moved into this location, but under a new directory (named as build number) every time. Is there a way to have the same location over written everytime. we have some batch files that copy the binaries out to multiple servers that will be accessed by the end users. We need the location to remain constant so that the batch files can work correctly.
If this is not possible, is there a way for the batch files to pick the latest location which contains our exe (sometimes, the folder is created even when the build failed).
Having an unique name of the drop location, is something you cannot (and don't want to) change. To solve your issue, you can either
1) start the batch files with arguments (so the directory is %1) where you specify the name of the directory
2) Add a task in the build to copy all the files to a file share. If you are using TFS 2008, you can follow the steps provided at http://blogs.msdn.com/b/msbuild/archive/2005/11/07/490068.aspx to copy the files.
If you are using TFS 2005/2008, then TFS Deployer. It flat rocks when doing deployments.
TFS 2010 has a new build deployment model that is pretty good.

Resources