问题
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://stackoverflow.com/a/13267694/595473
<?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.
回答1:
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!
回答2:
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.
来源:https://stackoverflow.com/questions/27074014/how-do-i-get-a-tfs-build-to-precompile-a-web-application-using-a-saved-publish-p