Bug: sam build fails if Visual Studio is open
Description:
I am running sam build on directory https://github.com/aws-samples/serverless-dotnet-demo/tree/main/src/NET8MinimalAPI
If Visual Studio is open, I get an error message Permission denied in the .vs folder:
C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI main ≡
❯ sam build
Building codeuri: C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI runtime: provided.al2 architecture: x86_64 functions: ApiFunction
ApiFunction: Running CustomMakeBuilder:CopySource
Build Failed
Error: CustomMakeBuilder:CopySource - [Errno 13] Permission denied: 'C:\\projects\\aws-samples\\serverless-dotnet-demo\\src\\NET8MinimalAPI\\.vs\\NET8MinimalAPI\\FileContentIndex\\69c73d1c-9558-4ac2-8b30-e42e28097ef0.vsidx'
If I close Visual Studio sam build works fine.
Steps to reproduce:
- Windows 10
- Clone https://github.com/aws-samples/serverless-dotnet-demo/tree/main/src/NET8MinimalAPI
- Open sln in Visual Studio
- Run
sam build
Observed result:
error message above
Expected result:
It should not be necessary to close Visual Studio to run sam build
Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
- OS: Windows 10 22h2
-
sam --version: SAM CLI, version 1.123.0 - AWS region: n/a
# Paste the output of `sam --info` here
{
"version": "1.123.0",
"system": {
"python": "3.11.8",
"os": "Windows-10-10.0.19045-SP0"
},
"additional_dependencies": {
"docker_engine": "Not available",
"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_RUST_CARGO_LAMBDA"
]
}
Add --debug flag to command you are running
❯ sam build --debug
2025-02-12 16:56:37,416 | No config file found in this directory.
2025-02-12 16:56:37,419 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'C:\\projects\\aws-samples\\serverless-dotnet-demo\\src\\NET8MinimalAPI\\samconfig.toml'
2025-02-12 16:56:37,421 | Config file location: C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\samconfig.toml
2025-02-12 16:56:37,422 | Config file 'C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\samconfig.toml' does not exist
2025-02-12 16:56:37,427 | Using SAM Template at C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\template.yaml
2025-02-12 16:56:37,444 | OSError occurred while reading TOML file: [Errno 2] No such file or directory:
'C:\\projects\\aws-samples\\serverless-dotnet-demo\\src\\NET8MinimalAPI\\samconfig.toml'
2025-02-12 16:56:37,446 | Using config file: samconfig.toml, config environment: default
2025-02-12 16:56:37,447 | Expand command line arguments to:
2025-02-12 16:56:37,448 | --template_file=C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\template.yaml --mount_with=READ
--build_dir=.aws-sam\build --cache_dir=.aws-sam\cache
2025-02-12 16:56:37,613 | 'build' command is called
2025-02-12 16:56:37,617 | No Parameters detected in the template
2025-02-12 16:56:37,641 | There is no customer defined id or cdk path defined for resource ApiFunction, so we will use the resource logical id as the
resource id
2025-02-12 16:56:37,643 | There is no customer defined id or cdk path defined for resource Table, so we will use the resource logical id as the resource
id
2025-02-12 16:56:37,644 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as
the resource id
2025-02-12 16:56:37,646 | 0 stacks found in the template
2025-02-12 16:56:37,647 | No Parameters detected in the template
2025-02-12 16:56:37,663 | There is no customer defined id or cdk path defined for resource ApiFunction, so we will use the resource logical id as the
resource id
2025-02-12 16:56:37,664 | There is no customer defined id or cdk path defined for resource Table, so we will use the resource logical id as the resource
id
2025-02-12 16:56:37,665 | There is no customer defined id or cdk path defined for resource ServerlessHttpApi, so we will use the resource logical id as
the resource id
2025-02-12 16:56:37,666 | 3 resources found in the stack
2025-02-12 16:56:37,667 | Found Serverless function with name='ApiFunction' and CodeUri='./'
2025-02-12 16:56:37,668 | --base-dir is not presented, adjusting uri ./ relative to
C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\template.yaml
2025-02-12 16:56:37,674 | 3 resources found in the stack
2025-02-12 16:56:37,675 | Found Serverless function with name='ApiFunction' and CodeUri='./'
2025-02-12 16:56:37,677 | Instantiating build definitions
2025-02-12 16:56:37,680 | Same function build definition found, adding function (Previous: BuildDefinition(provided.al2,
C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI, Zip, , 71368360-c28d-489a-8c97-ed98d11bec7a, {}, {}, x86_64, []), Current:
BuildDefinition(provided.al2, C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI, Zip, , 9ea06547-46cd-4b66-a0de-33284cc3201d, {}, {},
x86_64, []), Function: Function({'function_id': 'ApiFunction', 'name': 'ApiFunction', 'functionname': 'ApiFunction', 'runtime': 'provided.al2',
'memory': 1024, 'timeout': 30, 'handler': 'ApiBootstrap', 'imageuri': None, 'packagetype': 'Zip', 'imageconfig': None, 'codeuri':
'C:\\projects\\aws-samples\\serverless-dotnet-demo\\src\\NET8MinimalAPI', 'environment': {'Variables': {'PRODUCT_TABLE_NAME': 'Table',
'LOG_GROUP_PREFIX': '/aws/lambda/net-8-minimal-', 'LOAD_TEST_TYPE': 'NET 8 Minimal API'}}, 'rolearn': None, 'layers': [], 'events': {'Api': {'Type':
'HttpApi', 'Properties': {'Path': '/{proxy+}', 'Method': 'ANY', 'ApiId': 'ServerlessHttpApi'}}}, 'metadata': {'SamResourceId': 'ApiFunction'},
'inlinecode': None, 'codesign_config_arn': None, 'architectures': ['x86_64'], 'function_url_config': None, 'function_build_info':
<FunctionBuildInfo.BuildableZip: ('BuildableZip', 'Regular ZIP function which can be build with SAM CLI')>, 'stack_path': '',
'runtime_management_config': None, 'logging_config': None}))
2025-02-12 16:56:37,686 | Building codeuri: C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI runtime: provided.al2 architecture: x86_64
functions: ApiFunction
2025-02-12 16:56:37,687 | Building to following folder C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.aws-sam\build\ApiFunction
2025-02-12 16:56:37,690 | Loading workflow module 'aws_lambda_builders.workflows'
2025-02-12 16:56:37,698 | Registering workflow 'CustomMakeBuilder' with capability 'Capability(language='provided', dependency_manager=None,
application_framework=None)'
2025-02-12 16:56:37,705 | Registering workflow 'DotnetCliPackageBuilder' with capability 'Capability(language='dotnet',
dependency_manager='cli-package', application_framework=None)'
2025-02-12 16:56:37,713 | Registering workflow 'GoModulesBuilder' with capability 'Capability(language='go', dependency_manager='modules',
application_framework=None)'
2025-02-12 16:56:37,724 | Registering workflow 'JavaGradleWorkflow' with capability 'Capability(language='java', dependency_manager='gradle',
application_framework=None)'
2025-02-12 16:56:37,731 | Registering workflow 'JavaMavenWorkflow' with capability 'Capability(language='java', dependency_manager='maven',
application_framework=None)'
2025-02-12 16:56:37,739 | Registering workflow 'NodejsNpmBuilder' with capability 'Capability(language='nodejs', dependency_manager='npm',
application_framework=None)'
2025-02-12 16:56:37,748 | Registering workflow 'NodejsNpmEsbuildBuilder' with capability 'Capability(language='nodejs',
dependency_manager='npm-esbuild', application_framework=None)'
2025-02-12 16:56:37,761 | Registering workflow 'PythonPipBuilder' with capability 'Capability(language='python', dependency_manager='pip',
application_framework=None)'
2025-02-12 16:56:37,768 | Registering workflow 'RubyBundlerBuilder' with capability 'Capability(language='ruby', dependency_manager='bundler',
application_framework=None)'
2025-02-12 16:56:37,776 | Registering workflow 'RustCargoLambdaBuilder' with capability 'Capability(language='rust', dependency_manager='cargo',
application_framework=None)'
2025-02-12 16:56:37,778 | Found workflow 'CustomMakeBuilder' to support capabilities 'Capability(language='provided', dependency_manager=None,
application_framework=None)'
2025-02-12 16:56:37,799 | Running workflow 'CustomMakeBuilder'
2025-02-12 16:56:37,801 | ApiFunction: Running CustomMakeBuilder:CopySource
2025-02-12 16:56:37,803 | File (.aws-sam) is in ignored set, skipping it
2025-02-12 16:56:37,803 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs
2025-02-12 16:56:37,804 | Copying directory metadata from source (C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs)
2025-02-12 16:56:37,805 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI
2025-02-12 16:56:37,806 | Copying directory metadata from source (C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI)
to destination (C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI)
2025-02-12 16:56:37,808 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices
2025-02-12 16:56:37,808 | Copying directory metadata from source
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices)
2025-02-12 16:56:37,810 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981
2025-02-12 16:56:37,812 | Copying directory metadata from source
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981)
2025-02-12 16:56:37,814 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db)
2025-02-12 16:56:37,818 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db-shm) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db-shm)
2025-02-12 16:56:37,822 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db-wal) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\CodeChunks.db-wal)
2025-02-12 16:56:37,825 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db)
2025-02-12 16:56:37,829 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db-shm) to
destination (C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db-shm)
2025-02-12 16:56:37,832 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db-wal) to
destination (C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\CopilotIndices\17.12.53.23981\SemanticSymbols.db-wal)
2025-02-12 16:56:37,836 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\DesignTimeBuild
2025-02-12 16:56:37,837 | Copying directory metadata from source
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\DesignTimeBuild) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\DesignTimeBuild)
2025-02-12 16:56:37,838 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\DesignTimeBuild\.dtbcache.v2) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\DesignTimeBuild\.dtbcache.v2)
2025-02-12 16:56:37,841 | Creating target folders at C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\FileContentIndex
2025-02-12 16:56:37,843 | Copying directory metadata from source
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\FileContentIndex) to destination
(C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\FileContentIndex)
2025-02-12 16:56:37,844 | Copying source file
(C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\FileContentIndex\69c73d1c-9558-4ac2-8b30-e42e28097ef0.vsidx) to
destination (C:\Users\pittle\AppData\Local\Temp\tmpp0ww5gjf\.vs\NET8MinimalAPI\FileContentIndex\69c73d1c-9558-4ac2-8b30-e42e28097ef0.vsidx)
2025-02-12 16:56:37,845 | CustomMakeBuilder:CopySource raised unhandled exception
Traceback (most recent call last):
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\workflow.py", line 374, in run
action.execute()
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\actions.py", line 115, in execute
copytree(
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\utils.py", line 87, in copytree
copytree(new_source, new_destination, ignore=ignore, include=include, maintain_symlinks=maintain_symlinks)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\utils.py", line 87, in copytree
copytree(new_source, new_destination, ignore=ignore, include=include, maintain_symlinks=maintain_symlinks)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\utils.py", line 87, in copytree
copytree(new_source, new_destination, ignore=ignore, include=include, maintain_symlinks=maintain_symlinks)
File "C:\Program Files\Amazon\AWSSAMCLI\runtime\Lib\site-packages\aws_lambda_builders\utils.py", line 90, in copytree
shutil.copy2(new_source, new_destination)
File "shutil.py", line 448, in copy2
File "shutil.py", line 256, in copyfile
PermissionError: [Errno 13] Permission denied:
'C:\\projects\\aws-samples\\serverless-dotnet-demo\\src\\NET8MinimalAPI\\.vs\\NET8MinimalAPI\\FileContentIndex\\69c73d1c-9558-4ac2-8b30-e42e28097ef0.vsi
dx'
Build Failed
I updated SAM to 1.133.0 and switched to using the --use-container flag. Still Fails
❯ sam --version
SAM CLI, version 1.133.0
❯ sam build --use-container
Starting Build inside a container
Building codeuri: C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI runtime: provided.al2 architecture: x86_64
functions: ApiFunction
Fetching public.ecr.aws/sam/build-provided.al2:latest-x86_64 Docker container image..................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
Mounting C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI as /tmp/samcli/source:ro,delegated, inside runtime container
Build Failed
Error: CustomMakeBuilder:CopySource - [Errno 13] Permission denied: '/tmp/samcli/source/.vs/NET8MinimalAPI/FileContentIndex/69c73d1c-9558-4ac2-8b30-e42e28097ef0.vsidx'
ApiFunction: Running CustomMakeBuilder:CopySource
I found a hack by following https://stackoverflow.com/questions/72237599/how-to-disable-that-new-filecontentindex-folder-and-vsidx-files-in-vs-2022 to delete the C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\Editor\ServiceHub\Indexing.servicehub.service.json and then deleting all files in C:\projects\aws-samples\serverless-dotnet-demo\src\NET8MinimalAPI\.vs\NET8MinimalAPI\FileContentIndex
While this allows the build to continue to the next problem, it's not the best solution.
Ideally, sam build should ignore the .vs folder completely.
Thank you for reporting this issue. We will try to reproduce the issue. We will reach out if we need additional information.
I think this might be related to the issue I am seeing where I get build errors when running the sam build docker container when attempting to publish a .net aot lambda with a project dependency.
https://github.com/aws/aws-extensions-for-dotnet-cli/discussions/364
Not the same error. Mine is throwing MSB4018 errors, but when I close VisualStudio the command works fine.