2

i'm having this error when i try to run docker build in my dotnet core API:

 Invalid framework identifier ''

Here is my dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY Backend/AppManagerAPI/AppManagerAPI.csproj Backend/AppManagerAPI/
COPY Backend/DTO/DTO.csproj Backend/DTO/
COPY nuget.config ./
COPY Build/dependencies.props ./Build
COPY Backend/Database/Database.csproj Backend/Database/
COPY Backend/Service/Service.csproj Backend/Service/
COPY Utilities/Utilities.csproj Utilities/
RUN dotnet restore "Backend/AppManagerAPI/AppManagerAPI.csproj"
COPY . .
WORKDIR "/src/Backend/AppManagerAPI"
RUN dotnet build "AppManagerAPI.csproj" -c Release -o /app

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

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

and the full error stack:

$ docker build -t appmanager .
Sending build context to Docker daemon  560.6kB
Step 1/23 : FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
 ---> 34973cab5999
Step 2/23 : WORKDIR /app
 ---> Using cache
 ---> c402eb945a47
Step 3/23 : EXPOSE 80
 ---> Using cache
 ---> 8ac4a84a040e
Step 4/23 : EXPOSE 443
 ---> Using cache
 ---> 3c5014f9b6d5
Step 5/23 : FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
 ---> 08657316a4cd
Step 6/23 : WORKDIR /src
 ---> Using cache
 ---> e851dfaa1225
Step 7/23 : COPY Backend/AppManagerAPI/AppManagerAPI.csproj Backend/AppManagerAPI/
 ---> Using cache
 ---> 1eaa1d28c559
Step 8/23 : COPY Backend/DTO/DTO.csproj Backend/DTO/
 ---> Using cache
 ---> 81f9260e48a0
Step 9/23 : COPY nuget.config ./
 ---> Using cache
 ---> 3901e5ab8090
Step 10/23 : COPY Build/dependencies.props ./Build
 ---> Using cache
 ---> 35128353acde
Step 11/23 : COPY Backend/Database/Database.csproj Backend/Database/
 ---> Using cache
 ---> 25686efb1af9
Step 12/23 : COPY Backend/Service/Service.csproj Backend/Service/
 ---> Using cache
 ---> 3287a7a78971
Step 13/23 : COPY Utilities/Utilities.csproj Utilities/
 ---> Using cache
 ---> fe57c187d929
Step 14/23 : RUN dotnet restore "Backend/AppManagerAPI/AppManagerAPI.csproj"
 ---> Running in 33780f69aa7d
/usr/share/dotnet/sdk/2.2.401/NuGet.targets(123,5): error : Invalid framework identifier ''. [/src/Backend/AppManagerAPI/AppManagerAPI.csproj]
The command '/bin/sh -c dotnet restore "Backend/AppManagerAPI/AppManagerAPI.csproj"' returned a non-zero code: 1

I've already tried everything that i could think of, i was wondering if it has anything to do with my properties.props file, but copying it to the container didn't work. Any help would be appreciated.

UPDATE

Here's is my AppManagerAPI.csproj

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>$(NetCoreTargetVersion)</TargetFramework>
    <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
    <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    <UserSecretsId>d37c9296-55fb-4c04-ad4e-3d1f5451dc28</UserSecretsId>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
  </PropertyGroup>

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <NoWarn></NoWarn>
    <AllowUnsafeBlocks></AllowUnsafeBlocks>
  </PropertyGroup>
  <ItemGroup>
    <None Remove="API.xml" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Alpha.WebUtils.Core" Version="$(AlphaWebUtilsCorePackageVersion)" />
    <PackageReference Include="Microsoft.AspNetCore.App">
      <PrivateAssets Condition="'%(PackageReference.Version)' == ''">all</PrivateAssets>
      <Publish Condition="'%(PackageReference.Version)' == ''">true</Publish>
    </PackageReference>
    <PackageReference Include="Alpha.Utils.Core" Version="$(AlphaUtilsCorePackageVersion)" />
    <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="$(AutomapperDIPackageVersion)" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.4.10" />
    <PackageReference Include="Scrutor" Version="$(ScrutorPackageVersion)" />
    <PackageReference Include="Alpha.Backend.Core" Version="$(AlphaBackendCorePackageVersion)" />
    <PackageReference Include="Alpha.Backend.EFCore" Version="$(AlphaBackendEFCorePackageVersion)" />
    <PackageReference Include="Swashbuckle.AspNetCore" Version="$(SwashbuckleAspNetCorePackageVersion)" />
    <PackageReference Include="NetEscapades.Extensions.Logging.RollingFile" Version="$(LoggingRollingFilePackageVersion)" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Api.Analyzers" Version="$(ApiAnalyzersPackageVersion)" />
    <PackageReference Include="EfCore.GenericBizRunner" Version="$(EfCoreGenericBizRunnerPackageVersion)" />
  </ItemGroup>

  <ItemGroup>    
    <ProjectReference Include="..\DTO\DTO.csproj" />    
    <ProjectReference Include="..\Service\Service.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Models\" />
    <Folder Include="wwwroot\Upload\" />
    <Folder Include="logs\" />
  </ItemGroup>

  <ItemGroup>
    <Compile Remove="Controllers\Administracion\RutasController.cs" />
    <Compile Remove="Controllers\Administracion\SectoresController.cs" />
    <Compile Remove="Controllers\Administracion\ConsultaRutasController.cs" />
    <Compile Remove="Controllers\Administracion\ComercioEntidadTipoClienteController.cs" />
    <Compile Remove="Controllers\Administracion\LugaresController.cs" />
    <Compile Remove="Controllers\Genericos\CentrosController.cs" />
    <Compile Remove="Controllers\Genericos\MenuController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\AlisysController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\OrdenesIntervencionesController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\SauController.cs" />
    <Compile Remove="Controllers\Genericos\SystemController.cs" />
    <Compile Remove="Controllers\Mantenimiento\AccesoriosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\DiasFestivosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\EemmsController.cs" />
    <Compile Remove="Controllers\Mantenimiento\EntidadesMantenedorasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\EtiquetasSatController.cs" />
    <Compile Remove="Controllers\Mantenimiento\GruposCualificadoresController.cs" />
    <Compile Remove="Controllers\Mantenimiento\HorariosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\IncidenciasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\MarcasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\ModelosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\ModelosIndicadosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\MotivoCierreController.cs" />
    <Compile Remove="Controllers\Mantenimiento\MotivosParadaController.cs" />
    <Compile Remove="Controllers\Mantenimiento\PatronesCentroController.cs" />
    <Compile Remove="Controllers\Mantenimiento\PerfilesUsuarioController.cs" />
    <Compile Remove="Controllers\Mantenimiento\PermisosController.cs" />
    <Compile Remove="Controllers\Mantenimiento\PiezaAlmacenPrecioController.cs" />
    <Compile Remove="Controllers\Mantenimiento\PiezasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\SoftwaresController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TecnologiasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TipoActualizacionController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TipoIncidenciaController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TipoIntervencionController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposClientesController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposCoberturasController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposLugarController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposMantenimientoController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposModoTerminalController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposSeguridadTerminalController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposTecnologiaController.cs" />
    <Compile Remove="Controllers\Mantenimiento\TiposTerminalController.cs" />
    <Compile Remove="Controllers\Administracion\DelegacionesController.cs" />
    <Compile Remove="Controllers\Administracion\ListasCorreoController.cs" />
    <Compile Remove="Controllers\Genericos\CodigosPostalesController.cs" />
    <Compile Remove="Controllers\Genericos\MotivoTipoEntidadController.cs" />
    <Compile Remove="Controllers\Genericos\PrioridadesController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\BloqueosController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\EstadosIntervencionController.cs" />
    <Compile Remove="Controllers\GestionIntervenciones\EstadosOdinController.cs" />
    <Compile Remove="Controllers\Mantenimiento\Configuracion\CalendarioLaboralesController.cs" />
    <Compile Remove="Controllers\Mantenimiento\Configuracion\NotificacionesEmailController.cs" />
    <Compile Remove="Controllers\Mantenimiento\AccionesController.cs" />
  </ItemGroup>
</Project>
Joey
  • 344,408
  • 85
  • 689
  • 683
Edgar
  • 467
  • 1
  • 8
  • 23
  • 1
    Can you post also .csproj file ? – hovjan Aug 23 '19 at 07:26
  • 1
    Please add the `AppManagerAPI.csproj` file – Jota.Toledo Aug 23 '19 at 08:50
  • updated my question with the AppManagerAPI.csproj @Jota.Toledo – Edgar Aug 23 '19 at 12:45
  • Seems like `$(NetCoreTargetVersion)` is being resolved to `''`. Is that a standard macro? @Edgar – Jota.Toledo Aug 23 '19 at 13:26
  • I already thought about that, and tried setting the framework manually, but didn't work. @Jota.Toledo – Edgar Aug 23 '19 at 13:31
  • What happens if you set the target framework to `netcoreapp2.2`? Please add the result into your question – Jota.Toledo Aug 23 '19 at 13:33
  • The exact same error. I can post it if you want me to. @Jota.Toledo – Edgar Aug 23 '19 at 13:52
  • @Jota.Toledo i changed all my csproj in the solution and now it's restoring. I'm getting a different error but it doesn't have to do with this. But i wonder, if there a way to get it to work with the $(NetCoreTargetVersion) var? – Edgar Aug 23 '19 at 14:02
  • You didnt answer my first question, so I cant tell. No clue where is that `$(NetCoreTargetVersion)` macro defined. Are you trying to read an env. variable? – Jota.Toledo Aug 23 '19 at 14:04
  • Sorry i missed that question. To be honest i didn't started this project so i don't know if it is standard. It is defined in this file ```Build/dependencies.props``` – Edgar Aug 23 '19 at 14:23
  • 1
    Update your question with that info and the file in question. Also check https://stackoverflow.com/questions/42790536/sharedassemblyinfo-equivalent-in-net-core-projects – Jota.Toledo Aug 23 '19 at 14:40
  • thanks @Jota.Toledo already figured it out, posted my answer. – Edgar Aug 23 '19 at 15:12

1 Answers1

8

The problem was that i needed to copy my Directory.Build.props file and now is working. Just added this line to my dockerfile

COPY Directory.Build.props ./
Edgar
  • 467
  • 1
  • 8
  • 23