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

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.

Related

TFS Build 2013 - Cannot resolve primary reference

I'm evaluating TFS Build 2013 for use in a corporate environment.
TFs itself has been running fine for ages, and today I setup the Build components. No problem so far.
I grabbed a fairly simple project from source and created a manually triggered build definition, using the standard defaults.
I ran a test build and hit an issue straight away with a primary reference. The error in the logs is:
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets(1697,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "XYZ.dll".
So a bit of back of background on how we store and use references:
We create a root folder for the solution, inside this goes the .sln file and sub directories for the projects as normal. We then add a "References" folder at this level, which holds all of the DLLs required for the project. These are generally DLLs from other in house code libraries, but also certain 3rd party ones (such as the old Enterprise Library DLLs, and anything else we don't get from NuGet).
Each of the projects that require these DLLs reference this folder (and from inspecting the .proj files I can see the link is stored as "..\References\XYZ.dll" etc. This works fine for local builds and nobody has ever had an issue. The reference folder gets checked into TFS and everybody gets a copy. From what I've read through trying to diagnose our issue, this is a fairly common and accepted way to manage references.
So, the build error that I receive is as above. Basically saying the build target can't find the DLL from the References folder. The log goes on to list all of the places it's tried to find it.
Crucially (it would seem) the first line reads:
For SearchPath "{HintPathFromItem}".
Considered "..\References\XYZ.dll", but it didn't exist.
Furthermore it looks in the Framework folder, various default assembly folders, the GAC and so on, none of which (of course) contains it.
So I'm wondering where I've gone wrong. Have I misconfigured one of the build/drop locations? Is there some other convention for referencing required DLLs (bearing in mind our entire company uses the "..\References" folder setup, or is there something else?
I'm fairly new to TFS Build, but I'm by no means new to TFS or Visual Studio
itself. I've spent about an hour or so Googling without finding anyone experiencing the same issue as me, so any help would be greatly appreciated.
Thanks
UPDATE:
The build agent is configured as follows:
Build Agent- working directory:
D:\BuildAgent\$(BuildAgentId)\$(BuildDefinitionPath)
The build definition "Source Settings" have the (I assume) default values of:
Status: Active | Source Control Folder: $/ProjectRoot | Build Agent Folder: $(SourceDir)
Status: Cloaked | Source Control Folder: $/ProjectRoot/Drops | Build Agent Folder:
The references folder is not explicitly configured here, but when I look in the Build Agent's working directory I can see it:
D:\BuildAgent\1\ClientName\SolutionName\src\Dev\Evolution\Source\SolutionName.Solution\References
If I open VS2013 Command Prompt, navigate to the folder that contains the .sln file (and also the References folder) and run "msbuild d:\path\to\Solution.sln" then it builds successfully with no warnings or errors.
Well it turns out this wasn't a fault with TFS at all...
The problematic DLL, although present in the References folder, was not actually checked into TFS.
Right clicking the References folder in VS (added as a "Solution Folder") and selecting to Add Existing Item, then a check in fixed the issue.
So the References folder was being used as you would expect, in the same way that VS uses it. MSBuild worked locally because I had the file in my local folder, but because it wasn't part of the solution it wasn't with the rest of the source.

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.

Dynamically add files to user data folder with visual studio setup project

I have a solution under which i have two projects :
-- MyApp -which needs to be deployed
--Documentation
-- file1
-- file2
-- MySetup project
I want to add the contents of the Documentation folder dynamically to User Personal Data folder in the FileSystem Editor of MySetup project i.e not with AddFile from FileSystemEditior. I want this adding to be something like prebuild event for MySetup project.
That is because Documentation folder changes very frequently ( new files added) and I don't want to manually add the files to MySetup project, every time it changes.
Is this possible ?
Thank you for your help
This is not supported by Visual Studio setup projects. However, some commercial setup authoring tools offer direct support for synchronized folders. You can find a list here:
http://en.wikipedia.org/wiki/List_of_installation_software

How do I skip certain files (or should I?) when deploying with MSBuild/MSDeploy?

I'm using this command to build and deploy my site:
MSBuild myprj.sln
/P:Configuration=Debug
/P:DeployOnBuild=True
/P:MsDeployServiceUrl=http://myserver/MsDeployAgentService
/P:MSDeployPublishMethod=RemoteAgent
/P:DeployTarget=MSDeployPublish
/P:UserName=foo
/P:Password=bar
/P:DeployIisAppPath="Default Web Site\MyApp"
It works great, except I think I want to exclude a certain data file, say, ~/App_Data/data.xml. I don't want data.xml in my project since it's generated by the app or setup by the user (e.g. by renaming and configuring data.xml.orig to data.xml).
So what to do? Can I simply exclude it from MSDeploy or should I be handling this another way?
The files that get published are the build outputs from your project; this includes your DLL and any files with Build Action set to Content. If you set the Build Action to None (click the file in VS, view it's properties), it should get excluded automatically.
If you want to exclude the contents of the App_Data folder entirely, there's an option in the project properties, on the Package/Publish Web tab.
If I got you right, you should add /p:SkipExtraFilesOnServer=True to your command line.
This would leave all extra files on destination, which could be a flaw in some scenarios
If you want to skip only some folders (which could be required, if you do not want to garbage your server a lot, while still keeping some folders intact) - you could use solution from this question:
MSDeploy skip rules when using MSBuild PublishProfile with Visual Studio 2012

Install two web sites in two different virtual directories with a Visual Studio Web Setup project

I'm trying to put two web projects that needs to be installed in different virtual directories in the same Web Setup Project, because they are closely related, but they have to run sepparately.
I can put project 1 in one directory, and project 2 in a subdirectory in the same virtual directory.
I've tried to add a "Web custom folder" in the filesystem editor, and configure one of the outputs to go there, then when I run the installer, the textbox for the virtual directory appears empty, and after put some the installation fails.
Can this be done? How?
Thanks a lot.
Yes you can do it. What you described here just works: One additional Web Custom Folder for each additional virtual directory and add output of the target project to each one. Make sure that the property of each of the folders is different from TARGETDIR and is all capitalized (global variable). They will have to share the same AppPool by default, though.

Resources