TelegramBots / book

Documentation for Telegram Bots Projects
https://telegrambots.github.io/book
81 stars 31 forks source link

ASP .NET Core dependency since version 21.2.0 #112

Closed Ludwintor closed 1 month ago

Ludwintor commented 2 months ago

All 21.X versions prior to 21.1 doesn't depend on ASP .NET Core runtime but since 21.2 it does and I have this error below because I just use .NET runtime in docker. That's not critical but I want to run long pooling bot in docker so I don't need whole asp .net core image but I have to use it because of that dependency

Steps to reproduce

  1. Create any non ASP .NET Core project (console, hosted worker service and etc) with name SampleProject and reference Telegram.Bot version higher or equal to 21.2.0
    <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
    <PackageReference Include="Telegram.Bot" Version="21.2.0" />
    </ItemGroup>
  2. Add nuget.config to project directory (to have access to 21.X versions)
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
    <packageSources>
        <add key="Nuget Voids" value="https://nuget.voids.site/v3/index.json"/>
    </packageSources>
    </configuration>

    3, Create Dockerfile in project directory where we use simple .NET runtime

    
    FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
    USER app
    WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build ARG BUILD_CONFIGURATION=Release WORKDIR /src COPY ["SampleProject/nuget.config", "SampleProject/"] COPY ["SampleProject/SampleProject.csproj", "SampleProject/"] RUN dotnet restore "./SampleProject/SampleProject.csproj" COPY . . WORKDIR "/src/SampleProject" RUN dotnet build "./SampleProject.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish ARG BUILD_CONFIGURATION=Release RUN dotnet publish "./SampleProject.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

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

4. Build and run Docker image

docker build --tag sample -f ./SampleProject/Dockerfile . docker run sample

5. Get error message that you should use ASP .NET Core framework

You must install or update .NET to run this application.

App: /app/SampleProject.dll Architecture: x64 Framework: 'Microsoft.AspNetCore.App', version '8.0.0' (x64) .NET location: /usr/share/dotnet/

No frameworks were found.

Learn more: https://aka.ms/dotnet/app-launch-failed

To install missing framework, download: https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=8.0.0&arch=x64&rid=linux-x64&os=debian.12

Ludwintor commented 1 month ago

sorry, wrong repo