安裝 Microsoft Advertising SDKInstall the Microsoft Advertising SDK

警告

從2020年6月1日起,適用于 Windows UWP 應用程式的 Microsoft Ad 營收平臺將會關閉。As of June 1, 2020, the Microsoft Ad Monetization platform for Windows UWP apps will be shut down. 深入了解Learn more

若要在您的適用於 Windows 10 的 UWP app 中顯示廣告,請安裝 Microsoft Advertising SDKTo display ads in your UWP apps for Windows 10, install the Microsoft Advertising SDK. 這個 SDK 是 Visual Studio 2015 和更新版本的擴充功能。This SDK is an extension to Visual Studio 2015 and later versions.

注意

如果您正在開發 JavaScript/HTML UWP 應用程式,且您已安裝 Windows 10 SDK 版本 10.0.14393 (年度更新) 或更新版本,您也必須安裝 WinJS 程式庫。If you are developing a JavaScript/HTML UWP app and you have installed Windows 10 SDK version 10.0.14393 (Anniversary Update) or later, you must also install the WinJS library. 這個程式庫原本包含在舊版的 Windows 10 SDK 中,但是從 Windows 10 SDK 版本 10.0.14393 (年度更新版) 起必須另外安裝。This library used to be included in previous versions of the Windows 10 SDK, but starting with the Windows 10 SDK version 10.0.14393 (Anniversary Update) this library must be installed separately.

透過 MSI 安裝Install via MSI

透過 MSI 安裝程式安裝 Microsoft Advertising SDK:To install the Microsoft Advertising SDK via the MSI installer:

  1. 關閉所有 Visual Studio 執行個體。Close all instances of Visual Studio.

  2. 如果您先前已安裝任何版本的 Microsoft Advertising SDK、Universal Ad Client SDK、Ad Mediator 擴充功能或 Microsoft Store Engagement and Monetization SDK,請將這些 SDK 版本解除安裝。If you previously installed any previous version of the Microsoft Advertising SDK, Universal Ad Client SDK, Ad Mediator extension, or Microsoft Store Engagement and Monetization SDK, uninstall these SDK versions now. 或者,也可以開啟 [命令提示字元] 視窗,然後執行下列命令,以清除可能已與 Visual Studio 一起安裝但未出現在電腦上已安裝程式清單中的任何舊廣告 SDK 版本:Optionally, open a Command Prompt window and run these commands to clean out any older advertising SDK versions that may have been installed with Visual Studio, but which may not appear in the list of installed programs on your computer:

    MsiExec.exe /x{5C87A4DB-31C7-465E-9356-71B485B69EC8}
    MsiExec.exe /x{6AB13C21-C3EC-46E1-8009-6FD5EBEE515B}
    MsiExec.exe /x{6AC81125-8485-463D-9352-3F35A2508C11}
    
  3. 下載並安裝 Microsoft Advertising SDKDownload and install the Microsoft Advertising SDK. 可能需要幾分鐘的時間來安裝。It may take a few minutes to install. 請務必等到程序完成為止。Be sure and wait until the process has finished.

  4. 重新啟動 Visual Studio。Restart Visual Studio.

  5. 如果您現有的專案參考來自任何舊版 Microsoft Advertising SDK、通用廣告用戶端 SDK 或 Microsoft Store Engagement and Monetization SDK 的廣告庫,建議您在 Visual Studio 中開啟您的專案,然後清除並重建您的專案 (在 [方案總管] 中您的專案節點上按一下滑鼠右鍵並選擇 [清除],然後在您的專案節點上再次按一下滑鼠右鍵並選擇 [重建])。If you have an existing project that references advertising libraries from any earlier version of the Microsoft Advertising SDK, Universal Ad Client SDK, or Microsoft Store Engagement and Monetization SDK, we recommend that you open your project in Visual Studio and clean and rebuild your project (in Solution Explorer, right-click your project node and choose Clean, and then right-click your project node again and choose Rebuild).

否則,如果您是第一次在專案中使用 Microsoft Advertising SDK,您現在便已準備好新增 Microsoft Advertising SDK 的參考Otherwise, if you are using the Microsoft Advertising SDK for the first time in your project, you are now ready to add a reference to the Microsoft Advertising SDK.

透過 NuGet 安裝Install via NuGet

若要透過 NuGet 在特定 UWP 專案中安裝 Microsoft Advertising SDK:To install the Microsoft Advertising SDK in a specific UWP project via NuGet:

  1. 關閉所有 Visual Studio 執行個體。Close all instances of Visual Studio.

  2. 如果您先前已安裝任何版本的 Microsoft Advertising SDK、Universal Ad Client SDK、Ad Mediator 擴充功能或 Microsoft Store Engagement and Monetization SDK,請將這些 SDK 版本解除安裝。If you previously installed any previous version of the Microsoft Advertising SDK, Universal Ad Client SDK, Ad Mediator extension, or Microsoft Store Engagement and Monetization SDK, uninstall these SDK versions now. 或者,也可以開啟 [命令提示字元] 視窗,然後執行下列命令,以清除可能已與 Visual Studio 一起安裝但未出現在電腦上已安裝程式清單中的任何舊廣告 SDK 版本:Optionally, open a Command Prompt window and run these commands to clean out any older advertising SDK versions that may have been installed with Visual Studio, but which may not appear in the list of installed programs on your computer:

    MsiExec.exe /x{5C87A4DB-31C7-465E-9356-71B485B69EC8}
    MsiExec.exe /x{6AB13C21-C3EC-46E1-8009-6FD5EBEE515B}
    MsiExec.exe /x{6AC81125-8485-463D-9352-3F35A2508C11}
    
  3. 啟動 Visual Studio,然後開啟您要在其中使用 Microsoft Advertising SDK 的專案。Start Visual Studio and open the project in which you want to use the Microsoft Advertising SDK.

    注意

    如果您的專案已經包含來自先前 MSI 安裝之 SDK 的程式庫參考,請從您的專案中移除這些參考。If your project already includes library references from an earlier MSI installation of the SDK, remove these references from your project. 這些參考的旁邊將會有警告圖示,因為在先前的步驟中已移除它們所參考的程式庫。These references will have warning icons next to them because the libraries they reference were removed in the previous steps.

  4. 在 Visual Studio 中,按一下 [專案]**** 和 [管理 NuGet 套件]****。In Visual Studio, click Project and Manage NuGet Packages.

  5. 在搜尋方塊中,輸入 Microsoft.Advertising.XAML (適用於 XAML 專案) 或 Microsoft.Advertising.JS (適用於 JavaScript/HTML 專案) 並安裝對應的套件。In the search box, type Microsoft.Advertising.XAML (for a XAML project) or Microsoft.Advertising.JS (for a JavaScript/HTML project) and install the corresponding package. 套件完成安裝後,儲存您的方案。When the package is done installing, save your solution.

    注意

    如果 [輸出] 視窗回報 Install-Package 錯誤,指出指定的路徑太長,您可能需要設定讓 NuGet 將套件解壓縮至路徑比預設位置短的替代位置。If the Output window reports an Install-Package error that indicates the specified path is too long, you may need to configure NuGet to extract packages to an alternate location with a shorter path than the default location. 若要這樣做,請將 repositoryPath 值新增到您電腦上的 nuget.config 檔案中,然後將它指派至可解壓縮 NuGet 套件的較短資料夾路徑。To do this, add the repositoryPath value to a nuget.config file on your computer and assign it to a short folder path where NuGet packages can be extracted. 如需詳細資訊,請參閱 NuGet 文件中的這篇文章For more information, see this article in the NuGet documentation. 或者,您也可以嘗試將您的 Visual Studio 專案移至路徑較短的替代資料夾。Alternatively, you can try moving your Visual Studio project to an alternate folder with a shorter path.

  6. 關閉您的方案,然後重新開啟它。Close your solution and then reopen it.

  7. 如果您的專案已經參考來自透過 NuGet 安裝之舊版 Microsoft Advertising SDK 的程式庫,而您已將專案更新至新版 SDK,建議您清除並重建您的專案 (在 [方案總管] 中您的專案節點上按一下滑鼠右鍵並選擇 [清除],然後在您的專案節點上再次按一下滑鼠右鍵並選擇 [重建])。If your project already references libraries from an earlier version of the Microsoft Advertising SDK that was installed via NuGet and you have updated your project to a newer release of the SDK, we recommend that you clean and rebuild your project (in Solution Explorer, right-click your project node and choose Clean, and then right-click your project node again and choose Rebuild).

否則,如果您是第一次在專案中使用 SDK,您現在便已準備好新增 Microsoft Advertising SDK 的參考Otherwise, if you are using the SDK for the first time in your project, you are now ready to add a reference to the Microsoft Advertising SDK.

新增Microsoft Advertising SDK 的參考Add a reference to the Microsoft Advertising SDK

安裝 Microsoft Advertising SDK 之後,請依照這些指示,在專案中參考 SDK 以便使用廣告 API。After you install the Microsoft Advertising SDK, follow these instructions to reference the SDK in your project so you can use the advertising APIs.

  1. 在 Visual Studio 中,開啟您的專案。Open your project in Visual Studio.

    注意

    如果專案的目標是 [任何 CPU],請將您的專案更新成使用架構特定的建置輸出 (例如,[x86])。If your project targets Any CPU, update your project to use an architecture-specific build output (for example, x86). 如果專案的目標是 [任何 CPU],您將無法於下列步驟中成功加入 Microsoft Advertising SDK 的參考。If your project targets Any CPU, you will not be able to successfully add a reference to the Microsoft Advertising SDK in the following steps. 如需詳細資訊,請參閱專案中因目標為 [任何 CPU] 所造成的參考錯誤For more information, see Reference errors caused by targeting Any CPU in your project.

  2. 方案總管中,以滑鼠右鍵按一下 [參考],然後選取 [加入參考]。In Solution Explorer, right click References and select Add Reference…

  3. [參考管理員] 中,展開 [通用 Windows],按一下 [擴充功能],然後選取 [適用於 XAML 的 Microsoft Advertising SDK] 旁邊的核取方塊 (適用於 XAML app) 或 [適用於 JavaScript 的 Microsoft Advertising SDK] 旁邊的核取方塊 (適用於使用 JavaScript 和 HTML 建置的應用程式)。In Reference Manager, expand Universal Windows, click Extensions, and then select the check box next to Microsoft Advertising SDK for XAML (for XAML apps) or Microsoft Advertising SDK for JavaScript (for apps built using JavaScript and HTML).

  4. 在 [參考管理員]**** 中,按一下 [確定]。In Reference Manager, click OK.

如需示範如何開始使用廣告 API 的逐步解說,請參閱下列文章:For walkthroughs that show how to get started using the advertising APIs, see the following articles:

了解 Microsoft Advertising SDK 中的架構套件Understanding framework packages in the Microsoft Advertising SDK

適用於 UWP App 的 Microsoft Advertising SDK 中的 Microsoft.Advertising.dll 程式庫是設定為架構套件The Microsoft.Advertising.dll library in the Microsoft Advertising SDK (for UWP apps) is configured as a framework package. 這個程式庫包含 Microsoft.AdvertisingMicrosoft.Advertising.WinRT.UI 命名空間中的廣告 API。This library contains the advertising APIs in the Microsoft.Advertising and Microsoft.Advertising.WinRT.UI namespaces.

因為這個程式庫是架構套件,這意謂著在使用者安裝使用這個程式庫的 App 版本之後,每當我們發佈具有修正程式和效能改進的新程式庫版本時,便會在其裝置上透過 Windows Update 自動更新這個程式庫。Because this library is a framework package, this means that after a user installs a version of your app that uses this library, this library is automatically updated on their device through Windows Update whenever we publish a new version of the library with fixes and performance improvements. 這有助於確保您客戶的裝置上一律會安裝最新的可用程式庫版本。This helps to ensure that your customers always have the latest available version of the library installed on their devices.

如果我們發行的新版 SDK 在這個程式庫中引進新的 API 或功能,您將必須安裝最新版的 SDK 才能使用這些功能。If we release a new version of the SDK that introduces new APIs or features in this library, you will need to install the latest version of the SDK to use those features. 在此情況下,您也需要將已更新的 App 發佈到「Microsoft Store」。In this scenario, you would also need to publish your updated app to the Store.