Mike Schall
Mike Schall

Reputation: 5899

Exclude folder from website build using MSBuild

We use MSBuild to build our solutions through CruiseControl. We have several assemblies and a website as part of the solution. Building through VS2008 the build is successful. However on the build box we get the following error.

ASPNETCOMPILER (,):

        errorASPCONFIG: The CodeDom provider type "Microsoft.VJSharp.VJSharpCodeProvider, VJSharpCodeProvider, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.

The reason for this is that in the scripts folder of the website we have a couple files with the .java extension. We don't want these files built. And really we don't need anything in the scripts folder built.

Is there a way to exclude a folder or an extension from being built within a website project? Or tell MSBuild to follow the same rules VS2008 is using to decide what to compile?

Upvotes: 2

Views: 5200

Answers (3)

foka
foka

Reputation: 860

You can remove whole folders with Remove attribute of Item element (brief introduction on MSDN).

For example, if you have items defined like this:

<ItemGroup>
    ...
    <Compile Include="Tests\Test1.cs" />
    <Compile Include="Tests\SubTests\SubTest1.cs" />
    ...
</ItemGroup>

and you want to exclude all classes from "Tests" folder, you can define a task at the end of your project:

    ...
    <PropertyGroup>
        <CoreCompileDependsOn>$(CoreCompileDependsOn);ExcludeTestsFolder</CoreCompileDependsOn>
    </PropertyGroup>
    <Target Name="ExcludeTestsFolder">
        <ItemGroup>
            <Compile Remove="Tests\**\*.cs" />
        </ItemGroup>
    </Target>
</Project>

It's also a good idea to define such a task in an external file and import it with Import element (thorough explanation in another thread).

Upvotes: 1

Sayed Ibrahim Hashimi
Sayed Ibrahim Hashimi

Reputation: 44312

You can use Web Deployment Projects for this. In the WDP you can use the ExcludeFromBuild item to exclude those files. For more info see http://msdn.microsoft.com/en-us/library/aa479568.aspx.

Upvotes: 1

Preet Sangha
Preet Sangha

Reputation: 65476

Inside the build file will be an item group with the item/s concerned. Just edit the file to exclude that item.

For example:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <Res Include = "Strings.fr.resources" >
            <Culture>fr</Culture>
        </Res>
        <Res Include = "Dialogs.fr.resources" >
            <Culture>fr</Culture>
        </Res>

        <CodeFiles Include="**\*.cs" Exclude="**\generated\*.cs" />
        <CodeFiles Include="..\..\Resources\Constants.cs" />
    </ItemGroup>
...
</Project>

Edit: Correction to answer comment.

If you have only a sln file, could you create meta msbuild script that moves the files out of the way, calls the task to build your solution, and then put them back?

Upvotes: 0

Related Questions