Search code examples
visual-studionugetvisual-studio-2019ref

Visual Studio is creating ref folder


I have noticed that VS2019 creates this 'ref' folder inside my project. It contains just bunch of DLL's and I get an error when I try to delete it. When I close VS and delete bin and obj folders and reopen solution it is not there but gets created again shortly after.

I could not find much info on what is the purpose of this folder and why it appears there. Any information is appreciated. I also add screen shot for better understanding.

enter image description here


Solution

  • It contains just bunch of DLL's and I get an error when I try to delete it. When I close VS and delete bin and obj folders and reopen solution it is not there but gets created again shortly after.

    I think this issue is caused by some specific nuget packages if there are no other scripts for your project . And there is a similar issue.

    And the nuget package contains some <package_id>.targets or props files or contentfiles tag to import some extra files into your project and it created the ref folder which included some useful files in your situation due to it.

    Let me explain it in more detail

    When you create a nuget package and want to import some extra files or do some extra operation when you install this package into a new main project, you can use MSBuild props and targets, contentfiles tag or powershell scripts to import some extra files into the new project.

    Usually, the author creates them for a specific purpose, so please do not delete them easily in projects which will cause other problems. Besides, the author will add some sort of recovery mechanism to prevent accidental deletion of the file from being unrecoverable.

    To check this debavior:

    I suggest you could create a new empty project and then install these nuget packages one by one to check which package is the role. Or you can share these packages with us so that we can help you find it.