Gemini-powered .NET modernization¶
In this demo, you modernize a .NET Framework application to a Linux-ready .NET application.
This demo guide walks you through the following steps:
- Prepare the environment
- Generate a modernization assessment
- Modernize the application
- Generate deployment descriptors
- Deploy on Google Cloud
Requirements¶
To deploy this demo, you need:
- A Google Cloud project.
- An account that has the
ownerrole on that Google Cloud project. - The gcloud CLI
- Gemini CLI
- The codmod CLI
- Docker Engine (to test locally on
your host). This guide assumes that you can
manage Docker as a non-root user,
so you can run Docker commands without
sudo. - Chrome DevTools MCP
Prepare the environment¶
-
Open Cloud Shell.
-
Set up your Google Cloud environment:
-
Install the codmod CLI
-
Install the Chrome DevTools MCP in Gemini CLI:
For more information, see the Chrome DevTools MCP README:
-
Clone the repository and set the working directory:
Run the Migration Center App Modernization Assessment¶
To generate a Migration Center App Modernization Assessment report, you do the following:
-
Set the working directory:
-
Generate the report:
codmod create full \ --codebase ./dotnet-migration-sample \ --output-path ./codmod-full-report-dotnet-mod.html \ --project "${PROJECT_ID}" \ --region "${REGION}" \ --improve-fidelity \ --intent=MICROSOFT_MODERNIZATION \ --optional-sections "files,classes"This command takes about 15 minutes to run.
If you get
codmod: command not found, add the executable to yourPATH, for example by runningsudo mv codmod /usr/local/bin/. Alternatively, create an alias:alias codmod=./codmod. -
Open the generated report with a web browser, such as Google Chrome.
Modernize the .NET application using Gemini CLI¶
-
Change the working directory to the .NET application directory:
-
Run Gemini CLI:
-
Copy the prompt defined in
modernization-prompt.md, and paste the prompt in the Gemini CLI user interface, and press the Enter key.To complete the execution, Gemini CLI takes about 25 minutes.
-
After execution completes, exit Gemini CLI by entering
/quitor by pressingCTRL+Ctwice.
Sample modernized application¶
The dotnet-migration-sample-modernized directory contains an example of the
modernized .NET application resulting in running Gemini CLI with the above
prompt.
To run the example modernized application locally, you do the following:
-
Change the working directory to the .NET application directory:
-
Run the application using Docker Compose:
-
Wait for the application to accept connections. When the application is ready to accept connections, the output is similar to the following:
-
Open
http://localhost:8080/with a web browser, such as Google Chrome. -
Navigate the application using the web browser.
After completing your test, stop the application by sending the CTRL+C key
combination.
Deploy the application to Google Cloud¶
To deploy the example modernized application to Google Cloud using Cloud Run, Artifact Registry, and Cloud SQL for PostgreSQL, follow the guidance in this section.
You can follow similar steps to deploy your own modernized .NET application.
1. Enable necessary Google Cloud APIs¶
Enable the APIs that this demo requires: Identity and Access Management (IAM), Artifact Registry, Cloud SQL Admin, Cloud Run, Cloud Build, Vertex AI, and Cloud Resource Manager.
gcloud services enable \
iam.googleapis.com \
artifactregistry.googleapis.com \
sqladmin.googleapis.com \
run.googleapis.com \
cloudbuild.googleapis.com \
aiplatform.googleapis.com \
cloudresourcemanager.googleapis.com
2. Create and configure a dedicated service account¶
-
Create the service account:
-
Grant the necessary roles to the service account:
# For Cloud Run to connect to Cloud SQL gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:${SA_EMAIL}" \ --role="roles/cloudsql.client" # For Cloud Build to write logs gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:${SA_EMAIL}" \ --role="roles/logging.logWriter" # For Cloud Build to push images to Artifact Registry gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:${SA_EMAIL}" \ --role="roles/artifactregistry.writer" # For Cloud Build to manage storage buckets for artifacts gcloud projects add-iam-policy-binding $PROJECT_ID \ --member="serviceAccount:${SA_EMAIL}" \ --role="roles/storage.admin"
3. Create an Artifact Registry repository¶
Create a Docker repository in Artifact Registry to store the container images for your application.
export REPO_NAME="contoso-university-repo"
gcloud artifacts repositories create $REPO_NAME \
--repository-format=docker \
--location=$REGION \
--description="Docker repository for Contoso University"
4. Create a Cloud SQL for PostgreSQL instance¶
Create a PostgreSQL instance to host the application's database. This may take a few minutes.
export INSTANCE_NAME="contoso-university-db"
export DB_PASSWORD="[YOUR_DB_PASSWORD]" # Choose a strong password
gcloud sql instances create $INSTANCE_NAME \
--database-version=POSTGRES_13 \
--tier=db-g1-small \
--region=$REGION \
--root-password=$DB_PASSWORD
After Cloud SQL creates the instance, create a database for the application.
5. Build and push the container image¶
Use Cloud Build to build your container image and push it to the Artifact
Registry repository you created. Cloud Build uses the Dockerfile in your
project root.
cd "$(git rev-parse --show-toplevel)/projects/dotnet-modernization-demo/dotnet-migration-sample-modernized"
gcloud builds submit \
--tag $REGION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/contoso-university:latest \
--service-account="projects/${PROJECT_ID}/serviceAccounts/${SA_EMAIL}" \
--default-buckets-behavior=regional-user-owned-bucket .
6. Deploy the application to Cloud Run¶
Deploy the container image from Artifact Registry to Cloud Run. This command creates a new Cloud Run service and connects it to your Cloud SQL instance.
First, get your Cloud SQL instance connection name:
export INSTANCE_CONNECTION_NAME=$(gcloud sql instances describe $INSTANCE_NAME --format='value(connectionName)')
Now, deploy the service to Cloud Run:
gcloud run deploy contoso-university \
--image=$REGION-docker.pkg.dev/$PROJECT_ID/$REPO_NAME/contoso-university:latest \
--platform managed \
--allow-unauthenticated \
--add-cloudsql-instances=$INSTANCE_CONNECTION_NAME \
--region "${REGION}" \
--no-invoker-iam-check \
--service-account="${SA_EMAIL}" \
--set-env-vars "ConnectionStrings__SchoolContext=Host=/cloudsql/${INSTANCE_CONNECTION_NAME};Database=contosouniversity;Username=postgres;Password=${DB_PASSWORD}"
The command prompts you to confirm the deployment. After the deployment completes, the command outputs the URL for your deployed service.
7. Test the application¶
Once the deployment is complete, you can test the application:
- Copy the URL provided in the output of the
gcloud run deploycommand. - Open the URL in a web browser.
-
You should see the Contoso University application homepage. You can navigate through the site to view students, courses, instructors, and departments. The application is now running live on Cloud Run and connected to your Cloud SQL database.
-
Optionally, you can go back to the Gemini CLI and ask it to run the automated UI tests again, this time against the deployed application's URL.
Clean up your Google Cloud environment¶
To avoid incurring unwanted charges, follow these steps to remove all the resources provisioned for this demo.
-
Delete the Cloud Run service
-
Delete the Artifact Registry repository
-
Delete the Cloud SQL for PostgreSQL instance
-
Delete the custom service account