Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding Page from Release Build in ASP.NET Project

I am using an "Inspector.aspx" to do some tests in my Debug build. In a Release build (and more importantly when creating an installer), I manually exclude the page (and it's related C# files) from the project.

Is there a way to automatically exclude files in a selected solution configuration in an ASP.NET project?

C++ projects give control on exclusion/inclusion per file per configuration

like image 977
Agnel Kurian Avatar asked Mar 11 '09 09:03

Agnel Kurian


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.


1 Answers

One option is to edit your msbuild (*.csproj) file to conditionally exclude certain files based on the Solution Configuration (ie. Debug, Release, etc). For instance:

<Compile 
    Exclude="inspector.aspx" 
    Condition="'$(Configuration)' == 'Release'" />

Similarly you could define an ItemGroup containing only the files that you want to be included in the Debug build:

<ItemGroup Condition="'$(Configuration)' == 'Debug'">
    <Compile Include="inspector.aspx" />
    <Compile Include="...other files..." />
</ItemGroup>
like image 104
JulianM Avatar answered Sep 21 '22 09:09

JulianM