aws / aws-extensions-for-dotnet-cli

Extensions to the dotnet CLI to simplify the process of building and publishing .NET Core applications to AWS services
Apache License 2.0
369 stars 86 forks source link

Cannot build using mcr.microsoft.com/dotnet/sdk:6.0 #249

Closed savva312 closed 1 year ago

savva312 commented 1 year ago

Describe the bug

Hello up until recently (3 days ago) I was able to run dotnet lambda package --configuration Release

In Docker file.

Today I started having this error Target Framework of netcoreapp6.0 must have output type 'exe' and run on a custom runtime, since this is not a Lambda-managed .NET runtime.

I had to force to use older version for SAM to be able to build the project RUN dotnet tool install -g Amazon.Lambda.Tools --version 5.5.0

Expected Behavior

Build the project and push to clouformation

Current Behavior

Error

Target Framework of netcoreapp6.0 must have output type 'exe' and run on a custom runtime, since this is not a Lambda-managed .NET runtime.

Reproduction Steps

-

Possible Solution

No response

Additional Information/Context

No response

Targeted .NET platform

.NET6

CLI extension version

5.6.0

Environment details (OS name and version, etc.)

Windows 10

ashishdhingra commented 1 year ago

@savva312 Could you please recheck your .csproj file and compare it with what it was 3 or 4 days ago? netcoreapp6.0 doesn't appear to be a valid value for .NET 6 framework. It should be net6.0. Refer https://learn.microsoft.com/en-us/dotnet/standard/frameworks for Target framework moniker.

Thanks, Ashish

savva312 commented 1 year ago

Hey @ashishdhingra thanks for replying so fast.

I have checked git and the last edit on the .csproj was done on 28th of February. Since then, I have built the project with SAM multiple times with no problems.

I also managed to build the project 3 days ago and just yesterday I started getting the error mentioned above.

Specifying the --version in the Dockerfile fixed it for now.

ashishdhingra commented 1 year ago

Hey @ashishdhingra thanks for replying so fast.

I have checked git and the last edit on the .csproj was done on 28th of February. Since then, I have built the project with SAM multiple times with no problems.

I also managed to build the project 3 days ago and just yesterday I started getting the error mentioned above.

Specifying the --version in the Dockerfile fixed it for now.

@savva312 Thanks for your reply. Are you referring to --version for Amazon.Lambda.Tools? I would need to check what changed in the new version, May be an extra validation. Could you please share the contents of your .csproj file for further investigation?

Thanks, Ashish

savva312 commented 1 year ago

Sure here is my csproj file

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

  <PropertyGroup>
    <TargetFramework>netcoreapp6.0</TargetFramework>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <OutputType>Library</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="Data_old\**" />
    <EmbeddedResource Remove="Data_old\**" />
    <None Remove="Data_old\**" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Amazon.Lambda.Core" Version="2.0.0" />
    <PackageReference Include="Amazon.Lambda.APIGatewayEvents" Version="2.4.0" />
    <PackageReference Include="Amazon.Lambda.Serialization.SystemTextJson" Version="2.1.0" />
    <PackageReference Include="AWS.Logger.Core" Version="3.0.0" />
    <PackageReference Include="AWSSDK.Lambda" Version="3.7.8.18" />
    <PackageReference Include="AWSSDK.S3" Version="3.7.7.17" />
    <PackageReference Include="AWSSDK.SimpleSystemsManagement" Version="3.7.12.4" />
    <PackageReference Include="EFCore.NamingConventions" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="6.0.1" />
    <PackageReference Include="Serilog" Version="2.10.0" />
    <PackageReference Include="Serilog.Enrichers.GlobalLogContext" Version="1.0.0" />
    <PackageReference Include="Serilog.Exceptions" Version="8.1.0" />
    <PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
    <PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
    <PackageReference Include="Z.EntityFramework.Extensions.EFCore" Version="6.13.7" />
  </ItemGroup>
</Project>

This is my Dockerfile

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-image

ARG FUNCTION_DIR="/build"
ARG SAM_BUILD_MODE="run"
ENV PATH="/root/.dotnet/tools:${PATH}"

RUN apt-get update && apt-get -y install zip

RUN mkdir $FUNCTION_DIR
WORKDIR $FUNCTION_DIR
COPY . $FUNCTION_DIR/
RUN dotnet tool install -g Amazon.Lambda.Tools --version 5.5.0

# Build and Copy artifacts depending on build mode.
RUN mkdir -p build_artifacts
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then dotnet lambda package --configuration Debug; else dotnet lambda package --configuration Release; fi
RUN if [ "$SAM_BUILD_MODE" = "debug" ]; then cp -r /build/bin/Debug/netcoreapp6.0/publish/* /build/build_artifacts; else cp -r /build/bin/Release/netcoreapp6.0/publish/* /build/build_artifacts; fi

FROM public.ecr.aws/lambda/dotnet:6

COPY --from=build-image /build/build_artifacts/ /var/task/
# Command can be overwritten by providing a different command in the template directly.
CMD ["Project1::Project1.Function::FunctionHandler"]

And lastly am referring to Amazon.Lambda.Tools version

ashishdhingra commented 1 year ago

@savva312 Thanks. Clearly, the value netcoreapp6.0 is incorrect. The fix would be to change it to correct value net6.0 in the .csproj file. I will try to check how it worked in the previous version 5.5.0 of Amazon.Lambda.Tools. Is it possible for you to capture and share the output of dotnet lambda package --configuration Release when ran inside Docker container using Amazon.Lambda.Tools version 5.5.0?

savva312 commented 1 year ago

Sure, please see below, I hope this is what you are after

#14 [build-image 8/9] RUN dotnet lambda package --configuration Release
#14 sha256:8c4522a72a5a06891ad493cbc1267fd4f1bf26546d6b60b261c882a1d2d1e2cf
#14 0.863 Amazon Lambda Tools for .NET Core applications (5.5.0)
#14 0.863 Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet
#14 0.863
#14 0.901 Executing publish command
#14 0.906 ... invoking 'dotnet publish', working folder '/build/bin/Release/netcoreapp6.0/publish'
#14 0.909 ... dotnet publish --output "/build/bin/Release/netcoreapp6.0/publish" --configuration "Release" --framework "netcoreapp6.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-x64 --self-contained false
#14 1.006 ... publish: MSBuild version 17.3.2+561848881 for .NET
#14 1.378 ... publish:   Determining projects to restore...
#14 10.15 ... publish:   Restored /build/Project1.csproj (in 8.5 sec).
#14 11.86 ... publish:   Project1 -> /build/bin/Release/netcoreapp6.0/linux-x64/Project1.dll
#14 11.89 ... publish:   Project1 -> /build/bin/Release/netcoreapp6.0/publish/
#14 11.91 Changed permissions on published file (chmod +rx System.Windows.Extensions.dll).
#14 11.92 Changed permissions on published file (chmod +rx Microsoft.Extensions.DependencyInjection.dll).
#14 11.92 Changed permissions on published file (chmod +rx Z.EntityFramework.Extensions.EFCore.dll).
#14 11.92 Changed permissions on published file (chmod +rx Microsoft.Extensions.Logging.Abstractions.dll).
#14 11.92 Changed permissions on published file (chmod +rx Microsoft.Win32.SystemEvents.dll).
#14 11.92 Changed permissions on published file (chmod +rx Serilog.Formatting.Compact.dll).
#14 11.92 Changed permissions on published file (chmod +rx System.Configuration.ConfigurationManager.dll).
#14 11.92 Changed permissions on published file (chmod +rx Amazon.Lambda.Core.dll).
#14 11.92 Changed permissions on published file (chmod +rx AWSSDK.CloudWatchLogs.dll).
#14 11.92 Changed permissions on published file (chmod +rx Amazon.Lambda.Serialization.SystemTextJson.dll).
#14 11.92 Changed permissions on published file (chmod +rx AWSSDK.SimpleSystemsManagement.dll).
#14 11.92 Changed permissions on published file (chmod +rx Microsoft.Extensions.Options.dll).
#14 11.92 Changed permissions on published file (chmod +rx System.Drawing.Common.dll).
#14 11.93 Changed permissions on published file (chmod +rx Amazon.Lambda.APIGatewayEvents.dll).
#14 11.93 Changed permissions on published file (chmod +rx Serilog.Sinks.Console.dll).
#14 11.93 Changed permissions on published file (chmod +rx System.Security.Permissions.dll).
#14 11.93 Changed permissions on published file (chmod +rx Microsoft.Extensions.DependencyInjection.Abstractions.dll).
#14 11.93 Changed permissions on published file (chmod +rx Project1.runtimeconfig.json).
#14 11.93 Changed permissions on published file (chmod +rx Project1.deps.json).
#14 11.93 Changed permissions on published file (chmod +rx Project1.dll).
#14 11.93 Changed permissions on published file (chmod +rx Microsoft.Extensions.Logging.dll).
#14 11.93 Changed permissions on published file (chmod +rx AWS.Logger.Core.dll).
#14 11.93 Changed permissions on published file (chmod +rx System.Security.Cryptography.ProtectedData.dll).
#14 11.93 Changed permissions on published file (chmod +rx Microsoft.Extensions.Primitives.dll).
#14 11.93 Changed permissions on published file (chmod +rx Newtonsoft.Json.dll).
#14 11.93 Changed permissions on published file (chmod +rx Project1.pdb).
#14 11.93 Changed permissions on published file (chmod +rx Microsoft.EntityFrameworkCore.Abstractions.dll).
#14 11.94 Changed permissions on published file (chmod +rx Microsoft.Extensions.Caching.Memory.dll).
#14 11.94 Changed permissions on published file (chmod +rx Microsoft.EntityFrameworkCore.dll).
#14 11.94 Changed permissions on published file (chmod +rx MySqlConnector.dll).
#14 11.94 Changed permissions on published file (chmod +rx AWSSDK.Lambda.dll).
#14 11.94 Changed permissions on published file (chmod +rx Microsoft.EntityFrameworkCore.Relational.dll).
#14 11.94 Changed permissions on published file (chmod +rx Serilog.dll).
#14 11.94 Changed permissions on published file (chmod +rx Microsoft.Extensions.Configuration.Abstractions.dll).
#14 11.94 Changed permissions on published file (chmod +rx Pomelo.EntityFrameworkCore.MySql.dll).
#14 11.94 Changed permissions on published file (chmod +rx Serilog.Exceptions.dll).
#14 11.94 Changed permissions on published file (chmod +rx Serilog.Enrichers.GlobalLogContext.dll).
#14 11.94 Changed permissions on published file (chmod +rx AWSSDK.Core.dll).
#14 11.94 Changed permissions on published file (chmod +rx EFCore.NamingConventions.dll).
#14 11.94 Changed permissions on published file (chmod +rx Microsoft.Extensions.Caching.Abstractions.dll).
#14 11.95 Changed permissions on published file (chmod +rx AWSSDK.S3.dll).
#14 11.95 Zipping publish folder /build/bin/Release/netcoreapp6.0/publish to /build/bin/Release/netcoreapp6.0/build.zip
#14 11.95 ... zipping:   adding: System.Windows.Extensions.dll (deflated 50%)
#14 11.95 ... zipping:   adding: Microsoft.Extensions.DependencyInjection.dll (deflated 54%)
#14 12.00 ... zipping:   adding: Z.EntityFramework.Extensions.EFCore.dll (deflated 72%)
#14 12.01 ... zipping:   adding: Microsoft.Extensions.Logging.Abstractions.dll (deflated 54%)
#14 12.01 ... zipping:   adding: Microsoft.Win32.SystemEvents.dll (deflated 50%)
#14 12.01 ... zipping:   adding: Serilog.Formatting.Compact.dll (deflated 54%)
#14 12.02 ... zipping:   adding: System.Configuration.ConfigurationManager.dll (deflated 61%)
#14 12.03 ... zipping:   adding: Amazon.Lambda.Core.dll (deflated 47%)
#14 12.03 ... zipping:   adding: AWSSDK.CloudWatchLogs.dll (deflated 70%)
#14 12.03 ... zipping:   adding: Amazon.Lambda.Serialization.SystemTextJson.dll (deflated 48%)
#14 12.07 ... zipping:   adding: AWSSDK.SimpleSystemsManagement.dll (deflated 74%)
#14 12.07 ... zipping:   adding: Microsoft.Extensions.Options.dll (deflated 55%)
#14 12.09 ... zipping:   adding: System.Drawing.Common.dll (deflated 61%)
#14 12.09 ... zipping:   adding: Amazon.Lambda.APIGatewayEvents.dll (deflated 57%)
#14 12.09 ... zipping:   adding: Serilog.Sinks.Console.dll (deflated 58%)
#14 12.10 ... zipping:   adding: System.Security.Permissions.dll (deflated 60%)
#14 12.10 ... zipping:   adding: Microsoft.Extensions.DependencyInjection.Abstractions.dll (deflated 55%)
#14 12.10 ... zipping:   adding: Project1.runtimeconfig.json (deflated 32%)
#14 12.10 ... zipping:   adding: Project1.deps.json (deflated 81%)
#14 12.11 ... zipping:   adding: Project1.dll (deflated 60%)
#14 12.11 ... zipping:   adding: Microsoft.Extensions.Logging.dll (deflated 51%)
#14 12.11 ... zipping:   adding: AWS.Logger.Core.dll (deflated 50%)
#14 12.11 ... zipping:   adding: System.Security.Cryptography.ProtectedData.dll (deflated 48%)
#14 12.11 ... zipping:   adding: Microsoft.Extensions.Primitives.dll (deflated 51%)
#14 12.14 ... zipping:   adding: Newtonsoft.Json.dll (deflated 62%)
#14 12.15 ... zipping:   adding: Project1.pdb (deflated 59%)
#14 12.15 ... zipping:   adding: Microsoft.EntityFrameworkCore.Abstractions.dll (deflated 49%)
#14 12.15 ... zipping:   adding: Microsoft.Extensions.Caching.Memory.dll (deflated 49%)
#14 12.24 ... zipping:   adding: Microsoft.EntityFrameworkCore.dll (deflated 68%)
#14 12.26 ... zipping:   adding: MySqlConnector.dll (deflated 55%)
#14 12.28 ... zipping:   adding: AWSSDK.Lambda.dll (deflated 70%)
#14 12.34 ... zipping:   adding: Microsoft.EntityFrameworkCore.Relational.dll (deflated 67%)
#14 12.35 ... zipping:   adding: Serilog.dll (deflated 60%)
#14 12.35 ... zipping:   adding: Microsoft.Extensions.Configuration.Abstractions.dll (deflated 48%)
#14 12.37 ... zipping:   adding: Pomelo.EntityFrameworkCore.MySql.dll (deflated 64%)
#14 12.37 ... zipping:   adding: Serilog.Exceptions.dll (deflated 59%)
#14 12.37 ... zipping:   adding: Serilog.Enrichers.GlobalLogContext.dll (deflated 52%)
#14 12.41 ... zipping:   adding: AWSSDK.Core.dll (deflated 78%)
#14 12.41 ... zipping:   adding: EFCore.NamingConventions.dll (deflated 57%)
#14 12.41 ... zipping:   adding: Microsoft.Extensions.Caching.Abstractions.dll (deflated 49%)
#14 12.44 ... zipping:   adding: AWSSDK.S3.dll (deflated 66%)
#14 12.44 Created publish archive (/build/bin/Release/netcoreapp6.0/build.zip).
#14 12.44 Lambda project successfully packaged: /build/bin/Release/netcoreapp6.0/build.zip
#14 DONE 12.5s
normj commented 1 year ago

@savva312 It is true that version 5.6.0 of the Amazon.Lambda.Tools got some more validations logic on the target framework. This was done for some Native AOT .NET 7 support we added to the tooling. There are a lot of special case logic to make that work so we wanted to be sure we were giving users clear error messages when in an invalid situation.

As @ashishdhingra mentioned net6.0 is the actual framework moniker for .NET 6. Looks like the .NET SDK is forgiving with netcoreapp6.0 but it is non standard. Would it be possible for you to change your project to net6.0? I agree this is a regression in behavior for Amazon.Lambda.Tools but I would like to not have to maintain a list of non standard monikers as well if possible. If for whatever reason changing the framework moniker is unfeasible let me know.

savva312 commented 1 year ago

@normj Thank you for the clarifications.

If I remember correctly i ended up using netcore6.0 because .net 6 was not supported back then or i had some issues. Don’t remember exactly.

There is no problem to switch to .net6.

thank you both for your time.

ashishdhingra commented 1 year ago

@savva312 Thanks for your confirmation. Closing this issue.

github-actions[bot] commented 1 year ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.