SteeltoeOSS / Steeltoe

.NET Components for Externalized Configuration, Database Connectors, Service Discovery, Logging and Distributed Tracing, Application Management, Security, and more.
https://steeltoe.io
Apache License 2.0
1.01k stars 163 forks source link

Dependency on AspNetCoreApp #257

Closed djosemartine closed 4 years ago

djosemartine commented 4 years ago

Describe the bug

There is a dependency on AspNetCoreApp on versions above of 2.3.0 for the package Steeltoe.Extensions.Configuration.ConfigServerCore

Steps to reproduce

Steps to reproduce the behavior:

  1. Create a .Net Core Project based on Console or worker service template
  2. Add Docker support
  3. Install Steeltoe.Extensions.Configuration.ConfigServerCore on your project
  4. Use Config server in your project
  5. Debug App on Docker

Expected behavior

Debugging App using docker successfully

Environment (please complete the following information):

Source Code

using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Steeltoe.Extensions.Configuration.ConfigServer;

namespace WorkerService1
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .AddConfigServer()
                .ConfigureServices((hostContext, services) =>
                {
                    services.AddHostedService<Worker>();
                });
    }
}

Dockerfile

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["WorkerService1/WorkerService1.csproj", "WorkerService1/"]
RUN dotnet restore "WorkerService1/WorkerService1.csproj"
COPY . .
WORKDIR "/src/WorkerService1"
RUN dotnet build "WorkerService1.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "WorkerService1.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WorkerService1.dll"]

Error Output

You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
  - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=debian.10-x64
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program 'dotnet' has exited with code 150 (0x96).
TimHess commented 4 years ago

All of the Steeltoe packages with names ending in Core were built for ASP.NET Core, but it does look like some of the functionality could be moved to Base packages, namely the extension you're using here. I will see what I can do

TimHess commented 4 years ago

There's a wrinkle with the initial idea I had, in that we'd need to add a reference to Microsoft.Extensions.Hosting in ConfigServerBase or any other package we try to make this move. I'm not sure that's the best choice in our 2.x line, as that would bring that package and its dependencies in for lots of applications that don't need it. I'm inclined to defer further investigation on that until we find some other need, and suggest that change would be better suited for Steeltoe 3.x.

Something that will work right now however, would be to make these changes:

Given there's a solution to the immediate problem and lack of definition around a larger scoped problem, I'm going to close the issue ~ please feel free to reopen if the proposed solution doesn't end up working for you or if there's more to say here

djosemartine commented 4 years ago

Thank you @TimHess, understood! Thanks for all your help