77

I'm in the process of refactoring a project. I've got an entire subfolder which is known to be broken. Is there any declarative way to exclude that folder from the compile temporarily while I test the refactoring thus far?

I realize I could delete the folder, but I'd like to do this through configuration if possible.

Zdeněk Gromnica
  • 854
  • 2
  • 14
  • 31
Larsenal
  • 49,878
  • 43
  • 152
  • 220

13 Answers13

99

You could set the Build Action (in the Properties Window) to None for the files you want excluded. You could also right-click on the folder and choose Exclude from Project.

Rob Windsor
  • 6,744
  • 1
  • 21
  • 26
  • 1
    I asked a related question for Web Site codebehind here: http://stackoverflow.com/questions/219417/how-to-exclude-web-site-code-behind-files-from-visual-studio-compile – Larsenal Oct 20 '08 at 18:38
  • Is there any way to exclude every file with a specific file type? – anuith Jun 19 '13 at 08:44
  • Is there a shortcut available for this? In visual studio 2010. – Sohaib Oct 07 '13 at 14:19
  • 1
    There is not "Build Action" option in C++ projects. Is this only for C#? – Pedro77 Apr 21 '17 at 14:32
  • 2
    @Pedro77 For C++, right click on files in Solution Explorer (emphasize - files, not project) -> Property (the one near the bottom) -> "Exclude from build" = yes – javaLover May 15 '17 at 05:46
  • I wrote an extension doing exactly that and solving the problems raised here in the comments: https://marketplace.visualstudio.com/items?itemName=AdamWulkiewicz.ExcludeFromBuild – Adam Wulkiewicz Jun 13 '20 at 14:52
  • Note: Excluding the file from the project will remove it from the Solution Explorer. – Mats Gausdal Apr 13 '21 at 11:53
14

In VS 2010, right-click on the CPP module, choose Properties.

Then click on Configuration Properties -> General, Exclude from Build = Yes.

"Exclude from Project" is no good, it disappears from the other Configurations as well.

Pierre
  • 4,114
  • 2
  • 34
  • 39
9

Use ExcludeFoldersFromDeployment inside <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> tag, example:

<ExcludeFoldersFromDeployment>FolderToExclude</ExcludeFoldersFromDeployment>

For files, use:

<ExcludeFilesFromDeployment>File1.aspx;File2.aspx</ExcludeFilesFromDeployment>
L.Barral
  • 313
  • 3
  • 10
9

Right click all the files, and select Properties. Now set Action to None. Revert to Compile when you fixed the code :)

leppie
  • 115,091
  • 17
  • 196
  • 297
  • The answers provided are good. However, the Build Action doesn't appear for code-behind files in a web site. I should have been more specific about my case. I'll make a new question for that scenario. – Larsenal Oct 20 '08 at 18:34
7

On Visual studio 2010 or later, you can achieve the functionality in two ways.

  1. Right click the file, select 'Exclude From Project'

  2. Right click the file, select 'Properties' --> select 'Configuration Properties' --> select 'General' --> choose 'Yes' from drop down menu for option 'Excluded From Build'

pb2q
  • 58,613
  • 19
  • 146
  • 147
notytony
  • 1,032
  • 2
  • 11
  • 13
6
  1. Select the files that you don't want to have compiled on the Solution Explorer.

  2. Right click and choose Options...

  3. Set the "Build Action" on the files to "None".

That should do the trick for you!

pb2q
  • 58,613
  • 19
  • 146
  • 147
Mat Nadrofsky
  • 8,289
  • 8
  • 49
  • 73
2

You should just be able to right click on the folder name in your solution explorer, and click "exclude from project".

Kibbee
  • 65,369
  • 27
  • 142
  • 182
2

In a website project type, you can set the files/folders attributes to "hidden" in Explorer to achieve the same effect.

Peter Willis
  • 926
  • 5
  • 9
1

If you have a lot of image files in a folder, so many that compilation is a painfully long task; you can rename the folder in IIS, giving the folder a .exclude extension.

e.g. C:\intetpub\wwwroot\yoursite\images change to C:\intetpub\wwwroot\yoursite\images.exclude

Then when you compile your app, the .exclude folder is excluded from compilation.

jonsca
  • 10,218
  • 26
  • 54
  • 62
Alan
  • 337
  • 2
  • 3
1

This is a method I have found for IIS Website Projects.

Set the "Hidden" attribute for the file/folder which you want to exclude from project, and then refresh the project in Solution Explorer. For example:

1. Open Windows Explorer.
2. Go to the physical folder of your website.
3. Right click the file/folder which you want to exclude, and then select "Properties".
4. Check the "Hidden" attribute.
5. Click the "Refresh" button in the Visual Studio Solution Explorer

Benson Yu

Microsoft Online Community Support

Quoted from: https://forums.asp.net/post/1997766.aspx

OrangeKing89
  • 694
  • 6
  • 16
0

I'm quite sure that there should be a "Exclude from build" property on the folder, but I don't have my Visual Studio with me at the moment. At the very least there is such a property on files.

JesperE
  • 63,317
  • 21
  • 138
  • 197
0

In Rider, right click file in Navigation Bar, click Properties, change Build action to None.

cja
  • 9,512
  • 21
  • 75
  • 129
-3

In Visual Studio 2010 you need to right click the project in the Solution Explorer and choose Unload Project

Alex
  • 7,432
  • 20
  • 75
  • 118