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

dotnet lambda package fails with source generators #334

Closed petro2050 closed 1 week ago

petro2050 commented 3 weeks ago

Describe the bug

When I run dotnet lambda package -o output.zip -c Release -f net8.0 on a Mac M1 computer, I get CSC : error CS8034: Unable to load Analyzer assembly for one of the dependent projects which is a source generator. The same command succeeds in Github Actions since the build server is running Linux.

It seems internally dotnet lambda package sets publish runtime identifier to linux-x64. On Mac, this seems to work for .NET 8 projects, but it fails for a source generator using .NET Standard 2.0.

Expected Behavior

dotnet lambda package should run successfully on ARM-based Mac when the lambda uses a dependent source generator.

Current Behavior

Compilation throws CSC : error CS8034: Unable to load Analyzer assembly

Reproduction Steps

See the description

Possible Solution

No response

Additional Information/Context

No response

Targeted .NET platform

.NET 8 for the lambda and other dependent projects except for a source generator project built in .NET Standard 2.0.

CLI extension version

dotnet lambda package

Environment details (OS name and version, etc.)

macOS Sonoma

normj commented 3 weeks ago

What happens when you run dotnet publish -c Release -c Release -f net8.0 in the project directory?

petro2050 commented 3 weeks ago

this works, but it generates artifacts for osx-arm64.

if i run dotnet publish -c Release -f net8.0 -r linux-x64, it will fail with the same error.

in both runs, i see a non-fatal error:

error NETSDK1005: Assets file {project.assets.json for the generator} doesn't have a target for 'net8.0'. Ensure that restore has run and that you have included 'net8.0' in the TargetFrameworks for your project.

so it seems the issue may not be with lambda.

normj commented 2 weeks ago

Yeah it sounds like you have a regular .NET build issue. When you figure out I would be curious what the problem was in case we hear others having the problem. Is the source generator a public generator on NuGet?

petro2050 commented 2 weeks ago

it's not. it's a project reference and the generator is in the same solution as the referencing project.

bhoradc commented 1 week ago

Hi @petro2050,

Based on the information shared above, it appears that the issue you faced was related to your local .NET build environment and not directly related to the AWS SDK for .NET or the AWS Extensions for .NET CLI. Therefore, I will proceed to close this issue.

We appreciate if you are able to share the solution for your problem, which would benefit other users who may encounter similar issues.

Regards, Chaitanya

github-actions[bot] commented 1 week ago

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.