Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exclude folder in project.json

in the new asp.net 5 template there's a project.json in which you can exclude certain directories.

"exclude": [
    "wwwroot",
    "node_modules",
    "bower_components",
    "dist",
    ".tmp"
]

As you can see, I added a few folders like 'dist' and '.tmp', but they are still included in the solution explorer. There's not much documentation about this. How to exculde files/folders from your project in vs 2015?

like image 498
Elger Mensonides Avatar asked Jun 02 '15 12:06

Elger Mensonides


People also ask

How to exclude folder in tsconfig json?

Use the exclude option in your tsconfig. json file to exclude a folder from compilation in TypeScript. The exclude option changes what the include setting finds and defaults to node_modules and bower_components .

How do I exclude a folder from github?

You can create a . gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the . gitignore file in to your repository.


2 Answers

The "exclude" property does not hide the folder from visual studio, it will not make the folder "disappear" from the solution explorer.

The "exclude" property removes the folder from the compilation search path. It is an instruction to the compiler (Roslyn) not the IDE. As a more comprehensive answer "project.json" is intentionally IDE agnostic. That is why there is both a projecname.xspoj and a project.json which both contain project configuration information. This is necessary to allow for more robust cross IDE and cross platform development.

You can verify this behavior yourself with a simple excercise.

  1. Add a new class file (buildfail.cs) to your existing project (or create a new project) in the root project folder.
  2. Ensure buildfail.cs has the same namespace as the other source files in the project, contains compilation errors, and is in the root directory.
  3. You should see build errors in VS. If you don't manually build.
  4. Create a new folder (excludeme) off the project root and move buildfail.cs to that folder. You should still have build errors.
  5. Add excludeme to the exclude property in project.json. The build errors should be removed because builfail.cs is no longer in the build search path.

You may be wondering what is VS using to know to hide the node_packages folder from the Solution Explorer display. I am unsure and it may not be user configurable but it isn' the exclude property. Comment out node_packages in project.json and you will get build errors (package restore failure) but the folder will still be hidden from Solution Explorer. Since this is IDE specific behavior one would assume that maybe it is defined in projectname.xproj but I found no such property so at this time it would appear to be black box magic by VS.

like image 63
Gerald Davis Avatar answered Oct 17 '22 16:10

Gerald Davis


As of Asp.Net 5 beta-8 and complementary tooling update to Visual Studio 2015, you are now able to exclude/hide folders from being displayed in solution explorer. More information about this, and other changes are outlined in the announcement post. To hide a file or folder, right-click to bring up a context menu and select Hide from solution explorer. This creates an entry in the .xproj file:

<ItemGroup>
  <DnxInvisibleContent Include="myhiddenfile.txt" />
</ItemGroup>

Note also that there has been a change to where bower packages are installed by default. Previously, the Asp.Net 5 templates in Visual Studio would install bower packages to a folder called bower_components, a practice familiar to web developers who do not use Visual Studio. However, apparently due to developer confusion, this has been changed to wwwroot/lib. This can be changed by editing the bowerrc file. As such, the bower_components folder does not exist in the new beta-8 templates. Please see this post by Scott Hanselman for more information.

like image 38
Blake Mumford Avatar answered Oct 17 '22 17:10

Blake Mumford