Skip to content

Commit 645eaab

Browse files
authored
Mention adding dockerignore file as resolution to NETSDK1047 (#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.
1 parent 2308330 commit 645eaab

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

docs/core/tools/sdk-errors/netsdk1005.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ Here are some actions you can take that may resolve the error:
2323
* Delete the *obj* folder before building the project.
2424

2525
* Make sure that the missing target value is included in the `TargetFrameworks` property of your project.
26+
27+
* If you're building a Docker image, make sure the *.dockerignore* file ignores the *bin* and *obj* directories. For more information, see GitHub pull request [dotnet/docs #29530](https://github.com/dotnet/docs/pull/29530).

0 commit comments

Comments
 (0)