Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 674
David Avatar asked Feb 22 '10 19:02

David


People also ask

What happens when we build a solution in Visual Studio?

Build Solution - compiles code files (dll and exe) that have changed. Rebuild Solution - Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.

What is the difference between build and rebuild?

Taken from this link: Build means compile and link only the source files that have changed since the last build, while Rebuild means compile and link all source files regardless of whether they changed or not. Build is the normal thing to do and is faster.

How do I clean my Visual Studio project?

To build, rebuild, or clean an entire solution Choose Build All to compile the files and components within the project that have changed since the most recent build. Choose Rebuild All to "clean" the solution and then builds all project files and components. Choose Clean All to delete any intermediate and output files.


1 Answers

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.

like image 97
Sayed Ibrahim Hashimi Avatar answered Nov 15 '22 19:11

Sayed Ibrahim Hashimi