aws / aws-sam-cli-app-templates

Apache License 2.0
460 stars 255 forks source link

Bug: .NET 6 templates does not build on SAM CLI #441

Closed super132 closed 10 months ago

super132 commented 11 months ago

Description:

After running sam init and created a .NET6 Serverless API application, when I ran sam build -u, I got the following error:

Mounting /tmp/sam-app/src/sam-app as /tmp/samcli/source:rw,delegated, inside runtime container
Running DotnetCliPackageBuilder:GlobalToolInstall
You can invoke the tool using the following command: dotnet-lambda
Tool 'amazon.lambda.tools' (version '5.7.2') was successfully installed.
Running DotnetCliPackageBuilder:RunPackageAction
Amazon Lambda Tools for .NET Core applications (5.7.2)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Executing publish command
... invoking 'dotnet publish', working folder '/tmp/samcli/source/bin/Release/net6.0/publish'
... dotnet publish "/tmp/samcli/source" --output "/tmp/samcli/source/bin/Release/net6.0/publish" --configuration "Release" --framework "net6.0" --runtime linux-x64 /p:GenerateRuntimeConfigurationFiles=true --self-contained False
... publish: MSBuild version 17.3.2+561848881 for .NET
... publish:   Determining projects to restore...
... publish:   Restored /tmp/samcli/source/sam-app.csproj (in 4.45 sec).
... publish: /tmp/samcli/source/Controllers/BooksController.cs(3,10): error CS1002: ; expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Program.cs(5,10): error CS1002: ; expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Controllers/BooksController.cs(4,10): error CS1002: ; expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Controllers/BooksController.cs(6,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/BookRepository.cs(3,10): error CS1002: ; expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/BookRepository.cs(5,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/BookRepository.cs(5,14): error CS1514: { expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Controllers/BooksController.cs(6,14): error CS1514: { expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/BookRepository.cs(6,1): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Controllers/BooksController.cs(6,30): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Entities/Book.cs(3,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Controllers/BooksController.cs(104,2): error CS1513: } expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Entities/Book.cs(3,14): error CS1514: { expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Entities/Book.cs(3,27): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Entities/Book.cs(30,2): error CS1513: } expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/IBookRepository.cs(1,10): error CS1002: ; expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/IBookRepository.cs(3,19): error CS0116: A namespace cannot directly contain members such as fields, methods or statements [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/IBookRepository.cs(3,14): error CS1514: { expected [/tmp/samcli/source/sam-app.csproj]
... publish: /tmp/samcli/source/Repositories/IBookRepository.cs(4,1): error CS1022: Type or namespace definition, or end-of-file expected [/tmp/samcli/source/sam-app.csproj]
ERROR: The dotnet publish command return unsuccessful error code

Build Failed

Steps to reproduce:

  1. Run sam init
  2. Choose 7 (Serverless API)
  3. Choose .net6 as runtime
  4. Use default answer for the remaining questions
  5. run sam build -u

Observed result:

Error out with the stacktrace in the description.

Expected result:

Operation should be completed without errors

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

{ "version": "1.93.0", "system": { "python": "3.11.3", "os": "Linux-5.4.247-169.350.amzn2int.x86_64-x86_64-with-glibc2.26" }, "additional_dependencies": { "docker_engine": "20.10.23", "aws_cdk": "Not available", "terraform": "1.5.0" }, "available_beta_feature_env_vars": [ "SAM_CLI_BETA_FEATURES", "SAM_CLI_BETA_BUILD_PERFORMANCE", "SAM_CLI_BETA_TERRAFORM_SUPPORT", "SAM_CLI_BETA_RUST_CARGO_LAMBDA" ] }

moelasmar commented 11 months ago

I think the issue is related setting the application name to contain dashes in the name. If you used a name without dashes like samapp, sam build will finish successfully, but sam local invoke does not work.

moelasmar commented 10 months ago

Patch is released in v1.96.0. Closing