Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Modernisasi kode untuk .NET, yang didukung oleh model AI Generatif Gemini, adalah alat pembuatan kode dan modernisasi aplikasi. Alat ini membantu Anda memodernisasi aplikasi Microsoft .NET Framework yang bergantung pada Windows dengan memfaktorkan ulang aplikasi Anda ke kode .NET lintas platform.
Aplikasi .NET lintas platform, tidak seperti aplikasi .NET Framework, dapat berjalan di Linux, sehingga tidak memerlukan lisensi Windows dan memungkinkan kemampuan cloud-native termasuk containerisasi.
Dalam panduan ini, Anda akan memberikan peran IAM untuk project Google Cloud, membuat bucket Cloud Storage, membuat kunci Gemini API, dan menginstal ekstensi code-modernization-for-dotnet di komputer lokal untuk memfaktorkan ulang aplikasi .NET Framework ke kode .NET lintas platform.
Sebelum memulai
Buat Akun Google, jika Anda belum memilikinya. Anda dapat menggunakan alamat email apa pun untuk membuat Akun Google, termasuk alamat email kantor Anda.
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Klik more_horizTampilan dan Tindakan Lainnya, lalu pilih Instal dari VSIX.
Buka dan pilih file paket VSIX. Tindakan ini akan memulai penginstalan
ekstensi Code-modernization-for-dotnet di VS Code di komputer
lokal Anda.
Setelah penginstalan selesai, mulai ulang VS Code.
Perbarui setelan Code Modernization for .NET extension menjadi berikut:
Mode Ekstensi: LocalGit (experimental)
ID Project: PROJECT_ID
Nama Bucket: BUCKET_NAME
Region: us-central1
Secret Gemini API: gemini-api-key-secret-name
Akun Google: GOOGLE_ACCOUNT
Target Framework: .NET 8.0
Ganti kode berikut:
PROJECT_ID: ID project Google Cloud
Anda—misalnya, 1234567890.
BUCKET_NAME: Nama bucket Cloud Storage Anda.
GOOGLE_ACCOUNT: Akun Google Anda—misalnya, your_full_name@gmail.com.
Picu build
Untuk login ke Google Cloud, jalankan perintah berikut:
gcloud auth login --update-adc
Untuk memicu alur kerja modernisasi, di panel aktivitas, pilih Source
Control, klik more_horizMore Actions
untuk membuka menu konteks, lalu pilih Google Cloud: Modernize .NET code.
Menambahkan project Anda ke daftar yang diizinkan
Untuk memasukkan project Anda ke daftar yang diizinkan, kirimkan ID Akun Layanan Cloud Build Anda melalui email ke code-modernization-for-dotnet-discuss@google.com.
Anda juga dapat menghubungi alamat email yang sama untuk mendapatkan dukungan, mengajukan pertanyaan, atau memberikan masukan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-09-05 UTC."],[],[],null,["# Modernize your .NET application\n\n\u003cbr /\u003e\n\nCode modernization for .NET, powered by Gemini Generative AI models, is\na code generation and application modernization tool. It helps you modernize\nyour Microsoft .NET Framework applications that are Windows-dependent by\nrefactoring your applications to cross-platform .NET code.\n\nCross-platform .NET applications, unlike .NET Framework applications, can run on Linux,\neliminating the need for Windows licenses and enabling cloud-native capabilities including containerization.\n\nIn this guide, you'll grant IAM roles for your Google Cloud\nproject, create a Cloud Storage bucket, create a Gemini API\nkey, and install the `code-modernization-for-dotnet` extension on your local\nmachine to re-factor your .NET Framework application to cross-platform .NET\ncode.\n\nBefore you begin\n----------------\n\n1. [Create a Google\n Account](https://support.google.com/accounts/answer/27441), if you don't already have one. You can use any email address to create a Google Account, including your work email address.\n2. Submit the [Code Modernization for\n .NET: Allowlist Request form](https://docs.google.com/forms/d/1KPLECo92gZ8Q36L1h6EyVpmKr_QieOl6QFROrLOBvd4/edit) to join the allow list. You can't proceed with the steps on this page until this request has been approved.\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Build, Secret Manager,\n Cloud Storage JSON API, Generative Language API, Cloud Logging,\n and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,secretmanager.googleapis.com,storage-api.googleapis.com,generativelanguage.googleapis.com,logging.googleapis.com,compute.googleapis.com)\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n-\n\n\n Enable the Cloud Build, Secret Manager,\n Cloud Storage JSON API, Generative Language API, Cloud Logging,\n and Compute Engine APIs.\n\n\n [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,secretmanager.googleapis.com,storage-api.googleapis.com,generativelanguage.googleapis.com,logging.googleapis.com,compute.googleapis.com)\n\n3. [Install VS Code](https://code.visualstudio.com/), if you haven't already.\n\nGrant Identity and Access Management (IAM) roles\n------------------------------------------------\n\n### Console\n\n1. To grant the IAM roles for your Google Cloud project,\n go to the **IAM \\& Admin** page.\n\n [Go to IAM \\& Admin](https://console.cloud.google.com/projectselector/iam-admin/iam?supportedpurview=)\n2. Add the following IAM roles:\n\n- **User Permissions**\n\n - Storage Object User (`roles/storage.objectUser`)\n - Cloud Build Editor (`roles/cloudbuild.builds.editor`)\n- **Cloud Build Service Account**\n\n - Cloud Build Service Account (`roles/cloudbuild.builds.builder`)\n - Secret Manager Viewer (`roles/secretmanager.viewer`)\n - Logs Writer (`roles/logging.logWriter`)\n - Storage Object User (`roles/storage.objectUser`)\n\n### gcloud\n\nTo add the required IAM roles, run the following `gcloud`\ncommands:\n\n- Assign the Storage Object User (`roles/storage.objectUser`) role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"user:\u003cvar translate=\"no\"\u003eUSER_ID\u003c/var\u003e\" \\\n --role=\"roles/storage.objectUser\"\n\n- Assign the Cloud Build Editor (`roles/cloudbuild.builds.editor`) role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"user:\u003cvar translate=\"no\"\u003eUSER_ID\u003c/var\u003e\" \\\n --role=\"roles/cloudbuild.builds.editor\"\n\n- Assign the Cloud Build Service Account (`roles/cloudbuild.builds.builder`)\n role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e\" \\\n --role=\"roles/cloudbuild.builds.builder\"\n\n- Assign the Secret Manager Accessor (`roles/secretmanager.secretAccessor`)\n role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e\" \\\n --role=\"roles/secretmanager.secretAccessor\"\n\n- Assign the Logs Writer (`roles/logging.logWriter`) role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e\" \\\n --role=\"roles/logging.logWriter\"\n\n- Assign the Storage Object User (`roles/storage.objectUser`) role:\n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\"serviceAccount:\u003cvar translate=\"no\"\u003eSERVICE_ACCOUNT\u003c/var\u003e\" \\\n --role=\"roles/storage.objectUser\"\n\nCreate a Cloud Storage bucket\n-----------------------------\n\nTo create a Cloud Storage bucket, run the following: \n\n gcloud storage buckets create gs://\u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n\nCreate Gemini API key and save in Secret Manager\n------------------------------------------------\n\nTo create a Gemini API key, run the following: \n\n gcloud services api-keys create --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --display-name=\"API Key for .Net Modernization\" \\\n --api-target=\"service=generativelanguage.googleapis.com\" \\\n --key-id=\"gemini-api-key\"\n\nTo save the Gemini API key in Secret Manager, run\nthe following: \n\n echo -n \"(gcloud services api-keys get-key-string gemini-api-key \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --format=\"value(keyString)\")\" | \\\n\n gcloud secrets create \"gemini-api-key\" \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --data-file=- \\\n --replication-policy=\"automatic\"\n\nInstall and configure the extension\n-----------------------------------\n\n| **Note:** After submitting the [Code Modernization for\n| .NET: Allowlist Request form](https://docs.google.com/forms/d/1KPLECo92gZ8Q36L1h6EyVpmKr_QieOl6QFROrLOBvd4/edit) to join the allow list, you'll need to wait for the request to be approved before proceeding with the steps in this section.\n\nOnce your [Code Modernization for\n.NET: Allowlist Request form](https://docs.google.com/forms/d/1KPLECo92gZ8Q36L1h6EyVpmKr_QieOl6QFROrLOBvd4/edit) is approved, you'll receive the extension as a\n`.VSIX` file. To install the extension to your local machine, follow these\nsteps:\n\n1. In VS Code, navigate to **Extensions** in the activity bar.\n\n2. Click more_horiz **Views and More\n Actions** and select **Install from VSIX**.\n\n3. Navigate to and select the VSIX package file. This initiates the installation\n of the `Code-modernization-for-dotnet` extension in VS Code on your local\n machine.\n\n4. Once the installation is complete, restart VS Code.\n\n5. Update `Code Modernization for .NET extension` settings to the following:\n\n - **Extension Mode** : `LocalGit (experimental)`\n - **Project ID** : \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n - **Bucket Name** : \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e\n - **Region** : `us-central1`\n - **Gemini API Secret** : `gemini-api-key-secret-name`\n - **Google Account** : \u003cvar translate=\"no\"\u003eGOOGLE_ACCOUNT\u003c/var\u003e\n - **Target Framework** : `.NET 8.0`\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The ID of your Google Cloud project---for example, `1234567890`.\n - \u003cvar translate=\"no\"\u003eBUCKET_NAME\u003c/var\u003e: The name of your Cloud Storage bucket.\n - \u003cvar translate=\"no\"\u003eGOOGLE_ACCOUNT\u003c/var\u003e: Your Google Account---for example, `your_full_name@gmail.com`.\n\nTrigger the build\n-----------------\n\n1. To login to Google Cloud, run the following command:\n\n gcloud auth login --update-adc\n\n2. To trigger the modernization workflow, in the activity bar, select **Source\n Control** , click more_horiz **More Actions**\n to open the context menu, and select **Google Cloud: Modernize .NET code**.\n\nAdd your project to the allow list\n----------------------------------\n\nTo get your project on the allow list, email your Cloud Build Service Account ID\nto `code-modernization-for-dotnet-discuss@google.com`.\n\nYou can also contact the same email address for support, to ask questions, or to\nprovide feedback."]]