MSBuild: Add additional files to compile without altering the project file

Posted by Craig Norton on Stack Overflow See other posts from Stack Overflow or by Craig Norton
Published on 2010-06-12T20:43:26Z Indexed on 2010/06/12 20:52 UTC
Read the original article Hit count: 843

Filed under:

After looking around I can't find a simple answer to this problem.

I am trying to create an MSBuild file to allow me to easily use SpecFlow and NUnit within Visual Studio 2010 express.

The file below is not complete this is just a proof of concept and it needs to be made more generic.

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
    <BuildDependsOn>
        BuildSolution;          
        SpecFlow;
        BuildProject;           
        NUnit;
    </BuildDependsOn>
</PropertyGroup>

<PropertyGroup>
    <Solution>C:\Users\Craig\Documents\My Dropbox\Cells\Cells.sln</Solution>
    <CSProject>C:\Users\Craig\Documents\My Dropbox\Cells\Configuration\Configuration.csproj</CSProject>
    <DLL>C:\Users\Craig\Documents\My Dropbox\Cells\Configuration\bin\Debug\Configuration.dll</DLL>
</PropertyGroup>

<Target Name="Build" DependsOnTargets="$(BuildDependsOn)">
</Target>

<Target Name="BuildSolution">
    <MSBuild Projects="$(Solution)" Properties="Configuration=Debug" />
</Target>

<Target Name="SpecFlow">
    <Exec Command="SpecFlow generateall $(CSProject)" />
</Target>

<Target Name="BuildProject">
    <MSBuild Projects="$(CSProject)" Properties="Configuration=Debug" />
</Target>

<Target Name="NUnit">
    <Exec Command='NUnit /run "$(DLL)"' />
</Target>

The SpecFlow Task looks in the .csproj file and creates a SpecFlowFeature1.feature.cs. I need to include this file when building the .csproj so that NUnit can use it.

I know I could modify (either directly or on a copy) the .csproj file to include the generated file but I'd prefer to avoid this.

My question is: Is there a way to use the MSBuild Task to build the project file and tell it to include an additional file to include in the build?

Thank you.

© Stack Overflow or respective owner

Related posts about msbuild