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.
-
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 \ --experiments=enable_pdf,enable_images \ --improve-fidelity \ --intent=MICROSOFT_MODERNIZATION \ --optional-sections "files,classes"This command takes about 15 minutes to run.
-
Open the generated report with a web browser, such as Google Chrome.
To review how the output looks like, see the sample report:
modernization-report-sample/third_party/codmod-full-report-dotnet-mod.html.
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.
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 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. Set up your Google Cloud environment¶
Set your project ID and region as environment variables in your shell.
export PROJECT_ID="[YOUR_PROJECT_ID]"
export REGION="[YOUR_REGION]" # e.g., us-central1
gcloud config set project $PROJECT_ID
gcloud config set run/region $REGION
2. Enable necessary Google Cloud APIs¶
Enable the APIs for Artifact Registry, Cloud SQL, Cloud Build, and Cloud Run. This allows the services to work together.
gcloud services enable \
iam.googleapis.com \
artifactregistry.googleapis.com \
sqladmin.googleapis.com \
run.googleapis.com \
cloudbuild.googleapis.com
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 the instance is created, create a database for the application.
5. Build and push the container image¶
Use Google 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 .
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}" \
--set-env-vars "ConnectionStrings__SchoolContext=Host=/cloudsql/${INSTANCE_CONNECTION_NAME};Database=contosouniversity;Username=postgres;Password=${DB_PASSWORD}"
This command will prompt you to confirm the deployment. After it completes, it will output 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