Skip to content

Conversation

willbush
Copy link
Contributor

@willbush willbush commented May 19, 2022

Summary

Note added resolution is similar to netsdk1064.

Here are repeatable steps to repro the issue:

$ dotnet new worker --name dotnetapp
$ cd dotnetapp
$ curl https://raw.githubusercontent.com/dotnet/dotnet-docker/main/samples/dotnetapp/Dockerfile.alpine-x64-slim > Dockerfile
$ docker build .

Observe the error NETSDK1047 after the above command.

Adding dockerignore file to ignore bin and obj solves the error:

$ echo "**/bin/" >> .dockerignore
$ echo "**/obj/" >> .dockerignore
$ docker build .

Full console output

$ dotnet --version
6.0.202
$ dotnet new worker --name dotnetapp
The template "Worker Service" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on /home/will/code/dotnetapp/dotnetapp.csproj...
  Determining projects to restore...
  Restored /home/will/code/dotnetapp/dotnetapp.csproj (in 230 ms).
Restore succeeded.

$ cd dotnetapp
$ curl https://raw.githubusercontent.com/dotnet/dotnet-docker/main/samples/dotnetapp/Dockerfile.alpine-x64-slim > Dockerfile
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   854  100   854    0     0  27326      0 --:--:-- --:--:-- --:--:-- 27548

$ docker build .
Sending build context to Docker daemon  80.38kB
Step 1/10 : FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
 ---> 0124e89c43c7
Step 2/10 : WORKDIR /source
 ---> Using cache
 ---> 1554014dffe5
Step 3/10 : COPY *.csproj .
 ---> 01caeda5ca14
Step 4/10 : RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true
 ---> Running in 926d1062053f
  Determining projects to restore...
  Restored /source/dotnetapp.csproj (in 16.04 sec).
Removing intermediate container 926d1062053f
 ---> 5531fcf3a003
Step 5/10 : COPY . .
 ---> b25de1cd476a
Step 6/10 : RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
 ---> Running in 8c271c93794d
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/6.0.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1047: Assets file '/source/obj/project.assets.json' doesn't have a target for 'net6.0/linux-musl-x64'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. You may also need to include 'linux-musl-x64' in your project's RuntimeIdentifiers. [/source/dotnetapp.csproj]
The command '/bin/sh -c dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true' returned a non-zero code: 1

$ echo "**/bin/" >> .dockerignore

$ echo "**/obj/" >> .dockerignore

$ docker build .
Sending build context to Docker daemon  10.75kB
Step 1/10 : FROM mcr.microsoft.com/dotnet/sdk:6.0-alpine AS build
 ---> 0124e89c43c7
Step 2/10 : WORKDIR /source
 ---> Using cache
 ---> 1554014dffe5
Step 3/10 : COPY *.csproj .
 ---> Using cache
 ---> 01caeda5ca14
Step 4/10 : RUN dotnet restore -r linux-musl-x64 /p:PublishReadyToRun=true
 ---> Using cache
 ---> 5531fcf3a003
Step 5/10 : COPY . .
 ---> 60d2efbfb4d0
Step 6/10 : RUN dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true
 ---> Running in c1cb541971e2
Microsoft (R) Build Engine version 17.2.0+41abc5629 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  dotnetapp -> /source/bin/release/net6.0/linux-musl-x64/dotnetapp.dll
  Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
  dotnetapp -> /app/
Removing intermediate container c1cb541971e2
 ---> 728b78522360
Step 7/10 : FROM mcr.microsoft.com/dotnet/runtime-deps:6.0-alpine-amd64
 ---> 00348c290af7
Step 8/10 : WORKDIR /app
 ---> Using cache
 ---> e96486253dab
Step 9/10 : COPY --from=build /app .
 ---> 59bb12244572
Step 10/10 : ENTRYPOINT ["./dotnetapp"]
 ---> Running in 6aee9eeb84d5
Removing intermediate container 6aee9eeb84d5
 ---> 0a54d15e22ce
Successfully built 0a54d15e22ce

Also see:

https://stackoverflow.com/questions/49392196/assets-file-obj-project-assets-json-doesnt-have-a-target-vs2017/72298520#72298520

My answer below:

I ran into the `NETSDK1047` when playing around with Docker in a brand new dotnet project created using `docker new worker` and the docker file from [dotnet-docker samples](https://github.com/dotnet/dotnet-docker/blob/3739ebf9f8fa2cc85eb3b73bc00fca467672771f/samples/dotnetapp/Dockerfile.alpine-x64-slim).

```
❯ docker build -t dockertest .

output elided...

/usr/share/dotnet/sdk/6.0.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1047: Assets file '/source/obj/project.assets.json' doesn't have a target for 'net6.0/linux-musl-x64'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. You may also need to include 'linux-musl-x64' in your project's RuntimeIdentifiers. [/source/dockertest.csproj]
The command '/bin/sh -c dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true' returned a non-zero code: 1
dockertest on  main [✘] via .NET v6.0.202 🎯 net6.0
❯
```

The issue was because I forgot to add a `.dockerignore` [file](https://github.com/willbush/dockertest/blob/08ef0c3cd7d984af20902245d9573fdf3601223b/.dockerignore) ignoring the `bin` and `obj` directories.

I only realized why because I tried different Dockerfiles from the `dotnet-docker` repo and got a [different error](https://docs.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1064) which has this same resolution. I'll try to make a PR to the docs of `NETSDK1047` to add this resolution.
@willbush
Copy link
Contributor Author

I'm unable to find where in code this error message originates in the dotnet cli tool. I'm guessing it's closed source? An issue or PR to update that error message should also be done.

Copy link
Contributor

@tdykstra tdykstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this contribution. I'm just suggesting a change to the link text.

Co-authored-by: Tom Dykstra <tdykstra@microsoft.com>
@tdykstra tdykstra merged commit 645eaab into dotnet:main May 19, 2022
@willbush willbush deleted the docs/core/tools/sdk-errors/update-netsdk1005 branch May 19, 2022 19:21
baronfel pushed a commit to baronfel/dotnet-docs that referenced this pull request Jun 21, 2022
…29530)

* Mention adding dockerignore file as resolution to NETSDK1047

Also see:

https://stackoverflow.com/questions/49392196/assets-file-obj-project-assets-json-doesnt-have-a-target-vs2017/72298520#72298520

My answer below:

I ran into the `NETSDK1047` when playing around with Docker in a brand new dotnet project created using `docker new worker` and the docker file from [dotnet-docker samples](https://github.com/dotnet/dotnet-docker/blob/3739ebf9f8fa2cc85eb3b73bc00fca467672771f/samples/dotnetapp/Dockerfile.alpine-x64-slim).

```
❯ docker build -t dockertest .

output elided...

/usr/share/dotnet/sdk/6.0.300/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1047: Assets file '/source/obj/project.assets.json' doesn't have a target for 'net6.0/linux-musl-x64'. Ensure that restore has run and that you have included 'net6.0' in the TargetFrameworks for your project. You may also need to include 'linux-musl-x64' in your project's RuntimeIdentifiers. [/source/dockertest.csproj]
The command '/bin/sh -c dotnet publish -c release -o /app -r linux-musl-x64 --self-contained true --no-restore /p:PublishTrimmed=true /p:PublishReadyToRun=true /p:PublishSingleFile=true' returned a non-zero code: 1
dockertest on  main [✘] via .NET v6.0.202 🎯 net6.0
❯
```

The issue was because I forgot to add a `.dockerignore` [file](https://github.com/willbush/dockertest/blob/08ef0c3cd7d984af20902245d9573fdf3601223b/.dockerignore) ignoring the `bin` and `obj` directories.

I only realized why because I tried different Dockerfiles from the `dotnet-docker` repo and got a [different error](https://docs.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1064) which has this same resolution. I'll try to make a PR to the docs of `NETSDK1047` to add this resolution.
@Youssef1313
Copy link
Member

I'm unable to find where in code this error message originates in the dotnet cli tool. I'm guessing it's closed source? An issue or PR to update that error message should also be done.

It's here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants