Skip to content

Bug: Building project in VSCode invalidates sam cache #8572

@cbroxton

Description

@cbroxton

Description:

I have a .NET 10 AOT sam project with many functions with a structure like the following...

template.yml
MyApp.slnx
samconfig.toml
.aws-sam/
src/
  Functions/
    Function1/
      Function.cs
      Function 1.csproj
    Function2/
      Functions.cs
      Function2.csproj
    ...

I am editing my project in VSCode, whenever I run sam build from the root of the solution I get a bunch of red squiggly lines in my code about missing namespaces etc until I run another solution build. The problem is that after that the build cache becomes invalid even though no changes have happened and my build takes a very long time because it has to rebuild every function from scratch again.

Steps to reproduce:

  1. Create a project with the above structure and .NET 10 functions with a csproj similar to the below...
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AWSProjectType>Lambda</AWSProjectType>
    <AssemblyName>bootstrap</AssemblyName>
    <PublishAot>true</PublishAot>
    <PublishTrimmed>true</PublishTrimmed>
    <StripSymbols>true</StripSymbols>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
    <IncludeAllContentForSelfExtract>true</IncludeAllContentForSelfExtract>
    <TieredCompilation>false</TieredCompilation>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Shared\MyApp.DataAccess\MyApp.DataAccess.csproj" />
    <ProjectReference Include="..\..\Shared\MyApp.Shared\MyApp.Shared.csproj" />
    <TrimmerRootAssembly Include="MyApp.DataAccess" />
    <TrimmerRootAssembly Include="MyApp.Shared" />
  </ItemGroup>
</Project>

<img width="1399" height="255" alt="Image" src="https://github.com/user-attachments/assets/f95fc756-a9df-41df-b4ae-1b067f0b5410" />

  1. Build the solution in vscode
  2. Run sam build and observe errors in VSCode
  3. Run sam build again and observe that the cache is now invalid.

Observed result:

Showing build output for a single function.

2026-01-14 12:20:00,250 | DotnetCliPackageBuilder:RunPackageAction succeeded
2026-01-14 12:20:00,257 | Running incremental build for runtime dotnet10 for following resources (Function1Function)
2026-01-14 12:20:00,554 | Cache is invalid, running build and copying resources for following functions (Function1Function)
2026-01-14 12:20:00,554 | Building codeuri: C:\code\MyApp.API\src\Functions\MyApp.Function1 runtime: dotnet10 architecture: x86_64 functions: Function1Function
2026-01-14 12:20:00,555 | Building to following folder C:\code\MyApp.API\.aws-sam\build\Function1Function
2026-01-14 12:20:00,556 | Loading workflow module 'aws_lambda_builders.workflows'
2026-01-14 12:20:00,556 | Found workflow 'DotnetCliPackageBuilder' to support capabilities 'Capability(language='dotnet', dependency_manager='cli-package', application_framework=None)'
2026-01-14 12:20:00,557 | Workflow DotnetCliPackageBuilder does not support value "False" for building in source. Using default value "True".
2026-01-14 12:20:00,557 | Running workflow 'DotnetCliPackageBuilder'
2026-01-14 12:20:00,558 |  Running DotnetCliPackageBuilder:GlobalToolInstall
2026-01-14 12:20:00,558 | Entered synchronized block for updating Amazon.Lambda.Tools
2026-01-14 12:20:00,558 | Skipping to update Amazon.Lambda.Tools install/update, since it is updated recently
2026-01-14 12:20:00,559 | DotnetCliPackageBuilder:GlobalToolInstall succeeded
2026-01-14 12:20:00,559 |  Running DotnetCliPackageBuilder:RunPackageAction
2026-01-14 12:20:00,560 | Running `dotnet lambda package` in C:\code\MyApp.API\src\Functions\MyApp.Function1
2026-01-14 12:20:00,560 | executing dotnet: ['dotnet.exe', 'lambda', 'package', '--output-package', 'C:\\code\\MyApp.API\\.aws-sam\\build\\Function1Function\\MyApp.Function1.zip',
'--function-architecture', 'x86_64', '--msbuild-parameters', '--runtime linux-x64']
2026-01-14 12:20:17,241 | Amazon Lambda Tools for .NET Core applications (6.0.3)
Project Home: https://github.com/aws/aws-extensions-for-dotnet-cli, https://github.com/aws/aws-lambda-dotnet

Executing publish command
Starting container for native AOT build using build image: mcr.microsoft.com/dotnet/sdk:10.0-aot.
... invoking 'docker run --name tempLambdaBuildContainer-667f0016-ea15-4062-812f-143bb15fb17d --rm --volume "C:\code\MyApp.API":/tmp/source/ -i mcr.microsoft.com/dotnet/sdk:10.0-aot dotnet     
publish "/tmp/source/src/Functions/MyApp.Function1" --output "/tmp/source/src/Functions/MyApp.Function1\bin\Release\net10.0\publish" --configuration "Release" --framework "net10.0"        
--runtime linux-x64 /p:GenerateRuntimeConfigurationFiles=true --self-contained True  /p:StripSymbols=true' from directory C:\code\MyApp.API
... docker run:   Determining projects to restore...
... docker run:   Restored /tmp/source/src/Functions/MyApp.Function1/MyApp.Function1.csproj (in 11 sec).
... docker run:   Restored /tmp/source/src/Shared/MyApp.Shared/MyApp.Shared.csproj (in 11 sec).
... docker run:   Restored /tmp/source/src/Shared/MyApp.Models/MyApp.Models.csproj (in 11 sec).
... docker run:   Restored /tmp/source/src/Shared/MyApp.DataAccess/MyApp.DataAccess.csproj (in 11 sec).
... docker run:   MyApp.Shared -> /tmp/source/src/Shared/MyApp.Shared/bin/Release/net10.0/MyApp.Shared.dll
... docker run:   MyApp.Models -> /tmp/source/src/Shared/MyApp.Models/bin/Release/net10.0/MyApp.Models.dll
... docker run:   MyApp.DataAccess -> /tmp/source/src/Shared/MyApp.DataAccess/bin/Release/net10.0/MyApp.DataAccess.dll
... docker run:   MyApp.Function1 -> /tmp/source/src/Functions/MyApp.Function1/bin/Release/net10.0/linux-x64/bootstrap.dll
... docker run:   MyApp.Function1 -> /tmp/source/src/Functions/MyApp.Function1/bin/Release/net10.0/publish/
Missing deps.json file. Skipping flattening runtime folder because  is an unrecognized format
Zipping publish folder C:\code\MyApp.API\src\Functions\MyApp.Function1\bin\Release\net10.0\publish to C:\code\MyApp.API\.aws-sam\build\Function1Function\MyApp.Function1.zip
Creating directory C:\code\MyApp.API\.aws-sam\build\Function1Function
... zipping: bootstrap
... zipping: MyApp.DataAccess.pdb
... zipping: MyApp.Models.pdb
... zipping: MyApp.Shared.pdb
Created publish archive (C:\code\MyApp.API\.aws-sam\build\Function1Function\MyApp.Function1.zip).
Lambda project successfully packaged: C:\code\MyApp.API\.aws-sam\build\Function1Function\MyApp.Function1.zip
Image

Expected result:

sam build should not interfere with builds in the IDE and sam build cache should still be usable after doing a build in the IDE.

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

{
  "version": "1.151.0",
  "system": {
    "python": "3.13.6",
    "os": "Windows-11-10.0.26100-SP0"
  },
  "additional_dependencies": {
    "container_engine": "Docker(v29.1.3)",
    "aws_cdk": "Not available",
    "terraform": "Not available"
  },
  "available_beta_feature_env_vars": [
    "SAM_CLI_BETA_FEATURES",
    "SAM_CLI_BETA_BUILD_PERFORMANCE",
    "SAM_CLI_BETA_TERRAFORM_SUPPORT",
    "SAM_CLI_BETA_PACKAGE_PERFORMANCE",
    "SAM_CLI_BETA_RUST_CARGO_LAMBDA"
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETPull requests that update .net codearea/buildsam build commandtype/bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions