views:

37

answers:

1

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>
<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. :)

+2  A: 

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.

Sayed Ibrahim Hashimi
Thank you very much!
Dave