תחילת העבודה עם ספריית הלקוח של .NET
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
ג'ף פישר, צוות Google Data APIs
אוגוסט 2007
מבוא
איור 1: פתרון Google Data API
עבור מפתחים רבים, החלק הקשה ביותר בפרויקט חדש הוא להתחיל אותו – להתקין חבילות תוכנה חדשות, להגדיר סביבת פיתוח וללמוד ספריות חדשות. במאמר הזה ריכזתי כמה הוראות מפורטות שיעזרו לכם להתחיל להשתמש בספריית הלקוח של .NET באמצעות Visual Studio 2005 ל-Windows או Mono ל-Linux ולמערכות הפעלה אחרות של Unix. אני מקווה שההסבר הזה יחסוך לך זמן בתחילת העבודה, ותוכל להתחיל לעבוד עם קוד במהירות.
Visual Studio 2008
אם עדיין לא התקנתם את Visual Studio 2008, כדאי לשקול להשתמש ב-Visual C# 2008 Express Edition, גרסה חינמית של Visual Studio שתאפשר לכם לעבוד עם ספריית הלקוח של .NET.
הגדרת הסביבה
- מורידים את הגרסה האחרונה של MSI של ספריית הלקוח מהכתובת http://code.google.com/p/google-gdata/downloads/list.
- מריצים את קובץ ה-MSI שהורד כדי להתקין את החבילה. ההתקנה תתבצע בנתיב C:\Program Files\Google\Google Data API SDK\ כברירת מחדל. בדוגמאות נוספות במאמר הזה נניח שהתקנתם את ספריית הלקוח במיקום הזה.
- פותחים את קובץ הפתרון שנקרא Google Data API SDK בתיקייה Google Data API SDK בתפריט התחלה.
קומפילציה והרצה של דוגמאות
- מוודאים שהפעלת האפשרות Build > Build Solution (בנייה > בניית פתרון) מסתיימת ללא שגיאות.
- כדי ליצור גרסת Debug, עוברים אל 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.
- בתפריט 'פרויקט', בוחרים באפשרות 'הוספת הפניה'.
- לוחצים על הכרטיסייה 'עיון'.
- עוברים לספרייה Redist ב-SDK: C:\Program Files\Google\Google Data API SDK\Redist.
- בוחרים את קובצי ה-DLL שבהם הקוד ישתמש. ברוב הפרויקטים תצטרכו את הקבצים Google.GData.Extensions.dll ו-Google.GData.Client.dll, וגם את קובץ ה-DLL שספציפי לשירותי Google שבהם אתם משתמשים באפליקציה.
הערה: יש גם קובץ פתרון לספריות לקוח במכשירים ניידים. כברירת מחדל, הוא נמצא בנתיב C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005.mobile. הפתרון הזה יקמפל רק את קובצי ה-DLL של ספריות הלקוח.
הרצת בדיקות NUnit
אם מבצעים שינויים בספריות הלקוח או מתכננים לתרום להן, חשוב לוודא שהבדיקות המתאימות של NUnit עוברות. אם אתם מתכננים להשתמש בספריות הלקוח בלי לבצע בהן שינויים, בדרך כלל אין צורך להפעיל אותן.
- מורידים את קובץ ה-MSI של NUnit בגרסה .NET 2.0 מכתובת http://www.nunit.org/index.php?p=download.
- מריצים את קובץ ה-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 בחלונית Solution Explorer (סייר הפתרונות) בצד שמאל ובוחרים באפשרות Properties (מאפיינים). עכשיו לוחצים על הכרטיסייה Reference Paths (נתיבי הפניה) בחלון שנפתח. מזינים את המיקום של ספריית המשנה bin בהתקנה של NUnit כנתיב הפניה ולוחצים על Add Folder (הוספת תיקייה). לדוגמה, אם NUnit מותקן בנתיב C:\Program Files\NUnit\, צריך להזין C:\Program Files\NUnit\bin. חשוב לשמור את השינוי הזה לפני שממשיכים.
- פועלים לפי השלבים שמפורטים במאמר קומפילציה והרצה של דוגמאות כדי לבנות מחדש את ספריית הלקוח ואת בדיקות היחידות.
- מעתיקים את הקובץ unittests.dll.config בתיקייה C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\ אל ספריית ה-build של ניפוי הבאגים C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\. חשוב לערוך את הקובץ כדי לכלול בו את המידע המתאים לבדיקות שאתם מריצים. לדוגמה, כדי להשתמש ב-Base נדרש מפתח API, וכדי להשתמש ביומן נדרשים שם משתמש וסיסמה. מומלץ להשתמש בחשבון בדיקה ללא נתונים פעילים, כדי למנוע מחיקה של מידע על ידי בדיקות היחידה.
- פותחים את NUnit מתפריט ההתחלה.
- עוברים אל 'קובץ > פתיחת פרויקט' ובוחרים את הקובץ 'unittests.dll' מתוך 'C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\'.
- מריצים את בדיקות היחידה שמעניינות אתכם. חשוב לזכור שבשביל להריץ בדיקות מסוימות צריך להגדיר פרמטרים בקובץ unittests.dll.config. אם מריצים בדיקות עומס בשירותים מסוימים, יכול להיות שחשבון הבדיקה יסומן כחשבון שמייצר ספאם, ולא תהיה אפשרות לשלוח תוכן לשרתים של Google באופן פרוגרמטי בלי להיתקל באתגרי CAPTCHA.
מונו
Mono הוא פרויקט קוד פתוח שמאפשר להריץ אפליקציות לקוח ושרת של .NET ב-Linux, ב-Solaris, ב-Mac OS X, ב-Windows וב-Unix. אנחנו מציעים קובץ ZIP נפרד של ספריית הלקוח שלנו למפתחים שרוצים לעבוד באחת מהפלטפורמות האלה.
הגדרת הסביבה
- מורידים את קובץ ה-ZIP העדכני של ספריית הלקוח מכתובת http://code.google.com/p/google-gdata/downloads/list
- חילוץ לספרייה מקומית (לדוגמה, /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.
- עורכים את קובץ ה-Makefile בהתאם לגרסת .NET שבה רוצים להשתמש. ב- .NET 1.x, משתמשים ב-
CSC=mcs
, וב- .NET 2.x, משתמשים ב-CSC=gmcs
.
- מריצים את הפקודה
make
כדי לקמפל את הספריות ואת אפליקציות הדוגמה.
- מריצים את
make install
אם רוצים להתקין את קובצי ה-DLL של ספריית הלקוח בספריית Mono.
פיתוח אפליקציה משלכם
אם הפעלתם את הפקודה 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, וכדי להשתמש ביומן נדרשים שם משתמש וסיסמה. מומלץ להשתמש בחשבון בדיקה ללא נתונים פעילים כדי למנוע מחיקה של מידע על ידי בדיקות היחידה.
- אחרי הידור הספרייה, ייווצר קובץ unittests.dll בנתיב /scratch/gdata.NET/clients/cs. אפשר להשתמש ב-DLL הזה עם מנהל הבדיקות של NUnit לפי בחירתכם (nunit-console, gnunit וכו').
סיכום
עכשיו אמורה להיות לכם אפשרות לקמפל את הספריות ולהריץ את הקוד לדוגמה. אבל זו רק ההתחלה. מומלץ לקרוא את המסמכים בספריית הלקוח '.../clients/cs/docs'.
כדאי גם לעיין במדריך למפתחים של ספריית הלקוח של .NET, בדף הפרויקט ובמדריך העזר, וכן בפורום של ספריית הלקוח של Google Data ל- .NET.
כלים שמוזכרים במאמר הזה:
בהצלחה עם אפליקציית .NET הבאה שלך!
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-07-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-07-27 (שעון UTC)."],[[["\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!"]]