dotnet / aspire

Tools, templates, and packages to accelerate building observable, production-ready apps
https://learn.microsoft.com/dotnet/aspire
MIT License
3.88k stars 469 forks source link

Support legacy Asp.Net MVC and console (e.g. topshelf) projects for simpler upgrade from NetFX to Net Core/8 #4984

Open gentledepp opened 4 months ago

gentledepp commented 4 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe the problem.

The aspire host allows me to also start basic .net 4.8 console and mvc projects. But

See this discrussion for reference

4842

Describe the solution you'd like

Best option: VS support for adding Aspire to an existing Asp.NET MVC project.

Good enough: A step-by-step tutorial in how to set this up. I tried but failed unfortunately.

Additional context

Background information: We are trying to migrate an asp.net MVC app to Asp.Net Core using the recommended approach

Thereby it would be nice if we could use Aspire to develop and run the old and new web app and also see which calls end up where (strangler fig pattern)

rikbosch commented 3 months ago

Might be related to #4309 ?

Sebbs128 commented 3 months ago

I've been working on a proof of concept to see how getting ASP.NET projects might work with Aspire. It's currently published to https://github.com/Sebbs128/AspireNetFramework. It's based a little on an IIS Express-based resource David Fowler shared in another issue/discussion (but pulls the existing site configs VS uses from .vs/{solution name}/config/applicationhost.config).

I'm definitely interested in trying to develop this further in a community-maintained library, as I don't believe MS understandably wants to support legacy ASP.NET in the main Aspire repo/packages.

CZEMacLeod commented 3 months ago

This looks like a good start. I did some work to try and do something similar myself, but I was struggling to enumerate the PID for IISExpress after it launched, or work out how to tell VS to attach to it. Have you tried with the MSBuild.SDK.SystemWeb project type for your AspNet 4.x side? I did manage to inject all the OTEL / OTLP stuff and get the AspNet logging etc. working well with the Aspire dashboard.

Sebbs128 commented 3 months ago

I haven't tried with MSBuild.SDK.SystemWeb (I kind of forgot it exists 😅 Last I looked at it there was either some missing things that we needed or it was a bit too unofficial for us, but that's another conversation). So far I was trying to keep the project file within the realm of "supported" (eg. still using packages.config instead of PackageRef, although I know how to trick VS into upgrading a legacy-style ASP.NET project), since I figure that will be most projects that might use a potential future library.

I'd love to take a look at the OTEL/OTP stuff if you have any examples of what you did to get that working.

Attaching VS to IISExpress is another thing I haven't yet figured out; manually attaching via Debug->Attach to process works fine, but I'm planning on seeing if things like these SO answers will work.

CZEMacLeod commented 3 months ago

@Sebbs128 Used a little bit of your example to redo my implementation There are a couple of examples there (they both use MSBuild.SDK.SystemWeb 😉) My biggest issue is that I have 2 ways to try and get a debugger attached, and neither are very satisfactory. I don't know how to hook the IDE integration bit to attach to the PID - maybe better minds (or at least those more familiar with the DCP/Aspire inner workings) can enlighten me on this bit 😁.

The SO answers given require an Extension running in VS - you could try and create a WebApi of some kind in an extension to listen and attach, but I kind of think that is part of the VS integration already part of Aspire, so it would be a bit of reinventing the wheel. Perhaps we can get more info on how to use the native implementation of this and use that. I welcome feedback on the techniques, and the samples.

gentledepp commented 3 months ago

What are you guys talking about? I just added aspire to my old ASP.NET MVC based solution, run the app host:

var builder = DistributedApplication.CreateBuilder(args);

builder.AddProject<Projects.iCL_Portal_Reporting_Host>("dubidu-reporting-host"); // a .NET 4.8 based console app

builder.AddProject<Projects.iCL_Portal_Web>("dubidu-web"); // an ASP.NET 4.8 web application 

builder.Build().Run();

And I am attached with my debugger to IIS just fine. I did not have to do anything.

Are we talking about the same thing here?

How exactly do you get your ASP.NET MVC apps traces and logs to the dashboard?

CZEMacLeod commented 3 months ago

@gentledepp Yes - you can add a legacy project format to aspire (although I don't think this worked originally). It does not pick up the endpoints automatically however.

You have 2 things to do to get the telemetry back.

  1. Ensure you are running on http not https (there is an issue with grpc over https on net framework)
  2. Setup the telemetry in your HttpApplication Application_Start method (global.asax.cs).

I've added an example to C3D.Extensions.Aspire.IISExpress.

You can do step 2 either the same way as the SimpleMVC example, or I've created a library with an inheritable OpenTelemeteryApplication which does all the hook up for you.

The problem is that if you use an SDK format project for ASP.Net 4.x, Aspire cannot handle the LaunchProfiles correctly. You either get

Missing components to configure and manage IIS express.

or

Unable to cast object of type 'Microsoft.WebTools.ProjectSystem.WebServer.IISExpressWebServer' to type 'Microsoft.WebTools.ProjectSystem.IWebServerDebuggingSupport'.