Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude whole files based on configuration from build in VS2008

I have three different configurations on my project, all three do not require all files to be build into the application. Actually I'd prefer if I could exclude those files from the build, which would make my application a little more lightweight.

What I'm looking for is #if MYCONFIG or #if DEBUG statement but for files. I've already read that this can be accomplished by manually editing the csproj file, but I can't find that anymore...and are there other ways?

like image 666
Bobby Avatar asked Mar 03 '10 10:03

Bobby


People also ask

How do you exclude a project from a build?

On the menu bar, choose Build > Configuration Manager. In the Project contexts table, locate the project you want to exclude from the build. In the Build column for the project, clear the check box. Choose the Close button, and then rebuild the solution.

How do I ignore a folder in Visual Studio?

You can use Visual Studio to exclude a file from a solution by context-clicking the file in Solution Explorer and selecting Exclude from Project in the context menu.

What is none include?

None - The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file. Content - The file is not compiled, but is included in the Content output group.


1 Answers

There are two different ways: In your csproj files, you will have sections that look like this:

<ItemGroup>
    <Compile Include="Helper.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

What you can do is set up a new project configuration (Build menu, Configuration Manager, select New from the Active solution configuration dropdown), then manually change the ItemGroup node to this:

<ItemGroup Condition=" '$(Configuration)' == 'MyNewConfiguration' ">
    <Compile Include="Helper.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>

The second way, as you referred to in your question, is to use conditional debug symbols. At the top of your file, have the statement

#if MYDEBUGSYMBOL

and at the bottom have

#endif

then you can define the debug symbols; right clickon your project file, select Properties, go to the Build tab, and enter the debug symbol in the Conditional compilation symbols textbox.

I would probably stick with the first method.

like image 81
slugster Avatar answered Sep 30 '22 18:09

slugster