question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'dotnet lambda publish-layer' fails in .NET 6 with ‘--enable-package-optimization true’

See original GitHub issue

Describe the bug

When trying to publish a .NET 6 layer, if you try to enable package optimizations, you will get an exception complaining about crossgen not existing in the tools directory of the .NET 6 SDK. It seems crossgen is no longer included with .NET 6 tools. And it sounds like this is by design according to this issue: https://github.com/dotnet/sdk/issues/24752

Example command that throws the error: dotnet lambda publish-layer dotnetsixlayer --layer-type runtime-package-store --s3-bucket my-layer-store-bucket --region us-east-1 --package-manifest ./layer-test-manifest.csproj --enable-package-optimization true --framework net6

Either removing the --enable-package-optimization true or downgrading to .NET 5 fixes the problem.

Expected Behavior

Publishes the layer to the store

Current Behavior

Amazon Lambda Tools for .NET Core applications (5.3.0)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet
	
Warning: Package optimization has been enabled. Be sure to run this on an Amazon Linux environment or the optimization might not be compatbile with the Lambda runtime.
Converted ASP.NET Core project file to temporary package manifest file.
... invoking 'dotnet store' for manifest /tmp/tmpzG6rga.tmp into output directory /tmp/dotnetsixlayer-637849539422701007/dotnetcore/store
... store: Microsoft (R) Build Engine version 17.1.0+ae57d105c for .NET
... store: Copyright (C) Microsoft Corporation. All rights reserved.
... store:   Determining projects to restore...
... store:   Restored /tmp/tmpzG6rga.tmp (in 377 ms).
... store: /usr/share/dotnet/sdk/6.0.201/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.CrossGen.targets(82,5): error NETSDK1016: Unable to find resolved path for '/home/ec2-user/.nuget/packages/microsoft.netcore.app.runtime.linux-x64/6.0.3/runtimes/linux-x64/native/../../../tools/crossgen'. [/tmp/tmpzG6rga.tmp]
Error executing the 'dotnet store' command

Reproduction Steps

On an AL2 VM, create a file layer-test-manifest.csproj with a NuGet reference in it, then run this command: dotnet lambda publish-layer dotnetsixlayer --layer-type runtime-package-store --s3-bucket my-layer-store-bucket --region us-east-1 --package-manifest ./layer-test-manifest.csproj --enable-package-optimization true --framework net6

Possible Solution

This open issue mentions using FrameworkReferences

Additional Information/Context

No response

Targeted .NET platform

.NET 6

CLI extension version

Package Id Version Commands

amazon.lambda.testtool-3.1 0.12.1 dotnet-lambda-test-tool-3.1 amazon.lambda.testtool-5.0 0.12.0 dotnet-lambda-test-tool-5.0 amazon.lambda.testtool-6.0 0.12.1 dotnet-lambda-test-tool-6.0 amazon.lambda.tools 5.3.0 dotnet-lambda nbgv 3.4.255 nbgv

Environment details (OS name and version, etc.)

Windows 10, Amazon Linux 2

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Beau-Gosse-devcommented, May 2, 2022

@ashishdhingra it looks like Microsoft is removing support for dotnet store all together. Do we have a plan to keep functionality with .NET Lambda Layers some other way?

0reactions
controdavecommented, Oct 10, 2022

@controdave There are 2 workarounds for publishing a layer still, do either of these help for now?

Either removing the --enable-package-optimization true or downgrading to .NET 5 fixes the problem.

Awe shucks, will there be a performance knock at all with remove package optimization? Thank you sir!

Read more comments on GitHub >

github_iconTop Results From Across the Web

AWS Lambda layers with .NET Core
To tell the publish-layer command to optimize the layer, set the --enable-package-optimization switch to true. Upcoming AWS Toolkit for Visual ...
Read more >
Unable to run a .NET6 container image in AWS lambda
I am trying to run a .NET6 image in AWS lambda and it is failing with error: { "errorMessage": "RequestId: 5aca05-**** Error: Runtime...
Read more >
Using the new .NET 6.0 runtime in AWS Lambda - YouTube
In this session, Norm Johanson, Senior Software Dev Engineer for AWS SDKs and Tools joins Julian Wood to talk about how the newly...
Read more >
Dotnet fails to install tools - Microsoft Q&A
Lambda.Tools or your local dotnet tool, I tried your shared commands and they are works fine. If all .NET tools cannot be installed,...
Read more >
Building .NET Core AWS Lambda with ReadyToRun on ...
It has to be set to false for AWS Lambda. The flag tells the compiler that the application will be run on a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found