Is it possible to detect when building in the VS IDE?
I've added an additional after build step so that I can integrate mspec with teamcity. However I do not want to run this when I'm building in the IDE as it lengthens the time to build. Is there someway I can detect whether I'm building from the IDE and not execute this specific target? This is what I have so far.
<Target Name="RunSpecs">
<PropertyGroup>
<AdditionalSettings>--teamcity</AdditionalSettings>
<MSpecCommand>..\Lib\mspec\mspec.exe $(AdditionalSettings) "$(TargetDir)$(AssemblyName).dll"</MSpecCommand>
</PropertyGroup>
<Message Importance="high" Text="Running Specs with this command: $(MSpecCommand)" />
<Exec Command="$(MSpecCommand)" IgnoreExitCode="true" />
</Target&开发者_JAVA技巧gt;
<Target Name="AfterBuild" DependsOnTargets="RunSpecs" />
The easy solution is to add another build configuration but I'd prefer not to do that.
Also the TeamCity output being dumped to the output window is sort of annoying. :)
Yes you can check the property BuildingInsideVisualStudio
.
So in your case you could do something like the following:
<Target Name="RunSpecs" Condition=" '$(BuildingInsideVisualStudio)'!='true' ">
<PropertyGroup>
<AdditionalSettings>--teamcity</AdditionalSettings>
<MSpecCommand>..\Lib\mspec\mspec.exe $(AdditionalSettings) "$(TargetDir)$(AssemblyName).dll"</MSpecCommand>
</PropertyGroup>
<Message Importance="high" Text="Running Specs with this command: $(MSpecCommand)" />
<Exec Command="$(MSpecCommand)" IgnoreExitCode="true" />
</Target>
Notice the condition on the target. FYI, generally I generally advise against putting condition on targets but this is a good usage for them.
精彩评论