Tidy up - Unused Project and Nuget package reference using Visual Studio 2019

If you are a Developer/Architect using Visual Studio as IDE for your development activities, this blog post will be of your interest. During the Ignite 2021 conference, Microsoft released Visual Studio 2019 v16.9 and v16.10 Preview 1. As part of version 16.10 Preview 1, one of the cool features they introduced is to "Remove Unused References..." for any Projects and Nuget packages that are not in use. At the time of writing this blog post, we have Visual Studio Version 16.10.0 (official release) which includes this new feature.  As part of development, we generally get carried away and introduce new Nuget package references to your project and add new references to your Projects. By the end of development, you will not be 100% sure which are not being referenced and unused which means you will leave those unused project references in your application. Now you might be wondering what's the big deal in it since it doesn't harm. The advantage of removing unused project r

Troubleshooting - Issue in deleting a network profile associated to ACI

Recently I tried deleting a resource group (RG) having Azure Container Instance (ACI) resources which was secured using VNet. I couldn’t get RG deleted completely due to an error related to VNet delete (internally its associated to Network Profile). Then I googled a bit and found this is a common issue where most of the people reported in different forums like GitHub, Stack-overflow etc.

In this blog post I will be covering what is the option to resolve the above issue. Firstly, let me show what is the error you will be seeing in the above scenario.

Subnet raju-subnet-web-dev is in use by 
/subscriptions/XXXSubscriptionIdXXX/resourceGroups/raju-rg-dev/providers/Microsoft.Network/
networkProfiles/aci-network-profile-raju-vnet-dev-subnet-web-dev/
containerNetworkInterfaceConfigurations/eth0/ipConfigurations/ipconfigprofile 
and cannot be deleted.In order to delete the subnet, delete all the resources within the subnet. 
See aka.ms/deletesubnet.

With Error Code: InUseSubnetCannotBeDeleted

Operation name : Delete Virtual Network

At First instance I followed the Microsoft documentation which is mentioned here but no luck. Script that worked for me is documented below. Root cause for the above error message is after deleting the container group, Network profile is still left over which is associated to VNet. Until Network profile is not deleted it doesn't allow VNet to be removed which in-turns holds your resource group from deleting.

# Replace <your resource group> with the name of your resource group
RES_GROUP=<your resource group>

# Replace <vnet_name> with the name of your VNet name
VNET_NAME=<vnet_name>

# Replace <subnet_name> with the name of your subnet name
SUBNET_NAME=<subnet_name>

# Get network profile ID
NETWORK_PROFILE_ID=$(az network profile list --resource-group $RES_GROUP --query [0].id --output tsv)

Now update the containerNetworkInterfaceConfigurations property in Network profile properties to an empty list (Work around option)

#Update containerNetworkInterfaceConfigurations 
az resource update --ids $NETWORK_PROFILE_ID --set properties.containerNetworkInterfaceConfigurations=[]

# Delete the network profile
az network profile delete --id $NETWORK_PROFILE_ID -y
 
# Delete the subnet
az network vnet subnet delete --resource-group $RES_GROUP --vnet-name $VNET_NAME --name $SUBNET_NAME

# Delete virtual network
az network vnet delete --resource-group $RES_GROUP --name $VNET_NAME

Finally, now you can go ahead and delete your required resource group which was held due to network profile.

References

 


Comments

Popular posts from this blog

Tidy up - Unused Project and Nuget package reference using Visual Studio 2019

Swagger UI for Azure Function v2 & v3 APIs

Authenticate Azure Functions - API Keys