Code modernization for .NET, powered by Gemini Generative AI models, is a code generation and application modernization tool. It helps you modernize your Microsoft .NET Framework applications that are Windows-dependent by refactoring your applications to cross-platform .NET code.
Cross-platform .NET applications, unlike .NET Framework applications, can run on Linux, eliminating the need for Windows licenses and enabling cloud-native capabilities including containerization.
In this guide, you'll grant IAM roles for your Google Cloud
project, create a Cloud Storage bucket, create a Gemini API
key, and install the code-modernization-for-dotnet
extension on your local
machine to re-factor your .NET Framework application to cross-platform .NET
code.
Before you begin
- Create a Google Account, if you don't already have one. You can use any email address to create a Google Account, including your work email address.
- Submit the Code Modernization for .NET: Allowlist Request form to join the allow list. You can't proceed with the steps on this page until this request has been approved.
- 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.
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. -
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
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
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 Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin
), which contains theserviceusage.services.enable
permission. Learn how to grant roles. - Install VS Code, if you haven't already.
Grant Identity and Access Management (IAM) roles
Console
To grant the IAM roles for your Google Cloud project, go to the IAM & Admin page.
Add the following IAM roles:
User Permissions
- Storage Object User (
roles/storage.objectUser
) - Cloud Build Editor (
roles/cloudbuild.builds.editor
)
- Storage Object User (
Cloud Build Service Account
- Cloud Build Service Account (
roles/cloudbuild.builds.builder
) - Secret Manager Viewer (
roles/secretmanager.viewer
) - Logs Writer (
roles/logging.logWriter
) - Storage Object User (
roles/storage.objectUser
)
- Cloud Build Service Account (
gcloud
To add the required IAM roles, run the following gcloud
commands:
Assign the Storage Object User (
roles/storage.objectUser
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="user:USER_ID" \ --role="roles/storage.objectUser"
Assign the Cloud Build Editor (
roles/cloudbuild.builds.editor
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="user:USER_ID" \ --role="roles/cloudbuild.builds.editor"
Assign the Cloud Build Service Account (
roles/cloudbuild.builds.builder
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="roles/cloudbuild.builds.builder"
Assign the Secret Manager Accessor (
roles/secretmanager.secretAccessor
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="roles/secretmanager.secretAccessor"
Assign the Logs Writer (
roles/logging.logWriter
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="roles/logging.logWriter"
Assign the Storage Object User (
roles/storage.objectUser
) role:gcloud projects add-iam-policy-binding PROJECT_ID \ --member="serviceAccount:SERVICE_ACCOUNT" \ --role="roles/storage.objectUser"
Create a Cloud Storage bucket
To create a Cloud Storage bucket, run the following:
gcloud storage buckets create gs://BUCKET_NAME \
--project=PROJECT_ID
Create Gemini API key and save in Secret Manager
To create a Gemini API key, run the following:
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"
To save the Gemini API key in Secret Manager, run the following:
echo -n "(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"
Install and configure the extension
Once your Code Modernization for
.NET: Allowlist Request form is approved, you'll receive the extension as a
.VSIX
file. To install the extension to your local machine, follow these
steps:
In VS Code, navigate to Extensions in the activity bar.
Click more_horiz Views and More Actions and select Install from VSIX.
Navigate to and select the VSIX package file. This initiates the installation of the
Code-modernization-for-dotnet
extension in VS Code on your local machine.Once the installation is complete, restart VS Code.
Update
Code Modernization for .NET extension
settings to the following:- Extension Mode:
LocalGit (experimental)
- Project ID:
PROJECT_ID
- Bucket Name:
BUCKET_NAME
- Region:
us-central1
- Gemini API Secret:
gemini-api-key-secret-name
- Google Account:
GOOGLE_ACCOUNT
- Target Framework:
.NET 8.0
Replace the following:
PROJECT_ID
: The ID of your Google Cloud project—for example,1234567890
.BUCKET_NAME
: The name of your Cloud Storage bucket.GOOGLE_ACCOUNT
: Your Google Account—for example,your_full_name@gmail.com
.
- Extension Mode:
Trigger the build
To login to Google Cloud, run the following command:
gcloud auth login --update-adc
To trigger the modernization workflow, in the activity bar, select Source Control, click more_horiz More Actions to open the context menu, and select Google Cloud: Modernize .NET code.
Add your project to the allow list
To get your project on the allow list, email your Cloud Build Service Account ID
to code-modernization-for-dotnet-discuss@google.com
.
You can also contact the same email address for support, to ask questions, or to
provide feedback.