/linkresource (C# Compiler Options)


Updated: July 20, 2015

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

Creates a link to a .NET Framework resource in the output file. The resource file is not added to the output file. This differs from the /resource option which does embed a resource file in the output file.


The .NET Framework resource file to which you want to link from the assembly.

identifier (optional)
The logical name for the resource; the name that is used to load the resource. The default is the name of the file.

accessibility-modifier (optional)
The accessibility of the resource: public or private. The default is public.

By default, linked resources are public in the assembly when they are created with the C# compiler. To make the resources private, specify private as the accessibility modifier. No other modifier other than public or private is allowed.

/linkresource requires one of the /target options other than /target:module.

If filename is a .NET Framework resource file created, for example, by Resgen.exe or in the development environment, it can be accessed with members in the System.Resources namespace. For more information, see System.Resources.ResourceManager. For all other resources, use the GetManifestResource* methods in the Assembly class to access the resource at run time.

The file specified in filename can be any format. For example, you may want to make a native DLL part of the assembly, so that it can be installed into the global assembly cache and accessed from managed code in the assembly. The second of the following examples shows how to do this. You can do the same thing in the Assembly Linker. The third of the following examples shows how to do this. For more information, see Al.exe (Assembly Linker) and Working with Assemblies and the Global Assembly Cache.

/linkres is the short form of /linkresource.

This compiler option is unavailable in Visual Studio and cannot be changed programmatically.

Compile in.cs and link to resource file rf.resource:

csc /linkresource:rf.resource in.cs  

Compile A.cs into a DLL, link to a native DLL N.dll, and put the output in the Global Assembly Cache (GAC). In this example, both A.dll and N.dll will reside in the GAC.

csc /linkresource:N.dll /t:library A.cs  
gacutil -i A.dll  

This example does the same thing as the previous one, but by using Assembly Linker options.

csc /t:module A.cs  
al /out:A.dll A.netmodule /link:N.dll   
gacutil -i A.dll  

C# Compiler Options
Al.exe (Assembly Linker)
Working with Assemblies and the Global Assembly Cache
NIB How to: Modify Project Properties and Configuration Settings