How do I get a TFS build to precompile a web application using a saved publish profile?
Asked Answered
L

2

4

I'm currently running a CI build and deploy using TFS 2013 for the build and Release Management 2013 for the deployment, though I need the web applications (WebForms) that I'm deploying to be precompiled. I'm looking to use a publish profile to drive the precompilation before the output is copied to the drop location, but I haven't found anything that has been able to do this yet.

After finding How do I configure MSBuild to use a saved publishProfile for WebDeploy? , I set up a publish profile in my web application that will precompile the web application if I use msbuild.exe using the Developer Command Prompt for VS2013

msbuild.exe WebSite.csproj /p:DeployOnBuild=true /p:PublishProfile=TfsPrecompile

Publish Profile named TfsPrecompile, with some help from https://mcmap.net/q/336161/-webapplication-publish-to-relative-filesystem-path

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <WebPublishMethod>FileSystem</WebPublishMethod>
        <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
        <LastUsedPlatform>Any CPU</LastUsedPlatform>
        <SiteUrlToLaunchAfterPublish />
        <ExcludeApp_Data>False</ExcludeApp_Data>
        <PublishUrl>$(MSBuildProjectDirectory)\PublishDirectory</PublishUrl>
        <DeleteExistingFiles>True</DeleteExistingFiles>
        <PrecompileBeforePublish>True</PrecompileBeforePublish>
        <EnableUpdateable>False</EnableUpdateable>
        <DebugSymbols>False</DebugSymbols>
        <WDPMergeOption>DonotMerge</WDPMergeOption>
    </PropertyGroup>
</Project>

Running MSBuild locally, I end up with the precompiled site in a new PublishDirectory folder and all seems to have gone well.

To link TFS and Release Management, I'm using the ReleaseTfvcTemplate.12.xaml template.

Build > Projects: $/Insert_Directory_Here/WebSite.csproj

Advanced > MSBuild arguments: /p:DeployOnBuild=true /p:PublishProfile=TfsPrecompile

When I run the build with the MSBuild arguments there are no significant time differences in the nine-or-so minute build when compared to a build without the precompile arguments. When I run MSBuild locally I see references to ASPNETCOMPILER scroll by, though I see no references to ASPNETCOMPILER or aspnet_compiler in any of the TFS diagnostics logs.

Levi answered 22/11, 2014 at 4:21 Comment(3)
If you run the build with build logging verbosity at "detailed" or "diagnostic", do you see any warnings related to the ASP .NET compiler? This sounds really familiar.Kukri
Are you setting the VisualStudioVersion property? See sedodream.com/… for more details.Pontias
@DanielMann @SayedIbrahimHashimi I'm now using /flp:verbosity=diagnostic /p:VisualStudioVersion=12.0 /p:DeployOnBuild=true /p:PublishProfile=TfsPrecompile in Build>Advanced>MSBuild arugments, though I haven't seen any difference in the files on the build server or the drop location. The log files are the same size as they were before, and it seems that all builds now log at the diagnostic level in 2013. In the WebSite.log file I'm seeing DeployOnBuild = true and PublishProfile = TfsPrecompile under 1>Project "C:\Builds\1\DIRECTORY\WebSite.csproj" on node 1 (default targets).Levi
L
4

It turned out that the build box didn't have all the targets it needed in order to perform the publish, so it just ignored it.

Answer From https://social.msdn.microsoft.com/Forums/vstudio/en-US/c2d10c74-ed44-4635-acb9-ab08612701e2/deployonbuild-not-working?forum=tfsbuild

Finally! I have the solution. Whether deploying from Team Build or you are using MSBuild directly you will need to copy the MSBuild targets onto your build machine in order for publishing to succeed.

We do not install Visual Studio onto our build machine (waste of a license) - however we do install the Visual Studio Shell. It seems the shell installs some of the MSBuild targets - but not all - and certainly not Publishing.

Therefore on a machine with VS installed go to C:\Program Files (x86)\MSBuild\Microsoft

Copy this entire folder to your build machine and replace the same folder there. Maybe back up the original first. You could also probably figure out exactly which targets you actually need...

This fixed it for me!

Levi answered 23/11, 2014 at 18:26 Comment(1)
Might want to double-check as I don't think deploying VS on a build server requires a license--if you're only using it to facilitate builds.Nealson
T
-1

I believe that there is a bug in the Release templates that affects how web sites are pre-compiled. Look to use the Default Template and instead add the RM bits manually.

http://blogs.msdn.com/b/visualstudioalm/archive/2013/12/09/how-to-modify-the-build-process-template-to-use-the-option-trigger-release-from-build.aspx

First switch to the default template and verify that it does as you want. Then follow the trail above.

Truant answered 22/11, 2014 at 7:51 Comment(2)
The release templates build fine. There is/was a bug in the release templates where it wasn't swapping out tokenized configuration files in the _PublishedWebsites folder, but that's it. It was purely an issue with the release side. The release default template is basically identical to the default template, except it adds two little sections of logic that are purely related to release concerns. Build is not touched at all.Kukri
So your sating it is broken? If its not swapping the tokenized configs in the Release templates then it is not working like the default!Truant

© 2022 - 2024 — McMap. All rights reserved.