.NET 客户端库使用入门
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Jeff Fisher,Google Data API 团队
2007 年 8 月
简介
图 1:Google Data API 解决方案
对于许多开发者来说,新项目中最困难的部分是开始阶段,即安装新的软件包、配置开发环境和学习新的库。在本文中,我汇总了一些分步说明,介绍了如何使用 Visual Studio 2005 for Windows 或 Mono for Linux 及其他 Unix 操作系统开始使用 .NET 客户端库。希望这能帮助您节省一些入门时间,让您快速开始使用一些代码。
Visual Studio 2008
如果您尚未安装 Visual Studio 2008,不妨考虑使用 Visual C# 2008 Express Edition,这是 Visual Studio 的免费版本,可让您使用 .NET 客户端库。
设置环境
- 从 http://code.google.com/p/google-gdata/downloads/list 下载客户端库的最新 MSI 版本。
- 运行下载的 MSI 文件以安装软件包。默认情况下,它将安装到“C:\Program Files\Google\Google Data API SDK\”中。本文中的后续示例将假定您已将客户端库安装到此位置。
- 在“开始”菜单中的“Google Data API SDK”文件夹中打开名为“Google Data API SDK”的解决方案文件。
编译和运行示例
- 验证运行“Build > Build Solution”是否完成且没有出现任何错误。
- 如需创建调试 build,请依次前往“Build > Configuration Manager”,然后选择“Debug”作为有效解决方案配置。然后选择“Build > Build Solution”。
- 您刚刚编译的二进制文件和 DLL 文件位于“C:\Program Files\Google\Google Data API SDK\Sources\Samples\”中。例如,您可以执行“C:\Program Files\Google\Google Data API SDK\Sources\Samples\calendar\bin\Debug\Calendar.exe”来运行日历示例应用。此外,还有一些指向这些示例的“开始”菜单快捷方式。
开发自己的应用
如果您想在 MSI 文件提供的解决方案文件之外的项目中进行开发,则需要将客户端库 DLL 文件添加为引用路径。
- 在 Google API SDK 解决方案之外创建或打开项目。
- 从“项目”菜单中选择“添加参考”。
- 点击“浏览”标签页。
- 前往 SDK 中的 Redist 目录:“C:\Program Files\Google\Google Data API SDK\Redist”。
- 选择代码将使用的 DLL 文件。大多数项目都需要 Google.GData.Extensions.dll 和 Google.GData.Client.dll,以及您在应用中使用的 Google 服务的特定 DLL 文件。
注意:还有适用于移动设备上客户端库的解决方案文件。默认情况下,它位于“C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005.mobile”中。此解决方案只会编译客户端库的 DLL 文件。
运行 NUnit 测试
如果您对客户端库进行了任何更改,或者计划为其做出贡献,请务必确保相应的 NUnit 测试通过。如果您打算使用客户端库而不进行修改,通常无需运行它们。
- 从 http://www.nunit.org/index.php?p=download 下载 NUnit 的 .NET 2.0 MSI 文件版本。
- 运行 MSI 文件来安装 NUnit。默认安装位置类似于“C:\Program Files\NUnit 2.4.8”。您可能希望将其更改为“C:\Program Files\NUnit”之类的路径,以便日后升级 NUnit 时无需更改 Visual Studio 项目中的路径。
- 前往“C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005”目录,然后打开名为“Google Data APIs”的解决方案文件。
由于这是 Visual Studio 2005 项目文件,因此您会看到转换向导。您可以点击提示继续操作,也可以直接点击“完成”按钮。它应该会显示转化日志,您可以忽略该日志。
- 现在,必须将 NUnit 添加为引用路径。在右侧的解决方案资源管理器中,右键点击“unittests”项目,然后选择“属性”。现在,点击打开的窗口中的“参考路径”标签页。输入 NUnit 安装的“bin”子目录的位置作为参考路径,然后点击“添加文件夹”。例如,如果 NUnit 安装到了“C:\Program Files\NUnit\”,则应输入“C:\Program Files\NUnit\bin”。请务必先保存此更改,然后再继续。
- 按照编译和运行示例中列出的步骤重建客户端库和单元测试。
- 将“C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\”中的“unittests.dll.config”文件复制到调试 build 目录“C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\”。请记得修改该文件,以纳入您要运行的测试的相应信息。例如,Base 需要 API 密钥,而 Calendar 需要用户名和密码。建议使用没有任何实际数据的测试账号,以免信息被单元测试删除。
- 从“开始”菜单中打开 NUnit。
- 依次前往“File > Open Project”,然后从“C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\"中选择“unittests.dll”文件。
- 运行您感兴趣的单元测试。请注意,某些测试需要设置 unittests.dll.config 中的参数才能正常运行。如果您针对某些服务运行压力测试,您的测试账号可能会被标记为生成垃圾内容,并且在未遇到 CAPTCHA 挑战的情况下,无法以编程方式向 Google 服务器提交内容。
单声道
Mono 是一个开源项目,可让您在 Linux、Solaris、Mac OS X、Windows 和 Unix 上运行 .NET 客户端和服务器应用。对于想要在上述平台之一上工作的开发者,我们提供单独的客户端库 ZIP 文件。
设置环境
- 从 http://code.google.com/p/google-gdata/downloads/list 下载客户端库的最新 ZIP 文件版本
- 解压缩到本地目录(例如“/scratch/gdata.NET”)
- 使用发行版的软件包管理系统安装 Mono。
或者,您也可以从 http://www.mono-project.com 下载。
- 在某些发行版中,您必须确保 nunit.framework.dll 文件已正确链接到 Mono 库。如果 Mono 安装到“/usr/lib/mono”,请确保“/usr/lib/mono/1.0”和“/usr/lib/mono/2.0”中存在 nunit.framework.dll 的符号链接(应安装在“/usr/lib/mono/gac/nunit.framework/<someversionstring>/nunit.framework.dll”中)。
编译和运行示例
- 假设您已将客户端库安装到“/scratch/gdata.NET”,请更改为“/scratch/gdata.NET/clients/cs”目录。
- 根据您要使用的 .NET 版本修改 Makefile。对于 .NET 1.x,请使用
CSC=mcs
;对于 .NET 2.x,请使用 CSC=gmcs
。
- 运行
make
以编译库和示例应用。
- 如果您想将客户端库 DLL 安装到 Mono 库中,请执行
make install
。
开发自己的应用
如果您在编译客户端库后执行了 make install
,则应该能够通过将 -r:Google.GData.Extensions.dll -r:Google.GData.Client.dll
传递给 Mono C# 编译器(同时传递对您希望使用的任何特定服务扩展 DLL 文件的引用),在自己的代码中包含这些库。
运行 NUnit 测试
- 将 unittests.dll.config 文件从“/scratch/gdata.NET/clients/cs/src/unittests”复制到“/scratch/gdata.NET/clients/cs/”。
- 修改“/scratch/gdata.NET/clients/cs/unittests.dll.config”,以包含您要运行的测试的相应信息。例如,Base 需要 API 密钥,而 Calendar 需要用户名和密码。我建议您使用没有任何实时数据的测试账号,以避免信息被单元测试删除。
- 编译库后,“/scratch/gdata.NET/clients/cs”中会有一个 unittests.dll 文件。将此 DLL 与您选择的 NUnit 测试管理器(nunit-console、gnunit 等)搭配使用。
总结
现在,您应该能够编译库并运行示例代码了。不过,这仅仅是开始。建议您仔细阅读客户端库的“.../clients/cs/docs”目录中的文档。您可能还想查看 .NET 客户端库开发者指南、项目页面和参考指南,以及 Google Data .NET 客户端库论坛。
本文中提及的工具:
祝您在下一个 .NET 应用中取得成功!
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-27。
[null,null,["最后更新时间 (UTC):2025-07-27。"],[[["\u003cp\u003eThis guide provides step-by-step instructions for setting up and using the Google Data .NET client library with either Visual Studio 2008 or Mono.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use this library to interact with various Google services like Calendar by compiling and running provided sample applications or by developing their own applications.\u003c/p\u003e\n"],["\u003cp\u003eThe guide includes details on compiling the library, running provided unit tests for verifying functionality, and configuring the development environment for both Windows and Unix-based systems.\u003c/p\u003e\n"],["\u003cp\u003eAdditional resources such as the .NET Client Library Developer's Guide and project forums are available for further assistance.\u003c/p\u003e\n"]]],[],null,["# Getting Started with the .NET Client Library\n\n*Jeff Fisher, Google Data APIs team\nAugust 2007*\n\n- [Introduction](#introduction)\n- [Visual Studio 2008](#vs2005)\n - [Setting up your environment](#vssetup)\n - [Compiling and running samples](#vscompile)\n - [Developing your own application](#vsdevelop)\n - [Running the NUnit tests](#vsnunit)\n- [Mono](#mono)\n - [Setting up your environment](#monosetup)\n - [Compiling and running samples](#monocompile)\n - [Developing your own application](#monodevelop)\n - [Running the NUnit tests](#mononunit)\n- [Conclusion](#conclusion)\n\n### Introduction\n\n\u003cbr /\u003e\n\n**Figure 1: The Google Data API solution**\n\nFor many developers, the most difficult part of a new project is getting the ball rolling-installing new software packages, configuring a development environment, and learning new libraries. In this article, I have pulled together some step-by-step instructions for how to begin with the .NET client library using either Visual Studio 2005 for Windows or Mono for Linux and other Unix operating systems. It is my hope that this will save you some time in getting started and let you quickly start working with some code.\n\nVisual Studio 2008\n------------------\n\nIf you do not already have Visual Studio 2008 installed, you may want to consider using [Visual C# 2008 Express Edition](http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-02.aspx), a free version of Visual Studio that will allow you to work with the .NET client library.\n\n### Setting up your environment\n\n1. Download the latest MSI release of the client library from [http://code.google.com/p/google-gdata/downloads/list](//code.google.com/p/google-gdata/downloads/list).\n2. Run the downloaded MSI file to install the package. It will install to \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\\" by default. Further examples in this article will assume you installed the client library to this location.\n3. Open the solution file called \"Google Data API SDK\" in the \"Google Data API SDK\" folder in the Start Menu.\n\n### Compiling and running samples\n\n1. Verify that running \"Build \\\u003e Build Solution\" completes without any errors.\n2. To create a Debug build go to \"Build \\\u003e Configuration Manager\" and select \"Debug\" as the active solution configuration. Then select \"Build \\\u003e Build Solution\".\n3. The binaries and DLL files you have just compiled can be found in \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Sources\\\\Samples\\\\\" For example, you can run the sample application for Calendar by executing \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Sources\\\\Samples\\\\calendar\\\\bin\\\\Debug\\\\Calendar.exe\". There are also some Start Menu shortcuts to these samples.\n\n### Developing your own application\n\nIf you want to develop in a project outside of the solution file provided by the MSI file, you need to add the client library DLL files as a reference path.\n\n1. Create or open a project outside of the Google API SDK solution.\n2. Select \"Add Reference\" from the Project menu.\n3. Click on the Browse tab.\n4. Navigate to the Redist directory in the SDK: \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Redist\".\n5. Select the DLL files that will be used by your code. Google.GData.Extensions.dll and Google.GData.Client.dll will be needed for most projects, along with the DLL file specific to the Google service(s) you are using in your application.\n\n**Note:** There is also a solution file for client libraries on Mobile devices. It is found in \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Sources\\\\Library\\\\VS2005.mobile\" by default. This solution will only compile the DLL files for the client libraries.\n\n### Running the NUnit tests\n\nMaking sure the appropriate NUnit tests pass is an important step if you make any changes to the client libraries or plan to contribute to them. If you plan to use the client libraries without modifications then there is normally no need to run them.\n\n1. Download the .NET 2.0 MSI file release of NUnit from \u003chttp://www.nunit.org/index.php?p=download\u003e.\n2. Install NUnit by running the MSI file. The default install location is similar to \"C:\\\\Program Files\\\\NUnit 2.4.8\". You may wish to change this to something like \"C:\\\\Program Files\\\\NUnit\" so you can upgrade NUnit in the future without having to change the path in your Visual Studio project.\n3. Go to the \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Sources\\\\Library\\\\VS2005\" directory and open the solution file named \"Google Data APIs\". You will see the Conversion Wizard since this is a Visual Studio 2005 project file. Either click through the prompts or simply click on the \"Finish\" button. It should display the conversion log, which can be ignored.\n4. Now NUnit must be added as a reference path. Right click on the \"unittests\" project in the Solution Explorer on the right and select \"Properties\". Now click on the \"Reference Paths\" tab within the window that opens. Enter in the location of the \"bin\" subdirectory of the NUnit installation as a reference path and click \"Add Folder\". For example, if NUnit is installed to \"C:\\\\Program Files\\\\NUnit\\\\\", one would enter \"C:\\\\Program Files\\\\NUnit\\\\bin\". Be sure to save this change before continuing.\n5. Follow the steps listed in [Compiling and running samples](#vscompile) to rebuild the client library and the unit tests.\n6. Copy the \"unittests.dll.config\" file in \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Sources\\\\Library\\\\unittests\\\\\" to your debug build directory \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Source\\\\Library\\\\VS2005\\\\unittests\\\\bin\\\\Debug\\\\\". Remember to edit the file to include the appropriate information for the tests you are running. For example, Base requires an API key and Calendar requires a username and password. It is recommended to use a test account without any live data to avoid having information deleted by the unit tests.\n7. Open NUnit from the Start Menu.\n8. Go to \"File \\\u003e Open Project\" and select the \"unittests.dll\" file from \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Source\\\\Library\\\\VS2005\\\\unittests\\\\bin\\\\Debug\\\\\".\n9. Run the unit tests you are interested in. Remember that certain tests require parameters be set in unittests.dll.config to work. If you run the stress tests for certain services you may have your test account flagged as generating spam and be unable to programmatically submit content to Google servers without encountering CAPTCHA challenges.\n\nMono\n----\n\nMono is an open source project that allows you to run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. We offer a separate ZIP file of our client library for developers who want to work on one of these platforms.\n\n### Setting up your environment\n\n1. Download the latest ZIP file release of the client library from [http://code.google.com/p/google-gdata/downloads/list](//code.google.com/p/google-gdata/downloads/list)\n2. Extract to a local directory (e.g. \"/scratch/gdata.NET\")\n3. Use your distribution's package management to install Mono. Alternatively, you can download it from \u003chttp://www.mono-project.com\u003e.\n4. In some distributions you have to make sure that the nunit.framework.dll file is properly linked into the mono library. If mono was installed to \"/usr/lib/mono\", then ensure that there are symbolic links in \"/usr/lib/mono/1.0\" and \"/usr/lib/mono/2.0\" for nunit.framework.dll (which should be installed in \"/usr/lib/mono/gac/nunit.framework/\\\u003csomeversionstring\\\u003e/nunit.framework.dll\").\n\n### Compiling and running samples\n\n1. Assuming you installed the client library to \"/scratch/gdata.NET\", change to the \"/scratch/gdata.NET/clients/cs\" directory.\n2. Edit the Makefile depending on what version of .NET you wish to use. For .NET 1.x, use `CSC=mcs` and for .NET 2.x, use `CSC=gmcs`.\n3. Run `make` to compile the libraries and sample applications.\n4. Execute `make install` if you want to install the client library DLLs into the Mono library.\n\n### Developing your own application\n\nIf you executed a `make install` after compiling the client library, you should be able to include the libraries in your own code by passing `-r:Google.GData.Extensions.dll -r:Google.GData.Client.dll` to the Mono C# compiler along with references to the DLL files of any specific service extensions you wish to use.\n\n### Running the NUnit tests\n\n1. Copy the unittests.dll.config file from \"/scratch/gdata.NET/clients/cs/src/unittests\" to \"/scratch/gdata.NET/clients/cs/\".\n2. Edit \"/scratch/gdata.NET/clients/cs/unittests.dll.config\" to include the appropriate information for the tests you are running. For example, Base requires an API key and Calendar requires a username and password. I recommend using a test account without any live data to avoid having information deleted by the unit tests.\n3. After compiling the library there will be a unittests.dll file in \"/scratch/gdata.NET/clients/cs\". Use this DLL with your NUnit test manager of choice (nunit-console, gnunit, etc.).\n\n### Conclusion\n\nNow you should be able to compile the libraries and run the sample code. This is only the beginning, however. I encourage you to read through the documentation found in the \".../clients/cs/docs\" directory of the client library.\nYou might also want to check out the [.NET Client Library Developer's Guide](/gdata/client-cs), the [project page](http://code.google.com/p/google-gdata/) and [reference guide](http://google-gdata.googlecode.com/svn/docs/Index.html), and the [Google Data .NET client library forum](http://groups.google.com/group/gdata-dotnet-client-library).\n\nTools referenced in this article:\n\n- [Mono Project](http://www.mono-project.com/Main_Page)\n- [Visual Studio](http://msdn2.microsoft.com/en-us/vstudio/default.aspx)\n- [Visual C# 2008 Express Edition](http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-02.aspx)\n- [NUnit](http://www.nunit.org/)\n\nGood luck on your next .NET application!"]]