|
| 1 | +--- |
| 2 | +title: Remove Application Insights in Visual Studio - Azure Monitor |
| 3 | +description: How to remove Application Insights SDK for ASP.NET and ASP.NET Core in Visual Studio. |
| 4 | +ms.topic: conceptual |
| 5 | +ms.date: 04/06/2020 |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +# How to remove Application Insights in Visual Studio |
| 10 | + |
| 11 | +This article will show you how to remove the ASP.NET and ASP.NET Core Application Insights SDK in Visual Studio. |
| 12 | + |
| 13 | +To remove Application Insights, you'll need to remove the NuGet packages and references from the API in your application. You can uninstall NuGet packages by using the Package Management Console or Manage NuGet Solution in Visual Studio. The following sections will show two ways to remove NuGet Packages and what was automatically added in your project. Be sure to confirm the files added and areas with in your own code in which you made calls to the API are removed. |
| 14 | + |
| 15 | +## Uninstall using the Package Management Console |
| 16 | + |
| 17 | +# [.NET](#tab/net) |
| 18 | + |
| 19 | +1. To open the Package Management Console, in the top menu select Tools > NuGet Package Manager > Package Manager Console. |
| 20 | + |
| 21 | +  |
| 22 | + |
| 23 | + > [!NOTE] |
| 24 | + > If trace collection is enabled you need to first uninstall Microsoft.ApplicationInsights.TraceListener. Enter `Uninstall-package Microsoft.ApplicationInsights.TraceListener` then follow the step below to remove Microsoft.ApplicationInsights.Web. |
| 25 | +
|
| 26 | +1. Enter the following command: `Uninstall-Package Microsoft.ApplicationInsights.Web -RemoveDependencies` |
| 27 | + |
| 28 | + After entering the command, the Application Insights package and all of its dependencies will be uninstalled from the project. |
| 29 | + |
| 30 | +  |
| 31 | + |
| 32 | +# [.NET Core](#tab/netcore) |
| 33 | + |
| 34 | +1. To open the Package Management Console, in the top menu select Tools > NuGet Package Manager > Package Manager Console. |
| 35 | + |
| 36 | +  |
| 37 | + |
| 38 | +1. Enter the following command: ` Uninstall-Package Microsoft.ApplicationInsights.AspNetCore -RemoveDependencies` |
| 39 | + |
| 40 | + After entering the command, the Application Insights package and all of its dependencies will be uninstalled from the project. |
| 41 | + |
| 42 | +--- |
| 43 | + |
| 44 | +## Uninstall using the Visual Studio NuGet UI |
| 45 | + |
| 46 | +# [.NET](#tab/net) |
| 47 | + |
| 48 | +1. In the *Solution Explorer* on the right, right click on **Solution** and select **Manage NuGet Packages for Solution**. |
| 49 | + |
| 50 | + You'll then see a screen that allows you to edit all the NuGet packages that are part of the project. |
| 51 | + |
| 52 | +  |
| 53 | + |
| 54 | + > [!NOTE] |
| 55 | + > If trace collection is enabled you need to first uninstall Microsoft.ApplicationInsights.TraceListener without remove dependencies selected and then follow the steps below to uninstall Microsoft.ApplicationInsights.Web with remove dependencies selected. |
| 56 | + |
| 57 | +1. Click on the "Microsoft.ApplicationInsights.Web" package. On the right, check the checkbox next to *Project* to select all projects. |
| 58 | + |
| 59 | +1. To remove all dependencies when uninstalling, select the **Options** dropdown button below the section where you selected project. |
| 60 | + |
| 61 | + Under *Uninstall Options*, select the checkbox next to *Remove dependencies*. |
| 62 | + |
| 63 | +1. Select **Uninstall**. |
| 64 | + |
| 65 | +  |
| 66 | + |
| 67 | + A dialog box will display that shows all of the dependencies to be removed from the application. Select **ok** to uninstall. |
| 68 | + |
| 69 | +  |
| 70 | + |
| 71 | +1. After everything is uninstalled, you may still see "ApplicationInsights.config" and "AiHandleErrorAttribute.cs" in the *Solution Explorer*. You can delete the two files manually. |
| 72 | + |
| 73 | +# [.NET Core](#tab/netcore) |
| 74 | + |
| 75 | +1. In the *Solution Explorer* on the right, right click on **Solution** and select **Manage NuGet Packages for Solution**. |
| 76 | + |
| 77 | + You'll then see a screen that allows you to edit all the NuGet packages that are part of the project. |
| 78 | + |
| 79 | +  |
| 80 | + |
| 81 | +1. Click on "Microsoft.ApplicationInsights.AspNetCore" package. On the right, check the checkbox next to *Project* to select all projects then select **Uninstall**. |
| 82 | + |
| 83 | +  |
| 84 | + |
| 85 | +--- |
| 86 | + |
| 87 | +## What is created when you add Application Insights |
| 88 | + |
| 89 | +When you add Application Insights to your project, it creates files and adds code to some of your files. Solely uninstalling the NuGet Packages will not always discard the files and code. To fully remove Application Insights, you should check and manually delete the added code or files along with any API calls you added in your project. |
| 90 | + |
| 91 | +# [.NET](#tab/net) |
| 92 | + |
| 93 | +When you add Application Insights Telemetry to a Visual Studio ASP.NET project, it adds the following files: |
| 94 | + |
| 95 | +- ApplicationInsights.config |
| 96 | +- AiHandleErrorAttribute.cs |
| 97 | + |
| 98 | +The following pieces of code are added: |
| 99 | + |
| 100 | +- [Your project's name].csproj |
| 101 | + |
| 102 | + ```C# |
| 103 | + <ApplicationInsightsResourceId>/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/WebApplication4</ApplicationInsightsResourceId> |
| 104 | + ``` |
| 105 | + |
| 106 | +- Packages.config |
| 107 | + |
| 108 | + ```xml |
| 109 | + <packages> |
| 110 | + ... |
| 111 | + |
| 112 | + <package id="Microsoft.ApplicationInsights" version="2.12.0" targetFramework="net472" /> |
| 113 | + <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" /> |
| 114 | + <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.12.0" targetFramework="net472" /> |
| 115 | + <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.12.0" targetFramework="net472" /> |
| 116 | + <package id="Microsoft.ApplicationInsights.Web" version="2.12.0" targetFramework="net472" /> |
| 117 | + <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.12.0" targetFramework="net472" /> |
| 118 | + <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.12.0" targetFramework="net472" /> |
| 119 | + |
| 120 | + <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.7" targetFramework="net472" /> |
| 121 | + |
| 122 | + <package id="System.Buffers" version="4.4.0" targetFramework="net472" /> |
| 123 | + <package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net472" /> |
| 124 | + <package id="System.Memory" version="4.5.3" targetFramework="net472" /> |
| 125 | + <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" /> |
| 126 | + <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" /> |
| 127 | + ... |
| 128 | + </packages> |
| 129 | + ``` |
| 130 | + |
| 131 | +- Layout.cshtml |
| 132 | + |
| 133 | + If your project has a Layout.cshtml file the code below is added. |
| 134 | + |
| 135 | + ```html |
| 136 | + <head> |
| 137 | + ... |
| 138 | + <script type = 'text/javascript' > |
| 139 | + var appInsights=window.appInsights||function(config) |
| 140 | + { |
| 141 | + function r(config){ t[config] = function(){ var i = arguments; t.queue.push(function(){ t[config].apply(t, i)})} } |
| 142 | + var t = { config:config},u=document,e=window,o='script',s=u.createElement(o),i,f;for(s.src=config.url||'//az416426.vo.msecnd.net/scripts/a/ai.0.js',u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=['Event','Exception','Metric','PageView','Trace','Ajax'];i.length;)r('track'+i.pop());return r('setAuthenticatedUserContext'),r('clearAuthenticatedUserContext'),config.disableExceptionTracking||(i='onerror',r('_'+i),f=e[i],e[i]=function(config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t['_' + i](config, r, u, e, o),s}),t |
| 143 | + }({ |
| 144 | + instrumentationKey:'00000000-0000-0000-0000-000000000000' |
| 145 | + }); |
| 146 | + |
| 147 | + window.appInsights=appInsights; |
| 148 | + appInsights.trackPageView(); |
| 149 | + </script> |
| 150 | + ... |
| 151 | + </head> |
| 152 | + ``` |
| 153 | + |
| 154 | +- ConnectedService.json |
| 155 | + |
| 156 | + ```json |
| 157 | + { |
| 158 | + "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider", |
| 159 | + "Version": "16.0.0.0", |
| 160 | + "GettingStartedDocument": { |
| 161 | + "Uri": "https://go.microsoft.com/fwlink/?LinkID=613413" |
| 162 | + } |
| 163 | + } |
| 164 | + ``` |
| 165 | + |
| 166 | +- FilterConfig.cs |
| 167 | + |
| 168 | + ```csharp |
| 169 | + public static void RegisterGlobalFilters(GlobalFilterCollection filters) |
| 170 | + { |
| 171 | + filters.Add(new ErrorHandler.AiHandleErrorAttribute());// This line was added |
| 172 | + } |
| 173 | + ``` |
| 174 | + |
| 175 | +# [.NET Core](#tab/netcore) |
| 176 | + |
| 177 | +When you add Application Insights Telemetry to a Visual Studio ASP.NET Core template project, it adds the following code: |
| 178 | + |
| 179 | +- [Your project's name].csproj |
| 180 | + |
| 181 | + ```csharp |
| 182 | + <PropertyGroup> |
| 183 | + <TargetFramework>netcoreapp3.1</TargetFramework> |
| 184 | + <ApplicationInsightsResourceId>/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/WebApplication4core</ApplicationInsightsResourceId> |
| 185 | + </PropertyGroup> |
| 186 | + |
| 187 | + <ItemGroup> |
| 188 | + <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0" /> |
| 189 | + </ItemGroup> |
| 190 | + |
| 191 | + <ItemGroup> |
| 192 | + <WCFMetadata Include="Connected Services" /> |
| 193 | + </ItemGroup> |
| 194 | + ``` |
| 195 | + |
| 196 | +- Appsettings.json: |
| 197 | + |
| 198 | + ```json |
| 199 | + "ApplicationInsights": { |
| 200 | + "InstrumentationKey": "00000000-0000-0000-0000-000000000000" |
| 201 | + ``` |
| 202 | + |
| 203 | +- ConnectedService.json |
| 204 | + |
| 205 | + ```json |
| 206 | + { |
| 207 | + "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider", |
| 208 | + "Version": "16.0.0.0", |
| 209 | + "GettingStartedDocument": { |
| 210 | + "Uri": "https://go.microsoft.com/fwlink/?LinkID=798432" |
| 211 | + } |
| 212 | + } |
| 213 | + ``` |
| 214 | +- Startup.cs |
| 215 | + |
| 216 | + ```csharp |
| 217 | + public void ConfigureServices(IServiceCollection services) |
| 218 | + { |
| 219 | + services.AddRazorPages(); |
| 220 | + services.AddApplicationInsightsTelemetry(); // This is added |
| 221 | + } |
| 222 | + ``` |
| 223 | + |
| 224 | +--- |
| 225 | + |
| 226 | +## Next steps |
| 227 | + |
| 228 | +- [Azure Monitor](https://docs.microsoft.com/azure/azure-monitor/overview) |
0 commit comments