7 ms·
ASP.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 meth
by jkulubya 5y ago
ASP.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...
- luuio 5y agoThat 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
- dahauns 5y agoBut those are just sets of convenient defaults? You could just start with the default sdk and add the imports/targets yourself (or in practice: let the IDE do it for you.) And >- If you switch the project to Sdk=...Web, you won't have the dependencies to build the worker services. Yes you will, since the worker sdk is simply a subset of the web sdk.
- luuio 5y ago> You could just start with the default sdk and add the imports/targets yourself (or in practice: let the IDE do it for you.) That's what I have been calling out. I have not had much luck in pulling in the right dependencies needed. Could not find any documentation on it. Everything relies on that Sdk=...Web thing on the official documentation.
- dahauns 5y agoWell, not much to add to what jkulubya said, but: Just use Web, then - that's what it's for and it just worksTM. We have almost your exact scenario in production - a (Quartz.NET-based) service for background/scheduled jobs, with a web dashboard and a healthcheck API, all from a single console executable without external dependencies. And it was super straightforward to implement.
- jkulubya 5y agoIf you’re just looking to be unblocked, use the Web SDK because you’re building and running combined web + hosted services [1]. The section linked shows the precise difference between the Web and Worker SDKs for hosted services. If you’re looking for docs on what all the SDKs are/do, and their source code, start here [2]. If you’re looking to just add the asp net core packages/apis to your basic sdk/console project, here [3]. But note that your app build/publish probably won’t work 100% because msbuild won’t be configured to do so. If you want to fix that manually (i.e do what the Web SDK does automatically), You can use the Web SDK props file as a starting point [4]. (Linked to in [2]) It seems well documented to me, but you’re welcome to propose new docs to the aspnet docs team. They’re very responsive [5]. [1] https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services?view=aspnetcore-6.0&tabs=visual-studio#package https://docs.microsoft.com/en-us/aspnet/core/fundamentals/ho... [2] https://docs.microsoft.com/en-us/dotnet/core/project-sdk/overview https://docs.microsoft.com/en-us/dotnet/core/project-sdk/ove... [3] https://docs.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-5.0&tabs=visual-studio#use-the-aspnet-core-shared-framework https://docs.microsoft.com/en-us/aspnet/core/fundamentals/ta... [4] https://github.com/dotnet/sdk/blob/ee98c8c25188195fd4f8a145b9e5f6aed33dd175/src/WebSdk/Web/Sdk/Sdk.props https://github.com/dotnet/sdk/blob/ee98c8c25188195fd4f8a145b... [5] https://github.com/dotnet/AspNetCore.Docs https://github.com/dotnet/AspNetCore.Docs
- 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.
- jkulubya 5y agoThe original poster is going slightly off the beaten path and therefore has to manually compose three or four different concepts together to come to the right solution vs relying on the out of the box experience. I, and a lot of other devs, would be able to solve this particular problem without looking up the docs but I can’t assume any knowledge on the poster’s behalf so I posted the links to the docs about the building blocks and an article showing one possible way of composing them. The same exact problem as posed by the poster was thought of by the dotnet/aspnet teams and the pieces (apis/docs/samples) are all there, just not the default.
- 5y ago