简体   繁体   中英

How to exclude file/folder from visual studio project?

I can't find any option or command to make a file or folder to be excluded from my visual studio project. (csproj, jsproj... )

There is the option to include files and folders in the Solution Explorer -> Show All Files -> left mouse click on target -> Include In Project.

but there is no option for exclude ...

I'm using VS 2015.

I noticed that the option for exclude was available in VS 2008 and 2010. by this doc:

https://msdn.microsoft.com/en-us/library/0ebzhwsk(v=vs.100).aspx

any solution?

thanks

EDIT:

The problem is only in jsproj type of project (Apache Cordova project for example). excuding in csproj is working great.

在此处输入图片说明

I have the German version and it shows "exclude from project", when right-clicking on the Item/File/Directory

I also can use "Project > Exclude selected File from Project" .
It could look like your Installation is broken. Maybe update/reinstall VS to solve the problem...


btw.: This is VS2015...


EDIT №1: This thread does also complain about the context menu option not showing up, but I could not find the answer.


EDIT №2: You could edit your .csproj -file using a text editor to manually include or exclude different files, but it is always a bit ponderous to close the project, edit the file and reopen the project....

The appropriate tag is named <ItemGroup> and should look like this:

<ItemGroup>
  <Content Include="css\foundation.css" />
  <Content Include="css\foundation.min.css" />
  <Content Include="css\main.css" />
  <Content Include="img\my_image.png" />
 ...
</ItemGroup>

Simply change the first attribute from Include to Exclude . If this does not work, try to uncomment the specific files/directories:

<ItemGroup>
  <!--
  <Content Include="file\to_be.ignored" />
  -->
 ...
</ItemGroup>

Visual Studio 2019:

Example: remove relative folder node_modules

add this to csproj file

<ItemGroup>
  <Compile Remove="ClientApp\node_modules\**" />
  <Content Remove="ClientApp\node_modules\**" />
  <EmbeddedResource Remove="ClientApp\node_modules\**" />
  <None Remove="ClientApp\node_modules\**" />
</ItemGroup>

VS Version: 1.51.1

Using settings.json file in the.vscode directory you could add a "files.exclude" property. This worked immediately for me.

 "files.exclude": {
    "dist/": true,
    "node_modules/": true,
    ".angular/": true
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM