Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
A modernização de código para .NET, com tecnologia dos modelos de IA generativa do Gemini, é uma ferramenta de geração de código e modernização de aplicativos. Ele ajuda a modernizar
seus aplicativos do Microsoft .NET Framework dependentes do Windows
refatorando os aplicativos para código .NET multiplataforma.
Os aplicativos .NET multiplataforma, ao contrário dos aplicativos .NET Framework, podem ser executados no Linux, eliminando a necessidade de licenças do Windows e ativando recursos nativos da nuvem, incluindo a conteinerização.
Neste guia, você vai conceder papéis do IAM ao seu projeto Google Cloud, criar um bucket do Cloud Storage, criar uma chave da API Gemini e instalar a extensão code-modernization-for-dotnet na sua máquina local para refatorar o aplicativo .NET Framework em código .NET multiplataforma.
Antes de começar
Crie uma Conta do Google, caso ainda não tenha uma. É possível usar qualquer endereço de e-mail para
criar uma Conta do Google, incluindo seu endereço de e-mail do trabalho.
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.
No VS Code, navegue até Extensões na barra de atividades.
Clique em more_horizVisualizações e mais
ações e selecione Instalar pelo VSIX.
Navegue até o arquivo de pacote VSIX e selecione-o. Isso inicia a instalação
da extensão Code-modernization-for-dotnet no VS Code na sua máquina
local.
Quando a instalação for concluída, reinicie o VS Code.
Atualize as configurações de Code Modernization for .NET extension para:
Modo de extensão: LocalGit (experimental)
Project ID: PROJECT_ID
Nome do bucket: BUCKET_NAME
Região: us-central1
API Secret do Gemini: gemini-api-key-secret-name
Conta do Google: GOOGLE_ACCOUNT
Framework de destino: .NET 8.0
Substitua:
PROJECT_ID: o ID do seu projeto Google Cloud, por exemplo, 1234567890.
BUCKET_NAME: o nome do bucket do Cloud Storage.
GOOGLE_ACCOUNT: sua Conta do Google, por exemplo, your_full_name@gmail.com.
Acionar a compilação
Para fazer login no Google Cloud, execute o seguinte comando:
gcloud auth login --update-adc
Para acionar o fluxo de trabalho de modernização, na barra de atividades, selecione Controle
de origem, clique em more_horizMais ações
para abrir o menu de contexto e selecione Google Cloud: modernizar o código .NET.
Adicionar seu projeto à lista de permissões
Para incluir seu projeto na lista de permissões, envie por e-mail o ID da conta de serviço do Cloud Build para code-modernization-for-dotnet-discuss@google.com.
Você também pode entrar em contato com o mesmo endereço de e-mail para receber suporte, fazer perguntas ou enviar feedback.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 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."]]