Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ref folder within .NET 5.0 bin folder

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

I mean this one:

[project_path]\bin\Debug\net5.0\ref\ 
like image 759
Alek Depler Avatar asked Nov 20 '20 08:11

Alek Depler


People also ask

What is ref folder in .NET core?

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 ...

What is an Ref folder?

At run-time, in order to ensure Razor view engine uses same set of assemblies as referenced during compile time, refs folder is generated during the 'publish' step containing all the referenced assemblies of your app and its dependencies.

How to Add Reference to assembly c#?

In the Project Designer, click the References tab. Click the Add button to open the Add Reference dialog box. In the Add Reference dialog box, select the tab indicating the type of component you want to reference. Select the components you want to reference, and then click OK.


1 Answers

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:

  • https://stackoverflow.com/a/58911152/736079
like image 97
jessehouwing Avatar answered Sep 26 '22 07:09

jessehouwing