建置動作Build actions

Visual Studio for Mac 專案中的所有檔案都有一個建置動作。All files in a Visual Studio for Mac project have a build action. 組建動作會控制在組建期間,檔案會發生什麼事。The build action controls what happens to the file during a build.

注意

本主題適用於 Visual Studio for Mac。This topic applies to Visual Studio for Mac. 針對 Windows 上的 Visual Studio,請參閱 組建動作For Visual Studio on Windows, see Build actions.

設定建置動作Set a build action

若要在 Visual Studio for Mac 中設定檔案的組建動作,您可以在任何檔案上按一下滑鼠右鍵,然後流覽至 [ 建立] 動作,如下所示:To set a build action for a file in Visual Studio for Mac, you can right-click on any file and browsing to Build Action, as illustrated below:

從 [方案總管] 選取編譯建置動作

這個檔案的組建動作將會顯示在飛出視窗功能表中。Build actions for this file will be shown in the flyout menu.

建置動作值Build action values

您可以在 Visual Studio for Mac 中建立之專案的一些常見組建動作包括:Some of the common build actions for projects you can build in Visual Studio for Mac include:

建置動作Build Action 專案類型Project types 描述Description
編譯Compile 任意any 檔案會以原始程式檔的形式傳遞至 c # 編譯器。The file is passed to the C# compiler as a source file.
內容Content .NET,Xamarin.NET, Xamarin 若是 ASP.NET 專案,這些檔案將在網站部署時納入為網站的一部分。For ASP.NET projects, these files are included as part of the site when it's deployed. 針對 Xamarin.iOS 和 Xamarin.Mac 專案,它們會包含在應用程式套件組合中。For Xamarin.iOS and Xamarin.Mac projects, they'll be included in the app bundle.
Embedded ResourceEmbedded Resource .NET.NET 檔案會以資源的形式傳遞至 c # 編譯器,以內嵌在元件中。The file is passed to the C# compiler as a resource to be embedded in the assembly. 之後,可以使用 System.Reflection 命名空間中的 Assembly.GetManifestResourceStream 從組件中讀取該檔案。Assembly.GetManifestResourceStream, from the System.Reflection namespace, can then be used to read the file from the assembly.
None 任意any 檔案不是組建的一部分,而且會包含在專案中,以方便從 IDE 進行存取。The file isn't part of the build in any way and is included in the project for easy access from the IDE. 這個值可以用於文件檔,例如「讀我」檔案。This value can be used for documentation files such as "ReadMe" files, for example.

注意

由於可以針對特定專案類型定義其他建置動作,因此建置動作清單會取決於專案類型,而且可能會出現不在此清單中的值。Additional build actions may be defined by for specific project types, so the list of build actions depends on the project type and values might appear that are not in this list.

Xamarin.iOS 專案擁有 BundleResource 建置動作,該動作會新增檔案作為應用程式套件組合的一部分。Xamarin.iOS projects have the BundleResource build action, which will add the file as part of the app bundle. 如需 Xamarin.Android 特定建置動作的資訊,請參閱建置流程指南。Information on Xamarin.Android specific build actions can be found in the build process guide.

您也可以在 [方案瀏覽器] 中選取一個以上的檔案,讓您一次將組建動作設定為許多檔案。It's also possible to select more than one file in the solution explorer, allowing you to set the build action to many files at once.

另請參閱See also