Visual Studio and Github - Which files to ignore (C#)

Asked

Viewed 2,049 times

2

Hello! I’m studying C# and created a repository on Github to save the exercises.

When starting a new project, Visual Studio Community (2017) creates the following structure:

PastaDoProjeto/
    ArquivoProjeto.sln
    OutraPasta/
        Program.cs
        NomeDoPrograma.csproj
        App.config
        Properties/
            AssemblyInfo.cs
        obj/
            Debug/ //Pasta contendo vários arquivos
            Release/ //Pasta vazia
        bin/
            Debug/ //Pasta contendo vários arquivos
            Release/ //Pasta vazia

I’m in doubt about what files I must add to git and which to ignore. That is, what are the essential files for the repository to be cloned and the program run on another machine and, what files and/or folders can I simply ignore without injury to the "conveyance of program".

  • 1

    This site gitignore. is an online tool that generates . gitignore files according to the specified language. It is a very useful tool. On the home page just write the name of the language and click create. For your case just write Csharp it generates the file . gitignore.

2 answers

3


After the compilation process of a Visual Studio, files are usually created in folders /bin and /obj of your project, these being totally ignored in my gitignore's.

Already on the internet you can find several gitignore's ready for a specific type of project like Windows Forms, Asp.NET, etc..

Below I’ll leave a gitignore for you to test. (Remembering that if you have already uploaded the files that are as exception in gitignore, you will have to delete them manually from your repository):

*.suo
*.user
*.sln.docstates

# Build results
[Dd]ebug/
[Rr]elease/
x64/
[Bb]in/
[Oo]bj/
# build folder is nowadays used for build scripts and should not be ignored
#build/

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*

*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc

# OS generated files #
.DS_Store*
Icon?

# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile

# Visual Studio profiler
*.psess
*.vsp
*.vspx

# Guidance Automation Toolkit
*.gpState

# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper

# TeamCity is a build add-in
_TeamCity*

# DotCover is a Code Coverage Tool
*.dotCover

# NCrunch
*.ncrunch*
.*crunch*.local.xml

# Installshield output folder
[Ee]xpress/

# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html

# Click-Once directory
publish/

# Publish Web Output
*.Publish.xml

# Windows Azure Build Output
csx
*.build.csdef

# Windows Store app package directory
AppPackages/

# Others
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
modulesbin/
tempbin/

# EPiServer Site file (VPP)
AppData/

# RIA/Silverlight projects
Generated_Code/

# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm

# vim
*.txt~
*.swp
*.swo

# Temp files when opening LibreOffice on ubuntu
.~lock.*
 
# svn
.svn

# CVS - Source Control
**/CVS/

# Remainings from resolving conflicts in Source Control
*.orig

# SQL Server files
**/App_Data/*.mdf
**/App_Data/*.ldf
**/App_Data/*.sdf


#LightSwitch generated files
GeneratedArtifacts/
_Pvt_Extensions/
ModelManifest.xml

# =========================
# Windows detritus
# =========================

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Mac desktop service store files
.DS_Store

# SASS Compiler cache
.sass-cache

# Visual Studio 2014 CTP
**/*.sln.ide

# Visual Studio temp something
.vs/

# dotnet stuff
project.lock.json

# VS 2015+
*.vc.vc.opendb
*.vc.db

# Rider
.idea/

# Visual Studio Code
.vscode/

# Output folder used by Webpack or other FE stuff
**/node_modules/*
**/wwwroot/*

# SpecFlow specific
*.feature.cs
*.feature.xlsx.*
*.Specs_*.html

#####
# End of core ignore list, below put you custom 'per project' settings (patterns or path)
#####

Source: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

  • Just so I understand a little better: These files name.extension. guy *.obj are the files that Git will ignore?

  • Exactly friend. In fact any .objwill be ignored, not just a file with nome_específico.obj

  • 1

    Excellent. Independent of using the "gitignore generator" the shared file has already given me a good idea of what to include (in the file).

1

I’m wondering which files I should add to git and which ones to ignore. I can (read 'should') add the entire project folder?

You can add as many files as you want. The problem itself is that there are files that are not part of the development. These files should be ignored.

In python projects, I ignore "pycache". There is something like this in C# since Visual Studio (Community 2017) creates several folders and files?

In this case, you should focus on all files that are not important for project development.

For example, it makes no sense to commit log files, temporary folders, compiled files, upload folders, or files belonging to the library you are using.

In the latter case cited, when you will manage libraries of your project, you must commit the file responsible for controlling the management of their versions, and not the library archives themselves. For example, in Python projects instead of commiting the folder venv containing all dependencies, you must commit the requirements.txt; in the case of PHP, instead of commiting the folder vendor, you should only commit composer.json and composer.lock; In the case of VOLTARPM, you should not commit node_modules, and yes package.json. And so on and so forth.

The other developer who will develop together with you will, for example, run the npm install (or any other language library manager used) to install the dependencies on its machine.

For the files of node_modules are not part of the project, are only used by him as dependency.

In short

Do not focus on having a magic formula or just try to copy and paste from the internet the pattern to be followed for a .gitignore of a project.

To strengthen the idea, here is a translation of the documentation itself GIT:

Standards that must be controlled by version and distributed to other repositories via clone (i.e., files that all developers will want to ignore) must enter a file .gitignore.

A clear example of what is described above is a file .env (used in some languages to set local application settings). It makes no sense to add this to your repository, since it has your local database settings. If you send such a file in a commit, every time the developer who is working with you will have to edit and repair the database configuration.

  • When you say "Don’t focus on having a magic formula or just trying to copy and paste from the Internet... ", you write all your gitgnores each character? I just don’t see the need to reinvent the wheel, because it’s already ready on the internet, what you want is just to customize. Just my humble opinion.

  • "Already ready on the internet" leads you only to copy and paste, but without understanding the goal of existing gitignore. The so-called "ready on the internet" that you mentioned, only works for projects that have known structure. If it is using its own framework or doing it in alternative structure, it is more important to know how to do it than to copy and paste

  • But when the author says "I’m in doubt about which files I should add to git and which to ignore" he no longer understands the goal? You should point out in your answer that the goal of not copying from the internet is a means of learning by putting your hand in the dough because we developers know that it doesn’t work in practice unless you want to.

  • No. My goal was to train his head to know, without having to have a "cake recipe", how to proceed to ignore the files. There are no problems copying and pasting, but it’s important to understand where gitignore should be used. The goal of the answer was to be generic and be used for any language, since the purpose of the site is to make a specific question can be used to help other programmers

  • @Wallacemaxters I understand and thank you for your intention, however you do not answer my question... I know some "ready-made solutions" like gitignore.io and found some "models" like the one shared by the author of the previous answer. However, according to the question, I am studying C# now, I still have no knowledge about what is each folder and file, so the.

  • What framework are you using?

  • None (nothing but .NET)... are basically command-line studies.

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.