7 ms·
I have the same experience as the parent comment. For example, I wanted to have a process that runs both the asp.net service, a background discord bot, and anot
by luuio 5y ago
I have the same experience as the parent comment.
For example, I wanted to have a process that runs both the asp.net service, a background discord bot, and another asp.net service.
On any other platform, it's just a good old "console app" equivalent, and you can start multiple services in your main function, catch SIGTERM, and control each service on your own.
On .NET, the project type has to be some weird Microsoft.Web.SDK things if you wanna run asp.net, and the IDE/build system would figure out what dependencies to build. And if I wanna run other services in the same binary, tough luck.
Why can't ASP.NET just be constructed as a regular console app, where you pull in nuget dependencies, instead of a completely different app type, for example.
- kumarvvr 5y agohttps://www.syncfusion.com/blogs/post/how-to-develop-an-asp-net-core-application-using-visual-studio-code.aspx/amp https://www.syncfusion.com/blogs/post/how-to-develop-an-asp-...
- deleted 5y ago[deleted]
- luuio 5y agoHuh? I don't think you read what I'm saying. Here's a simple challenge for you. Create a command line app (your csproj file should say Sdk="Microsoft.NET.Sdk"), ask the user to input a port number at runtime. Use this port number to start an ASP.NET service. I have not had any luck to pull all the right nuget dependencies to do that so far. The only way to run asp.net app I could find is switching your whole project to be Sdk="Microsoft.NET.Sdk.Web"
- kumarvvr 5y agoYou can run multiple asp.net core services on different ports on same machine. You could create an over-arching console application to automate the same, or you can do it with a simple script. https://docs.microsoft.com/en-us/troubleshoot/developer/webapps/aspnetcore/practice-troubleshoot-linux/2-6-run-two-aspnetcore-applications-same-time https://docs.microsoft.com/en-us/troubleshoot/developer/weba...
- luuio 5y agoNope. Not the same thing. Again, I want them to be in the same binary. Like the example I gave you, have the user input a port number *at runtime*, then use that port to start an asp.net service. That's just an example. The point is mixing a regular console app with an asp.net service.
- useerup 5y ago1. Create a new web project (it is actually a console app) 2. In program.cs add the following lines at the top: Console.Write("Port number:"); var port = int.Parse(Console.ReadLine()); 3. Change the bottom line App.Run()` to app.Run($"https://localhost:{port}"); You now have an application which asks for a port and launches your empty website on that port. A `Microsoft.NET.Sdk.Web` project is still a console app. The "web" variant has some other default packages and (crucially) it has some other defaults for how to compile files such as cshtml.
- luuio 5y agoI can confidently tell you that what you put here won't work. Try it.
- useerup 5y agoI did. It works. The above code lines are cut directly from a test project that I made. Several people have pointed out how a web app in .NET 5/6 is really a console app which only starts a web server configured with an application and waits for it to complete (i.e. shut down). It really is that simple.
- luuio 5y agoThe whole point here is that the project does not target the Sdk.Web thing. Yours only works because the project is targeting Sdk.Web (instead of Sdk). When I said console app, I literally meant using the project that you would create if you do `dotnet new console`. To copy from my other comment: That is exactly the thing. I do not want to have the Sdk=...Web/Worker. Imagine this scenario, you started a new project with the Sdk targeting Worker. Then you need that binary to also target web. What do you do? - If you switch the project to Sdk=...Web, you won't have the dependencies to build the worker services. - If you keep it as Sdk=...Worker, you won't have the dependencies to build asp.net
- deleted 5y ago[deleted]
- Ducki 5y agoYou can set the ports via the kestrel options: https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel/endpoints?view=aspnetcore-6.0#listenoptionsusehttps https://docs.microsoft.com/en-us/aspnet/core/fundamentals/se...
- merb 5y ago> I have not had any luck to pull all the right nuget dependencies to do that so far. thats because they are not directly on nuget. at least not in the included one, you need a framework reference, since for packaging reasons they have a runtime and a "web runtime" (kinda like that) https://docs.microsoft.com/de-de/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-6.0&tabs=visual-studio https://docs.microsoft.com/de-de/aspnet/core/fundamentals/ta...
- aliswe 5y agoThey did that around .NET Core 1.x, but it became unwieldy (trust me it was a complete mess) and they switched it for the framework references, and they switched that for the SDK included dependencies iirc.
- throwra620 5y ago
- jkulubya 5y agoASP.NET Core apps are actually straightforward console applications. In fact most of the application types you’ll run on .net core are configured in a main method in program.cs. The answer to your specific questions about mixing different services in one app will be some combination of the following links. https://khalidabuhakmeh.com/hosting-two-aspnet-core-apps-in-one-host https://khalidabuhakmeh.com/hosting-two-aspnet-core-apps-in-... https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/generic-host?view=aspnetcore-6.0 https://docs.microsoft.com/en-us/aspnet/core/fundamentals/ho... https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-6.0&tabs=visual-studio https://docs.microsoft.com/en-us/aspnet/core/fundamentals/ho...
- spaetzleesser 5y agoThat’s the problem. You have to read multiple articles to achieve simple things.
- DeathArrow 5y agoWell how would you do it if another platform if you are a beginner. Because I am a beginner in Rust, this is the process I would use: 1. search Google, read few articles or posts 2. write code 3. make it compile 4. encounter bugs 5. research the bugs on yet other articles or posts 6. fix the bugs 7. ??? 8. profit!
- luuio 5y agoIt's not about if you should or should not search. It's about how often you have to do that, and how easy it is to search for what you want. It boils down to how much anti pattern a framework/ecosystem has. In this case, their default template caused me to search "dotnet core project multiple SDK", which yielded nothing, and is actually a completely wrong track. The answer the asp.net team shared below, was instead of using the SDK attribute, use a completely different thing called FrameworkReference. Which can completely replace this SDK attribute, it seems. Hence my question to them below was, why is framework reference not the default? Especially since it does lead to better searchability, and the template shows that one could have multiple of these per project, intuitively.
- pllbnk 5y agoI agree with your sentiment. It's probably a legacy left-over from the .NET Framework days where you had to choose upfront what app you are going to build and where it was going to run and then you had the full IDE experience configured. .NET team has made a lot of right steps to fix this, however they haven't fixed MSBuild. As a long-term .NET developer (not anymore sadly, but still find it the best development experience) I always found MSBuild confusing but it has only become harder to learn because it has too much going on under the hood. So, if you want to do what you are saying, you should look into learning more MSBuild because .NET certainly allows you to do that without workarounds if you have your build configured correctly.
- smaudet 5y agoI think C# is incredibly close to Java in this regard. Not in the specifics of e.g. your problem, but the big "solutions" tend to be very enterprise solution-y, single-goal orientated. Spring in JAVA (also J2EE) had a similar sort of issue, where everything worked as long as you weren't veering off of the beaten path, but things got wildly over-complicated as soon as you dared to stray... The claims made in this article also sound a lot like what Java folk would say back when their platform wasn't yet "cool" - they are nevertheless somewhat successful today, so maybe they have a point? Regardless, you can absolutely do web dev from a simple C# console app, I don't know there are pre-build server frameworks for doing so. If you don't like MS's offering, tough.