aws / aws/aws-extensions-for-dotnet-cli
'dotnet lambda publish-layer' fails in .NET 6 with ‘--enable-package-optimization true’
- Dominant language
- C#
- Stars
- 393
- Forks
- 90
- Avg merge
- 2d 19m
- Merged PRs (30d)
- 3
Description
### 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](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](https://github.com/dotnet/sdk/issues/24752) 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
Contributor guide
Research direction
Reproduce the `dotnet lambda publish-layer` command from the issue on an Amazon Linux 2 environment with .NET 6 and the example package manifest. Start with the `dotnet store` output and the referenced Microsoft.NET.CrossGen.targets failure, then review the linked .NET SDK issue about FrameworkReferences. Done means package optimization publishes the runtime layer successfully without the crossgen error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, csharp
- Domain
- cli, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100