问题
We use TFS 2010.
There are a couple of projects with deployment steps which must know whether they are running on a dev machine or on the TFS build agent.
Right now they check whether the build is from within Visual Studio assuming that only devs compile from VS. Alas, it means I cannot compile from the command line!
So, my question is how an msbuild script can determine if it is being run by the TFS build agent?
回答1:
You have a few options:
'$(BuildingInsideVisualStudio)' != ''
'$(TeamBuildConstants)' != ''
(supported in team Build 2008)'$(IsDesktopBuild)' == 'false'
You can check either one to detect the context the task has been executed in. If both don't evaluate then MsBuild has been called from the commandline or some other process.
回答2:
I have TFS2012 and use this:
<IsTfsServerBuild Condition=" '$(IsTfsServerBuild)' == '' ">false</IsTfsServerBuild>
<IsTfsServerBuild Condition=" '$(BuildingInsideVisualStudio)' != 'true' AND '$(BuildUri)' != '' ">true</IsTfsServerBuild>
回答3:
When calling MSBuild from the command line, you can pass/overwrite properties like this:
# Simulate Visual Studio build
. msbuild.exe Project.csproj /p:BuildingInsideVisualStudio=true [...]
# Custom property
. msbuild.exe Project.csproj /p:MyCustomProperty=true [...]
Is use these to check them in my post/afterbuild events.
来源:https://stackoverflow.com/questions/20401385/how-can-one-determine-if-a-csproj-is-being-run-on-a-tfs-build-agent