-resource (C# 編譯器選項)-resource (C# Compiler Options)

將指定的資源內嵌到輸出檔。Embeds the specified resource into the output file.

語法Syntax

-resource:filename[,identifier[,accessibility-modifier]]  

引數Arguments

filename
您想要內嵌到輸出檔的 .NET Framework 資源檔。The .NET Framework resource file that you want to embed in the output file.

identifier (選擇性)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 name.

accessibility-modifier (選擇性)accessibility-modifier (optional)
資源的存取範圍:公用或私用。The accessibility of the resource: public or private. 預設值是公用。The default is public.

備註Remarks

使用 -linkresource 將資源連結至組件,而不將資源檔新增至輸出檔案。Use -linkresource to link a resource to an assembly and not add the resource file to the output file.

根據預設,使用 C# 編譯器建立資源時,這些資源在組件中為公用狀態。By default, resources are public in the assembly when they are created by using the C# compiler. 若要將資源設為私用,可將 private 指定為存取範圍修飾詞。To make the resources private, specify private as the accessibility modifier. 不允許 publicprivate 以外的其他存取範圍。No other accessibility other than public or private is allowed.

例如,如果 filename 是由 Resgen.exe 或是在開發環境中所建立的 .NET Framework 資源檔,就可以使用 System.Resources 命名空間中的成員進行存取。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. 如需詳細資訊,請參閱 System.Resources.ResourceManagerFor more information, see System.Resources.ResourceManager. 對於其他所有資源,請使用 Assembly 類別中的 GetManifestResource 方法,以在執行階段存取資源。For all other resources, use the GetManifestResource methods in the Assembly class to access the resource at run time.

-res-resource 的簡短形式。-res is the short form of -resource.

輸出檔中資源的順序是從命令列上指定的順序決定。The order of the resources in the output file is determined from the order specified on the command line.

在 Visual Studio 開發環境中設定這個編譯器選項To set this compiler option in the Visual Studio development environment

  1. 將資源檔新增至專案。Add a resource file to your project.

  2. 選取您想要內嵌在方案總管 中的檔案。Select the file that you want to embed in Solution Explorer.

  3. 在 [屬性] 視窗中,選取檔案的 [建置動作] 。Select Build Action for the file in the Properties window.

  4. 將 [建置動作] 設定為 [內嵌資源] 。Set Build Action to Embedded Resource.

如需如何以程式設計方式設定這個編譯器選項的詳細資訊,請參閱 BuildActionFor information about how to set this compiler option programmatically, see BuildAction.

範例Example

編譯 in.cs,並附加 rf.resource 資源檔:Compile in.cs and attach resource file rf.resource:

csc -resource:rf.resource in.cs  

另請參閱See also