5

I know that NuGet packages (at least nowadays) should not be included in version control. How should I exclude files a package adds to my project?

For example: I have a .NET MVC project that uses the bootstrap NuGet package. It adds some CSS, JS, and font files to Content, Scripts, and fonts, respectively. Should these files be included in my source control? If not, what would be the best way to ignore them? (I'm using GIT on this particular project.)

sjokkogutten
  • 2,005
  • 2
  • 21
  • 24
ricksmt
  • 888
  • 2
  • 13
  • 34

2 Answers2

2

Generally speaking, generated files should not be tracked by your source control tool. Here is a good question that addresses pros/cons of doing so.

You can ignore those files and directories by creating a .gitignore file at the root of your repo.

Following your example package above, you could ignore that content by adding this to your .gitignore file:

Content
Scripts
fonts

Here is some more documentation on ignoring files with Git with .gitignore.

You can also populate your .gitignore based on what the VisualStudio project uses.

Community
  • 1
  • 1
Jonathan.Brink
  • 23,757
  • 20
  • 73
  • 115
  • Almost exactly what I wanted. I'm going to have non-Bootstrap files in Content and Scripts that I will want to include in my version control. Can you update or augment your answer to account for that? – ricksmt Jan 06 '16 at 00:11
  • @ricksmt that may get tricky since you will need to write a clever pattern to only include certain files in those directories. Have a look at the "Pattern Format" section here: https://git-scm.com/docs/gitignore. Have you considered putting your unique content in a separate directory path and then combining them together at runtime? – Jonathan.Brink Jan 06 '16 at 00:14
  • I suppose that's doable, but it puts development in nontraditional place, and I'd like to avoid that. – ricksmt Jan 06 '16 at 16:24
  • 1
    I'm going to add a comment (mostly for myself): I manually changed the `.gitignore` file, but Visual Studio wasn't having it. [This link](https://ericnelson.wordpress.com/2014/06/21/is-visual-studio-2013-ignoring-your-gitignore-file/) says to close Visual Studio and remove `ms-persist.xml` from the `.git` folder, and that fixes the problem. – ricksmt Jan 06 '16 at 16:32
1

You should add it to your .gitignore file.

You have this repository :
https://github.com/github/gitignore

Which is the official git repository for the ignored files for many platforms and languages.

You can also use this site to generate the file for you:

enter image description here

CodeWizard
  • 128,036
  • 21
  • 144
  • 167