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.

"sam build" for dotnetcore on Windows fails on first run

See original GitHub issue

Description

Briefly describe the bug you are facing.

Steps to reproduce

On Windows,

  1. sam init --runtime dotnetcore2.0
  2. sam build

Observed result

Please provide command output with --debug flag set.

...
Created publish archive (C:\Users\Desktop\dev\myapp\src\HelloWorld\.aws-sam\build\HelloWorldFunction\HelloWorld.zip).
Lambda project successfully packaged: C:\Users\Desktop\dev\myapp\src\HelloWorld\.aws-sam\build\HelloWorldFunction\HelloWorld.zip
Build Failed
Error: DotnetCliPackageBuilder:RunPackageAction - [Errno 2] No such file or directory: '.aws-sam\\build\\HelloWorldFunction\\HelloWorld.zip'
...

Expected result

Build succeeds

Describe what you expected.

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

  1. OS: Windows
  2. sam --version: 0.14.2

Add --debug flag to command you are running

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
wyllie2commented, May 20, 2021

I know this is an old thread but make sure that you have dotnet-lambda in your path. On MacOSX I used: export PATH=$PATH:~/.dotnet/tools

0reactions
rakkeshbishtcommented, Feb 25, 2021

“”" Actions for .NET dependency resolution with CLI Package “”"

import threading import os import logging

from aws_lambda_builders.actions import BaseAction, Purpose, ActionFailedError from aws_lambda_builders.workflow import BuildMode from .utils import OSUtils from .dotnetcli import DotnetCLIExecutionError

LOG = logging.getLogger(name)

class GlobalToolInstallAction(BaseAction): __lock = threading.Lock() __tools_installed = False

"""
A Lambda Builder Action which installs the Amazon.Lambda.Tools .NET Core Global Tool
"""

NAME = "GlobalToolInstall"
DESCRIPTION = "Install or update the Amazon.Lambda.Tools .NET Core Global Tool."
PURPOSE = Purpose.COMPILE_SOURCE

def __init__(self, subprocess_dotnet):
    super(GlobalToolInstallAction, self).__init__()
    self.subprocess_dotnet = subprocess_dotnet

def execute(self):
    # run Amazon.Lambda.Tools update in sync block in case build is triggered in parallel
    with GlobalToolInstallAction.__lock:
        LOG.debug("Entered synchronized block for updating Amazon.Lambda.Tools")

        # check if Amazon.Lambda.Tools updated recently
        if GlobalToolInstallAction.__tools_installed:
            LOG.info("Skipping to update Amazon.Lambda.Tools install/update, since it is updated recently")
            return

        try:
            LOG.debug("Installing Amazon.Lambda.Tools Global Tool")
            self.subprocess_dotnet.run(["tool", "install", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"])
            GlobalToolInstallAction.__tools_installed = True
        except DotnetCLIExecutionError as ex:
            LOG.debug("Error installing probably due to already installed. Attempt to update to latest version.")
            try:
                self.subprocess_dotnet.run(
                    ["tool", "update", "-g", "Amazon.Lambda.Tools", "--ignore-failed-sources"]
                )
                GlobalToolInstallAction.__tools_installed = True
            except DotnetCLIExecutionError as ex:
                raise ActionFailedError(
                    "Error configuring the Amazon.Lambda.Tools .NET Core Global Tool: " + str(ex)
                )

class RunPackageAction(BaseAction): “”" A Lambda Builder Action which builds the .NET Core project using the Amazon.Lambda.Tools .NET Core Global Tool “”"

NAME = "RunPackageAction"
DESCRIPTION = "Execute the `dotnet lambda package` command."
PURPOSE = Purpose.COMPILE_SOURCE

def __init__(self, source_dir, subprocess_dotnet, artifacts_dir, options, mode, os_utils=None):
    super(RunPackageAction, self).__init__()
    self.source_dir = source_dir
    self.subprocess_dotnet = subprocess_dotnet
    self.artifacts_dir = artifacts_dir
    self.options = options
    self.mode = mode
    self.os_utils = os_utils if os_utils else OSUtils()

def execute(self):
    try:
        LOG.debug("Running `dotnet lambda package` in %s", self.source_dir)

        zipfilename = os.path.basename(os.path.normpath(self.source_dir)) + ".zip"
        zipfullpath = os.path.abspath(os.path.join(self.artifacts_dir, zipfilename))

        arguments = ["lambda", "package", "--output-package", zipfullpath]

        LOG.debug("Zip full path Running `dotnet lambda package` in %s", zipfullpath)
        if self.mode and self.mode.lower() == BuildMode.DEBUG:
            LOG.debug("Debug build requested: Setting configuration to Debug")
            arguments += ["--configuration", "Debug"]

        if self.options is not None:
            for key in self.options:
                if str.startswith(key, "-"):
                    arguments.append(key)
                    arguments.append(self.options[key])

        self.subprocess_dotnet.run(arguments, cwd=self.source_dir)

        # The dotnet lambda package command outputs a zip file for the package. To make this compatible
        # with the workflow, unzip the zip file into the artifacts directory and then delete the zip archive.
        self.os_utils.expand_zip(zipfullpath, self.artifacts_dir)

    except DotnetCLIExecutionError as ex:
        raise ActionFailedError(str(ex))
Read more comments on GitHub >

github_iconTop Results From Across the Web

"sam build" for dotnetcore on Windows fails on first run #1101
Description Briefly describe the bug you are facing. Steps to reproduce On Windows, sam init --runtime dotnetcore2.0 sam build Observed ...
Read more >
.net - sam build error - Command 'dotnet-lambda' conflicts with ...
So to rectify ( on windows ) go to your users folder/dotnet/tools/ and delete the 'dotnet-lambda' folder. Try the install again and see...
Read more >
sam build - AWS Serverless Application Model
The sam build command processes your AWS SAM template file, application code, and any applicable language-specific files and dependencies. The command also ...
Read more >
CoreWCF 1.0 has been Released, WCF for .NET Core and ...
The CoreWCF Project team has released the 1.0 version of CoreWCF, a port of WCF to the .NET Core platform. It provides a...
Read more >
How to run ASP.NET Core & SQL Server from Docker
We will use EF Core to interact with the SQL Server Docker container. The full working solution can be found in this Github...
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