From 288a49ce8edbd8a8fac8e8862cbc07d3573e460c Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Tue, 24 May 2022 18:31:13 -0700 Subject: [PATCH 1/5] Add nuget package badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 94719b8..8b7f609 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Application Insights Profiler for ASP.NET Core +[![Nuget](https://img.shields.io/nuget/v/Microsoft.ApplicationInsights.Profiler.AspNetCore)](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/) + ## Announcement * Profiler [2.3.1](https://www.nuget.org/packages/Microsoft.ApplicationInsights.Profiler.AspNetCore/2.3.1) is released. From 383e23c36b3a325baa7983c36f7ab2a58bfba5d3 Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Wed, 25 May 2022 16:52:22 -0700 Subject: [PATCH 2/5] Add an example for repack profile in other package --- examples/ReReleaseNuGet/.gitignore | 1 + examples/ReReleaseNuGet/Readme.md | 70 +++++++++++++++++++ .../ReReleaseNuGet/SharedLib/SharedLib.csproj | 26 +++++++ .../ReReleaseNuGet/WebAPI/.vscode/tasks.json | 24 +++++++ .../Controllers/WeatherForecastController.cs | 32 +++++++++ examples/ReReleaseNuGet/WebAPI/Program.cs | 27 +++++++ .../ReReleaseNuGet/WebAPI/WeatherForecast.cs | 12 ++++ examples/ReReleaseNuGet/WebAPI/WebAPI.csproj | 14 ++++ .../WebAPI/appsettings.Development.json | 8 +++ .../ReReleaseNuGet/WebAPI/appsettings.json | 9 +++ examples/ReReleaseNuGet/nuget.config | 9 +++ 11 files changed, 232 insertions(+) create mode 100644 examples/ReReleaseNuGet/.gitignore create mode 100644 examples/ReReleaseNuGet/Readme.md create mode 100644 examples/ReReleaseNuGet/SharedLib/SharedLib.csproj create mode 100644 examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json create mode 100644 examples/ReReleaseNuGet/WebAPI/Controllers/WeatherForecastController.cs create mode 100644 examples/ReReleaseNuGet/WebAPI/Program.cs create mode 100644 examples/ReReleaseNuGet/WebAPI/WeatherForecast.cs create mode 100644 examples/ReReleaseNuGet/WebAPI/WebAPI.csproj create mode 100644 examples/ReReleaseNuGet/WebAPI/appsettings.Development.json create mode 100644 examples/ReReleaseNuGet/WebAPI/appsettings.json create mode 100644 examples/ReReleaseNuGet/nuget.config diff --git a/examples/ReReleaseNuGet/.gitignore b/examples/ReReleaseNuGet/.gitignore new file mode 100644 index 0000000..f4c13ee --- /dev/null +++ b/examples/ReReleaseNuGet/.gitignore @@ -0,0 +1 @@ +Pkgs \ No newline at end of file diff --git a/examples/ReReleaseNuGet/Readme.md b/examples/ReReleaseNuGet/Readme.md new file mode 100644 index 0000000..45d3fec --- /dev/null +++ b/examples/ReReleaseNuGet/Readme.md @@ -0,0 +1,70 @@ +# Re-releasing Profiler.ASPNetCore package + +It is common to have shared library in a solution. This example describes how to properly build a NuGet package of your own that carries profiler assets and could be shared across your own solution. + +In this example, there are 2 projects, `WebAPI` is client project, that's the project we turn profiler on. `SharedLib` will be built into a NuGet package to simulate whatever the common package your want to build, with Profiler enabled. As per the `PackageId` property in [SharedLib.csproj](./SharedLib/SharedLib.csproj), it will be built into `ProfilerExample.SharedLib.1.0.0.nupkg`. + +```mermaid +stateDiagram-v2 +[*] --> WebAPI +WebAPI --> ProfilerExample.SharedLib(NuGet) +ProfilerExample.SharedLib(NuGet) --> Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet) +Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet) --> [*] +``` + +Here's a recommended way to enable Profiler in `ProfilerExample.SharedLib` package: + +## Add reference to NuGet package + +1. Add reference to `Microsoft.ApplicationInsights.Profiler.AspNetCore` is in `SharedLib`: + + ```xml + + + + ``` + +1. [KEY STEP] Setup the package to exclude `contentFiles` from private assets: + + ```xml + + + + + analyzers;build + + + ``` + _Tips: You might want to reference `Microsoft.ApplicationInsights.AspNetCore` in your shared project as well._ + +## Verify it works + +1. Build the package + + ```shell + SharedLib> dotnet pack -o ../Pkgs + ``` + +1. Check the build output in [Pkgs](./Pkgs/) folder, expect to see `ProfilerExample.SharedLib.1.0.0.nupkg`. +1. Verify the NuGet package local source is configured correctly in [nuget.config](./nuget.config), specifically, the local source is added: + + ```xml + + ``` + +1. Reference the built package: + + ```xml + + ``` + +1. Now build the `WebAPI` project: + + ```shell + WebAPI> dotnet build + ``` + +1. Check that the file of `TraceUpload.zip` is included in the header project output at: `bin/Debug/net6.0/TraceUploader.zip` + +1. In any header project, you can follow the other instructions to enable profiler in your header project now. There is NO need to reference it again. + diff --git a/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj b/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj new file mode 100644 index 0000000..dfe6d4e --- /dev/null +++ b/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj @@ -0,0 +1,26 @@ + + + + netstandard2.1 + enable + true + ProfilerExample.SharedLib + + + + + + + + + + + + + + + + analyzers;build + + + \ No newline at end of file diff --git a/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json b/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json new file mode 100644 index 0000000..31c32bd --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json @@ -0,0 +1,24 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "shell", + "args": [ + "build", + // Ask dotnet build to generate full paths for file names. + "/property:GenerateFullPaths=true", + // Do not generate summary otherwise it leads to duplicate errors in Problems panel + "/consoleloggerparameters:NoSummary" + ], + "group": "build", + "presentation": { + "reveal": "silent" + }, + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/examples/ReReleaseNuGet/WebAPI/Controllers/WeatherForecastController.cs b/examples/ReReleaseNuGet/WebAPI/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..086e7cc --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace WebAPIOne.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/examples/ReReleaseNuGet/WebAPI/Program.cs b/examples/ReReleaseNuGet/WebAPI/Program.cs new file mode 100644 index 0000000..464aa18 --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/Program.cs @@ -0,0 +1,27 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. +builder.Services.AddApplicationInsightsTelemetry(); +builder.Services.AddServiceProfiler(); + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/examples/ReReleaseNuGet/WebAPI/WeatherForecast.cs b/examples/ReReleaseNuGet/WebAPI/WeatherForecast.cs new file mode 100644 index 0000000..392afea --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace WebAPIOne; + +public class WeatherForecast +{ + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/examples/ReReleaseNuGet/WebAPI/WebAPI.csproj b/examples/ReReleaseNuGet/WebAPI/WebAPI.csproj new file mode 100644 index 0000000..6e39684 --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/WebAPI.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/examples/ReReleaseNuGet/WebAPI/appsettings.Development.json b/examples/ReReleaseNuGet/WebAPI/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/examples/ReReleaseNuGet/WebAPI/appsettings.json b/examples/ReReleaseNuGet/WebAPI/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/examples/ReReleaseNuGet/WebAPI/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/examples/ReReleaseNuGet/nuget.config b/examples/ReReleaseNuGet/nuget.config new file mode 100644 index 0000000..1edc693 --- /dev/null +++ b/examples/ReReleaseNuGet/nuget.config @@ -0,0 +1,9 @@ + + + + + + + + + From a8ca1581af0a928114bbc059cff9125d14156db5 Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Thu, 26 May 2022 08:29:20 -0700 Subject: [PATCH 3/5] Review the readme --- examples/ReReleaseNuGet/Readme.md | 11 ++++++++--- examples/ReReleaseNuGet/SharedLib/SharedLib.csproj | 11 +++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/ReReleaseNuGet/Readme.md b/examples/ReReleaseNuGet/Readme.md index 45d3fec..7dc8de8 100644 --- a/examples/ReReleaseNuGet/Readme.md +++ b/examples/ReReleaseNuGet/Readme.md @@ -1,6 +1,6 @@ # Re-releasing Profiler.ASPNetCore package -It is common to have shared library in a solution. This example describes how to properly build a NuGet package of your own that carries profiler assets and could be shared across your own solution. +It is common to have shared library in a solution. This example describes how to properly build a NuGet package of your own that carries profiler assets and could be reused across your own solution. In this example, there are 2 projects, `WebAPI` is client project, that's the project we turn profiler on. `SharedLib` will be built into a NuGet package to simulate whatever the common package your want to build, with Profiler enabled. As per the `PackageId` property in [SharedLib.csproj](./SharedLib/SharedLib.csproj), it will be built into `ProfilerExample.SharedLib.1.0.0.nupkg`. @@ -12,7 +12,7 @@ ProfilerExample.SharedLib(NuGet) --> Microsoft.ApplicationInsights.Profiler.AspN Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet) --> [*] ``` -Here's a recommended way to enable Profiler in `ProfilerExample.SharedLib` package: +Here's a recommendation: ## Add reference to NuGet package @@ -35,6 +35,8 @@ Here's a recommended way to enable Profiler in `ProfilerExample.SharedLib` packa ``` + Refer to [SharedLib.csproj](./SharedLib/SharedLib.csproj) for details. The key is to setup `analyzers;build` to exclude the `contentFiles` from private assets. + _Tips: You might want to reference `Microsoft.ApplicationInsights.AspNetCore` in your shared project as well._ ## Verify it works @@ -66,5 +68,8 @@ Here's a recommended way to enable Profiler in `ProfilerExample.SharedLib` packa 1. Check that the file of `TraceUpload.zip` is included in the header project output at: `bin/Debug/net6.0/TraceUploader.zip` -1. In any header project, you can follow the other instructions to enable profiler in your header project now. There is NO need to reference it again. +1. In any header project, without reference profiler package again, you can then follow the other instructions to enable profiler. + +## Feedback +If you have suggestions or if there is any questions, problems, please [file an issue](https://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/issues). \ No newline at end of file diff --git a/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj b/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj index dfe6d4e..7c046b6 100644 --- a/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj +++ b/examples/ReReleaseNuGet/SharedLib/SharedLib.csproj @@ -9,18 +9,13 @@ - - - - - - - - analyzers;build + + + \ No newline at end of file From db4a6f81b2a9f082d1020a69b94cdf060000e00a Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Thu, 26 May 2022 08:31:34 -0700 Subject: [PATCH 4/5] Delete tasks.json --- .../ReReleaseNuGet/WebAPI/.vscode/tasks.json | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json diff --git a/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json b/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json deleted file mode 100644 index 31c32bd..0000000 --- a/examples/ReReleaseNuGet/WebAPI/.vscode/tasks.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - // See https://go.microsoft.com/fwlink/?LinkId=733558 - // for the documentation about the tasks.json format - "version": "2.0.0", - "tasks": [ - { - "label": "build", - "command": "dotnet", - "type": "shell", - "args": [ - "build", - // Ask dotnet build to generate full paths for file names. - "/property:GenerateFullPaths=true", - // Do not generate summary otherwise it leads to duplicate errors in Problems panel - "/consoleloggerparameters:NoSummary" - ], - "group": "build", - "presentation": { - "reveal": "silent" - }, - "problemMatcher": "$msCompile" - } - ] -} \ No newline at end of file From d12afc2b6e4a7e68fd31ebb1f896cc1db6859531 Mon Sep 17 00:00:00 2001 From: Saar Shen Date: Fri, 27 May 2022 15:18:06 -0700 Subject: [PATCH 5/5] Update the text a bit --- examples/ReReleaseNuGet/Readme.md | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/examples/ReReleaseNuGet/Readme.md b/examples/ReReleaseNuGet/Readme.md index 7dc8de8..6e33350 100644 --- a/examples/ReReleaseNuGet/Readme.md +++ b/examples/ReReleaseNuGet/Readme.md @@ -1,15 +1,21 @@ -# Re-releasing Profiler.ASPNetCore package +# Properly reference Microsoft.ApplicationInsights.Profiler.AspNetCore in your NuGet package -It is common to have shared library in a solution. This example describes how to properly build a NuGet package of your own that carries profiler assets and could be reused across your own solution. +It is common to have shared libraries in a solution, some times, your own NuGet packages. This example describes how to properly build a NuGet package of your own that carries profiler and could be reused by other projects. -In this example, there are 2 projects, `WebAPI` is client project, that's the project we turn profiler on. `SharedLib` will be built into a NuGet package to simulate whatever the common package your want to build, with Profiler enabled. As per the `PackageId` property in [SharedLib.csproj](./SharedLib/SharedLib.csproj), it will be built into `ProfilerExample.SharedLib.1.0.0.nupkg`. +In this example, there are 2 projects, `WebAPI` is client project, that's the project we want to turn profiler on. `SharedLib` will be built into a NuGet package to simulate whatever the common package your want to build, with Profiler ready to go. As per the `PackageId` property in [SharedLib.csproj](./SharedLib/SharedLib.csproj), it will be built into `ProfilerExample.SharedLib.1.0.0.nupkg`. ```mermaid stateDiagram-v2 [*] --> WebAPI +[*] --> WebAPI2 WebAPI --> ProfilerExample.SharedLib(NuGet) +WebAPI2 --> ProfilerExample.SharedLib(NuGet) ProfilerExample.SharedLib(NuGet) --> Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet) -Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet) --> [*] + +note left of WebAPI2: This is another project that need to turn on Profiler. +note left of WebAPI: This is your project to reference shared NuGet package. +note right of ProfilerExample.SharedLib(NuGet): This is the shared NuGet package built by you. +note right of Microsoft.ApplicationInsights.Profiler.AspNetCore(NuGet): This is the Profiler package ``` Here's a recommendation: