Ref folder within .NET 5.0 bin folder

C#.NetMsbuild.Net 5

C# Problem Overview


What is the ref folder when compiling .NET 5.0 application?

I mean this one:

[project_path]\bin\Debug\net5.0\ref\

C# Solutions


Solution 1 - C#

These are so called Reference Assemblies (assemblies that only contain the public interface of an assembly), these help speed up the build process, since projects that depend on this one will be able to see that there is no reason to recompile, even if the innards of the assembly have changed, because outwardly it's still the same.

These Reference Assemblies need to look the same as the real thing from the outside. Hence, they have the same filename, assembly name, assembly identity and everything. This allows the build system to use them as a substitute for the real thing. And since these assemblies don't have any of the implementation details, they only change when the interface of the contents changes. Due to these facts, they can't live in the same folder as the actual build output, and this is the reason for the extra ref folder. MsBuild will use these reference assemblies automatically to speed up the build process (at the expense of generating and comparing the reference assembly each time the compiled code results in a new project output and a few files in the output directory).

If your project isn't referenced by other projects, you don't get any benefits from these reference assemblies (if you don't hand them out to 3rd parties that is). And you can turn off this feature by adding this property to the project file:

<PropertyGroup>
     <!-- 
     Turns off reference assembly generation 
     See: https://docs.microsoft.com/en-us/dotnet/standard/assembly/reference-assemblies
     -->
     <ProduceReferenceAssembly>false</ProduceReferenceAssembly>
</PropertyGroup>

After changing the setting, make sure you clean your build outputs.

These reference assemblies can also be used to allow people to compile projects to work with your system, without having to install/redistribute the actual compiled assemblies that run on your server. This way people can develop extensions, plugins, or clients for your application without having to give them access to actual implementation. This can help protect your intellectual property, since .NET assemblies are easy to decompile.

See also:

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlek DeplerView Question on Stackoverflow
Solution 1 - C#jessehouwingView Answer on Stackoverflow