מודרניזציה של אפליקציית ‎ .NET

Code modernization for .NET, powered by Gemini Generative AI models, is a code generation and application modernization tool. הוא עוזר לכם לעשות מודרניזציה לאפליקציות של Microsoft .NET Framework שתלויות ב-Windows, על ידי ארגון הקוד מחדש של האפליקציות לקוד .NET בפלטפורמות שונות.

אפליקציות .NET חוצות פלטפורמות, בניגוד לאפליקציות .NET Framework, יכולות לפעול ב-Linux, ולכן אין צורך ברישיונות ל-Windows. בנוסף, הן מאפשרות יכולות מובנות בענן, כולל יצירת קונטיינרים.

במדריך הזה נסביר איך להקצות תפקידי IAM לפרויקט Google Cloud, ליצור קטגוריה של Cloud Storage, ליצור מפתח Gemini API ולהתקין את התוסף code-modernization-for-dotnet במחשב המקומי כדי לשכתב את אפליקציית .NET Framework לקוד .NET בפלטפורמות שונות.

לפני שמתחילים

  1. יוצרים חשבון Google, אם עדיין אין לכם חשבון. אתם יכולים להשתמש בכל כתובת אימייל כדי ליצור חשבון Google, כולל כתובת האימייל שלכם בעבודה.
  2. כדי להצטרף לרשימת ההיתרים, שולחים את הטופס Code Modernization for .NET: Allowlist Request. אי אפשר להמשיך לשלבים בדף הזה עד שהבקשה תאושר.
  3. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. Enable the Cloud Build, Secret Manager, Cloud Storage JSON API, Generative Language API, Cloud Logging, and Compute Engine APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  8. Verify that billing is enabled for your Google Cloud project.

  9. Enable the Cloud Build, Secret Manager, Cloud Storage JSON API, Generative Language API, Cloud Logging, and Compute Engine APIs.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  10. מתקינים את VS Code, אם עוד לא עשיתם זאת.

מתן תפקידים בניהול זהויות והרשאות גישה (IAM)

המסוף

  1. כדי להקצות את תפקידי ה-IAM בפרויקט Google Cloud , עוברים לדף IAM & Admin.

    כניסה לדף IAM & Admin

  2. מוסיפים את תפקידי ה-IAM הבאים:

  • הרשאות משתמשים

    • משתמש באובייקטים באחסון (roles/storage.objectUser)
    • עריכה ב-Cloud Build (roles/cloudbuild.builds.editor)
  • חשבון שירות של Cloud Build

    • חשבון שירות של Cloud Build‏ (roles/cloudbuild.builds.builder)
    • משתמש עם גישת קריאה ל-Secret Manager‏ (roles/secretmanager.secretAccessor)
    • כתיבת יומנים (roles/logging.logWriter)
    • משתמש באובייקטים באחסון (roles/storage.objectUser)

gcloud

כדי להוסיף את תפקידי ה-IAM הנדרשים, מריצים את הפקודות הבאות של gcloud:

  • מקצים את התפקיד Storage Object User (משתמש באובייקטים באחסון) (roles/storage.objectUser):

    gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_ID" \
    --role="roles/storage.objectUser"
    
  • מקצים את התפקיד 'עריכה ב-Cloud Build' (roles/cloudbuild.builds.editor):

    gcloud projects add-iam-policy-binding PROJECT_ID \
    --member="user:USER_ID" \
    --role="roles/cloudbuild.builds.editor"
    
  • מקצים את התפקיד 'חשבון שירות של Cloud Build' (roles/cloudbuild.builds.builder):

    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT" \
      --role="roles/cloudbuild.builds.builder"
    
  • הקצאת התפקיד Secret Manager Accessor (roles/secretmanager.secretAccessor):

    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT" \
      --role="roles/secretmanager.secretAccessor"
    
  • הקצאת התפקיד Logs Writer (roles/logging.logWriter):

    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT" \
      --role="roles/logging.logWriter"
    
  • מקצים את התפקיד Storage Object User (משתמש באובייקטים באחסון) (roles/storage.objectUser):

    gcloud projects add-iam-policy-binding PROJECT_ID \
      --member="serviceAccount:SERVICE_ACCOUNT" \
      --role="roles/storage.objectUser"
    

יצירת קטגוריה של Cloud Storage

כדי ליצור קטגוריה של Cloud Storage, מריצים את הפקודה הבאה:

gcloud storage buckets create gs://BUCKET_NAME \
--project=PROJECT_ID

יצירת מפתח Gemini API ושמירה ב-Secret Manager

כדי ליצור מפתח Gemini API, מריצים את הפקודה הבאה:

gcloud services api-keys create --project=PROJECT_ID \
  --display-name="API Key for .Net Modernization" \
  --api-target="service=generativelanguage.googleapis.com" \
  --key-id="gemini-api-key"

כדי לשמור את מפתח Gemini API ב-Secret Manager, מריצים את הפקודה הבאה:

gcloud services api-keys get-key-string gemini-api-key \
--project=PROJECT_ID \
--format="value(keyString)" | \

gcloud secrets create "gemini-api-key" \
--project=PROJECT_ID \
--data-file=- \
--replication-policy="automatic"

התקנה והגדרה של התוסף

אחרי שהבקשה שלכם באמצעות טופס הבקשה להוספה לרשימת ההיתרים של Code Modernization for .NET תאושר, תקבלו את התוסף כקובץ .VSIX. כדי להתקין את התוסף במחשב המקומי, פועלים לפי השלבים הבאים:

  1. ב-VS Code, עוברים אל Extensions (תוספים) בסרגל הפעילות.

  2. לוחצים על more_horiz Views and More Actions (תצוגות ועוד פעולות) ובוחרים באפשרות Install from VSIX (התקנה מ-VSIX).

  3. מנווטים אל קובץ חבילת ה-VSIX ובוחרים בו. הפעולה הזו תתחיל את ההתקנה של התוסף Code-modernization-for-dotnet ב-VS Code במחשב המקומי.

  4. אחרי שההתקנה מסתיימת, מפעילים מחדש את VS Code.

  5. מעדכנים את ההגדרות של Code Modernization for .NET extension לערכים הבאים:

    • מצב הרחבה: Version 2
    • מזהה הפרויקט: PROJECT_ID
    • שם הקטגוריה: BUCKET_NAME
    • אזור: us-central1
    • Gemini API Secret: gemini-api-key
    • חשבון Google: GOOGLE_ACCOUNT
    • Target Framework: .NET 8.0

    מחליפים את מה שכתוב בשדות הבאים:

    • PROJECT_ID: מזהה הפרויקט ב- Google Cloud. לדוגמה: 1234567890.
    • BUCKET_NAME: השם של קטגוריית Cloud Storage.
    • GOOGLE_ACCOUNT: חשבון Google שלכם. לדוגמה: your_full_name@gmail.com.

הפעלת build

  1. כדי להתחבר אל Google Cloud, מריצים את הפקודה הבאה:

    gcloud auth login --update-adc
    
  2. כדי להפעיל את תהליך העבודה של המודרניזציה, בסרגל הפעילות בוחרים באפשרות Source Control (בקרת מקור), לוחצים על more_horiz More Actions (פעולות נוספות) כדי לפתוח את תפריט ההקשר, ובוחרים באפשרות Google Cloud: Modernize .NET code (Google Cloud: מודרניזציה של קוד ‎.NET).

הוספת הפרויקט לרשימת ההיתרים

כדי להוסיף את הפרויקט לרשימת ההיתרים, שולחים את מזהה חשבון השירות ב-Cloud Build לכתובת code-modernization-for-dotnet-discuss@google.com.

אפשר גם לפנות לאותה כתובת אימייל כדי לקבל תמיכה, לשאול שאלות או לשלוח משוב.