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 87 forks source link

5.6.0 dotnet lambda package does not copy all files from publish folder #248

Closed stpanzer closed 1 year ago

stpanzer commented 1 year ago

Describe the bug

When running dotnet lambda package, the zip stage skips the PDB file. This breaks local debugging for SAM applications.

I've confirmed the previous behavior in 5.5.0 (see repro steps) was to copy the PDB file.

Expected Behavior

The PDB file to be copied into the zip.

Current Behavior

PDB file was not copied.

Reproduction Steps

radicaledward@work-panzer  ~/test/dotnettest  dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/radicaledward/test/dotnettest/dotnettest.csproj...
  Determining projects to restore...
  Restored /home/radicaledward/test/dotnettest/dotnettest.csproj (in 62 ms).
Restore succeeded.

 radicaledward@work-panzer  ~/test/dotnettest  dotnet lambda package
Amazon Lambda Tools for .NET Core applications (5.6.0)
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 '/home/radicaledward/test/dotnettest/bin/Release/net6.0/publish'
... dotnet publish "/home/radicaledward/test/dotnettest" --output "/home/radicaledward/test/dotnettest/bin/Release/net6.0/publish" --configuration "Release" --framework "net6.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-x64 --self-contained False
... publish: Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish:   Determining projects to restore...
... publish:   Restored /home/radicaledward/test/dotnettest/dotnettest.csproj (in 92 ms).
... publish:   dotnettest -> /home/radicaledward/test/dotnettest/bin/Release/net6.0/linux-x64/dotnettest.dll
... publish:   dotnettest -> /home/radicaledward/test/dotnettest/bin/Release/net6.0/publish/
Changed permissions on published file (chmod +rx dotnettest).
Changed permissions on published file (chmod +rx dotnettest.pdb).
Changed permissions on published file (chmod +rx dotnettest.dll).
Changed permissions on published file (chmod +rx dotnettest.runtimeconfig.json).
Changed permissions on published file (chmod +rx dotnettest.deps.json).
Zipping publish folder /home/radicaledward/test/dotnettest/bin/Release/net6.0/publish to /home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip
... zipping:   adding: dotnettest (deflated 63%)
... zipping:   adding: dotnettest.dll (deflated 59%)
... zipping:   adding: dotnettest.runtimeconfig.json (deflated 32%)
... zipping:   adding: dotnettest.deps.json (deflated 54%)
Created publish archive (/home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip).
Lambda project successfully packaged: /home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip

Note that this works fine on 5.5.0:

radicaledward@work-panzer  ~/test/dotnettest  dotnet tool uninstall --global Amazon.Lambda.Tools
Tool 'amazon.lambda.tools' (version '5.6.0') was successfully uninstalled.
 radicaledward@work-panzer  ~/test/dotnettest  dotnet tool install --global Amazon.Lambda.Tools --version 5.5.0
You can invoke the tool using the following command: dotnet-lambda
Tool 'amazon.lambda.tools' (version '5.5.0') was successfully installed.
 radicaledward@work-panzer  ~/test/dotnettest  dotnet lambda package
Amazon Lambda Tools for .NET Core applications (5.5.0)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Executing publish command
Deleted previous publish folder
... invoking 'dotnet publish', working folder '/home/radicaledward/test/dotnettest/bin/Release/net6.0/publish'
... dotnet publish --output "/home/radicaledward/test/dotnettest/bin/Release/net6.0/publish" --configuration "Release" --framework "net6.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-x64 --self-contained false
... publish: Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish:   Determining projects to restore...
... publish:   All projects are up-to-date for restore.
... publish:   dotnettest -> /home/radicaledward/test/dotnettest/bin/Release/net6.0/linux-x64/dotnettest.dll
... publish:   dotnettest -> /home/radicaledward/test/dotnettest/bin/Release/net6.0/publish/
Changed permissions on published file (chmod +rx dotnettest).
Changed permissions on published file (chmod +rx dotnettest.pdb).
Changed permissions on published file (chmod +rx dotnettest.dll).
Changed permissions on published file (chmod +rx dotnettest.runtimeconfig.json).
Changed permissions on published file (chmod +rx dotnettest.deps.json).
Zipping publish folder /home/radicaledward/test/dotnettest/bin/Release/net6.0/publish to /home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip
... zipping:   adding: dotnettest (deflated 63%)
... zipping:   adding: dotnettest.pdb (deflated 42%)
... zipping:   adding: dotnettest.dll (deflated 59%)
... zipping:   adding: dotnettest.runtimeconfig.json (deflated 32%)
... zipping:   adding: dotnettest.deps.json (deflated 54%)
Created publish archive (/home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip).
Lambda project successfully packaged: /home/radicaledward/test/dotnettest/bin/Release/net6.0/dotnettest.zip

Possible Solution

No response

Additional Information/Context

No response

Targeted .NET platform

6.0.302

CLI extension version

Package Id               Version         Commands
------------------------------------------------------
amazon.lambda.tools      5.6.0           dotnet-lambda
dotnet-ef                6.0.4           dotnet-ef
dotnet-symbol            1.0.212301      dotnet-symbol

Environment details (OS name and version, etc.)

WSL ubuntu

ashishdhingra commented 1 year ago

@stpanzer Looks like in Amazon.Lambda.Tools version 5.6.0, the change to skip dbg and pdb files was added at https://github.com/aws/aws-extensions-for-dotnet-cli/blob/599a3508d9c37e1e5784df76ba89abad1f49f7a9/src/Amazon.Lambda.Tools/LambdaPackager.cs#L592.

I do see in your log that you are using Release configuration per command dotnet publish "/home/radicaledward/test/dotnettest" --output "/home/radicaledward/test/dotnettest/bin/Release/net6.0/publish" --configuration "Release" --framework "net6.0" /p:GenerateRuntimeConfigurationFiles=true --runtime linux-x64 --self-contained False. The above logic appears to be common for release and debug configuration, however, unsure if we should include pdb files in Release configuration.

Needs review with the team.

Thanks, Ashish

normj commented 1 year ago

@stpanzer sorry for breaking your debug workflow. I'll work on getting a fix out quickly.

For background we have been working on adding Native AOT support and we wanted to not bundle the dbg files in, the native debug symbols file, because they are huge. We were over reaching by also removing pdb files to reduce executable size which aren't even generated for Native AOT. I'll change the code to only remove dbg files to unblock you. In the future we might add back a setting to optional exclude pdb files.

stpanzer commented 1 year ago

@normj @ashishdhingra Thanks for the quick responses!

Given the code linked above, I assume there isn't a workaround for 5.6.0?

Unfortunately, sam build will always update to the most recent version of Amazon.Lambda.Tools - https://github.com/aws/aws-lambda-builders/issues/347

I've been looking at patching the sam cli locally to stop this behavior but it's a bit more complicated than I'd hoped, and I'm no python dev 😄.

normj commented 1 year ago

The code is in the pipeline for release, so unless something unusual happens the fix should be out within the next couple hours.

Only work around till then I can think of is if you pull 5.5.0 into a local folder and set the folder up as a NuGet feed. Then put a nuget.config file that only has the local feed.

normj commented 1 year ago

Version 5.6.1 of Amazon.Lambda.Tools is out. Sorry again for the regression and thanks for letting us know.

normj commented 1 year ago

Closing since the fix has been released.

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.