Dotnet-docker: project.assets.json not found

Created on 25 Apr 2017  路  16Comments  路  Source: dotnet/dotnet-docker

Hi,
I try to run dotnet in a docker container. So i created a project on osx (with Rider from Jetbrains).
I have a docker-compose file and a dockerfile. If i build the container, evrything is fine, but if i want to start up the dockerfile, i get an error message:

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5): error : Assets file '/Users/eld/Documents/dashboard/IdentityServer/IdentityServer/obj/project.assets.json' not found.
Run a NuGet package restore to generate this file. [/app/IdentityServer.csproj]

When i do a restore nothing change. (without docker the project works fine)
/Users/eld/Documents/dashboard/IdentityServer/IdentityServer/obj/project.assets.json this is the correct path and there is a project.assets.json too. I don麓t understand what is wrong here.

i use this dockerfile:

FROM microsoft/dotnet:1.1-sdk

WORKDIR /app/
ADD . /app/
RUN dotnet restore

EXPOSE 5000
ENTRYPOINT ["dotnet", "run"]

folder overview:
-project
-bin
-config
-Controllers
-obj
_-_ project.assests.json
-views
-wwwroot
Program.cs
Startup.cs
project.csproj

Can someone help me?

question

Most helpful comment

Try adding a .dockerignore file next to your Dockerfile that contains

bin
obj

Alternatively you can delete these local directories prior to running docker build.

All 16 comments

@eld1887, Is IdentifyServer a project referenced from your Dockerized project? If so it needs to be accessible within the Dockerfile.

On a related note, is there a reason that you do not build your app as part of the Dockerfile? When you use ENTRYPOINT ["dotnet", "run"], the app is not built until you run the Docker image. This is not efficient because if you run the Docker image multiple times, the app will get compiled each time. A pattern I prefer using is the following.

FROM microsoft/dotnet:1.1-sdk
WORKDIR /app

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN dotnet restore

# copy and build everything else
COPY . .
RUN dotnet publish -c Release -o out
ENTRYPOINT ["dotnet", "out/<your project name>.dll"]

The reason to copy the csproj as a separate step is so that docker can utilize its layer cache each time you build. If the csproj doesn't change the cached layer is used and dotnet restore does not have to be rerun.

Thanks for your help and your modified dockerfile.
but if i run it i get after:
RUN dotnet publish -c Release -o out the following execption (its the same error msg as before):

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(154,5): error : Assets file '/Users/andreas/Documents/dashboard/IdentityServer/IdentityServer/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/IdentityServer.csproj]

The Dockerfile pattern I suggested was an orthogonal suggestion, I didn't intend to imply it would fix this issue.

Is IdentifyServer a project referenced from your project? Can you share you csproj file?

ah ok thanks for the hint.
IdentityServer is the name of my project folder or what do you mean with : referenced from my project? (sorry i麓m new to docker)
My identityServer.csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="IdentityServer4">
      <Version>1.5.0</Version>
    </PackageReference>
    <PackageReference Include="IdentityServer4.AccessTokenValidation">
      <Version>1.2.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
  </ItemGroup>
</Project>

I hope it can help you.
Thanks in advance

Try adding a .dockerignore file next to your Dockerfile that contains

bin
obj

Alternatively you can delete these local directories prior to running docker build.

hi,
i tried it with dockerignore and after i run the dockerfile with a docker-compose file and the command docker-compose build, i get an error message at line: RUN dotnet publish -c Release -o out

Building identityserver
Step 1/7 : FROM microsoft/dotnet:1.1-sdk
 ---> 51135eb30571
Step 2/7 : WORKDIR /app
 ---> Using cache
 ---> 1683302ee13a
Step 3/7 : COPY /IdentityServer/IdentityServer.csproj .
 ---> Using cache
 ---> bd3bcafd2c1f
Step 4/7 : RUN dotnet restore
 ---> Using cache
 ---> 6e604aff0f64
Step 5/7 : COPY ./IdentityServer/ .
 ---> 2bba0a1ae2b8
Removing intermediate container d3a046548ab8
Step 6/7 : RUN dotnet publish -c Release -o out
 ---> Running in 97867e2a5124
Microsoft (R) Build Engine version 15.1.548.43366
Copyright (C) Microsoft Corporation. All rights reserved.

/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(154,5): error : Assets file '/Users/andreas/Documents/dashboard/IdentityServer/IdentityServer/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/IdentityServer.csproj]
/tmp/.NETCoreApp,Version=v1.1.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [/app/IdentityServer.csproj]
obj/Release/netcoreapp1.1/IdentityServer.AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]
obj/Release/netcoreapp1.1/IdentityServer.AssemblyInfo.cs(7,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]
obj/Release/netcoreapp1.1/IdentityServer.AssemblyInfo.cs(8,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]
obj/Release/netcoreapp1.1/IdentityServer.AssemblyInfo.cs(9,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]
obj/Release/netcoreapp1.1/IdentityServer.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]

and so on

at the end of the error message:

Startup.cs(41,16): error CS0518: Predefined type 'System.Void' is not defined or imported [/app/IdentityServer.csproj]
Startup.cs(15,24): error CS0518: Predefined type 'System.Object' is not defined or imported [/app/IdentityServer.csproj]
Startup.cs(15,24): error CS0246: The type or namespace name 'IHostingEnvironment' could not be found (are you missing a using directive or an assembly reference?) [/app/IdentityServer.csproj]
Startup.cs(15,9): error CS0518: Predefined type 'System.Void' is not defined or imported [/app/IdentityServer.csproj]
/usr/share/dotnet/sdk/1.0.1/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(92,5): error : Assets file '/Users/andreas/Documents/dashboard/IdentityServer/IdentityServer/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/app/IdentityServer.csproj]
ERROR: Service 'identityserver' failed to build: The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1

it seems that the command RUN dotnet restore isn麓t executed

It sure looks like the bin and obj from your local build are still getting pulled into the image when building. What believe is happening is that when Step 5 is being run, the bin and obj from your local build are getting copied into the image and overriding the results of Step 4. I see your Dockerfile is not in the same directory as your project. Based on this, the .dockerignore I sent you wouldn't work as expected. To verify this is the case, can you try the following Dockerfile?

FROM microsoft/dotnet:1.1-sdk
WORKDIR /app
COPY ./IdentityServer/ .
RUN dotnet clean
RUN dotnet restore
RUN dotnet publish -c Release -o out

thanks for your patience.
Tested it with your new dockerfile and the result is that it successfully build the container.
if i try to bringing up the container i get these message:

Andreass-MBP:dashboard andreas$ docker-compose up
Recreating identityserver
Attaching to identityserver
identityserver exited with code 0

btw this is my docker-compose file (maybe its helpful):

identityserver:
    build: ./IdentityServer/
    dockerfile: ./IdentityServer/dockerfile
    container_name: identityserver
    volumes:
      - ./IdentityServer/IdentityServer/:/app/
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "5000:5000"

file structur:

dashboard
  /identityServer
  --/identityserver
  ----/Controller
  ----/bin
  ----/Views
  ----/wwwroot
  ----/obj
  ----Startup.cs
  ----Program.cs
  ----dockerfile
  ----.dockerignore
  --IdentityServer.sln
  docker-compose.yml

What is the purpose of the volume in your compose file? Isn't this overriding what you built in your Dockerfile?

normally i used volumes to see the changes at the implementation directly in the container (without restarting the docker container) for a dotnet container its maybe not the best practice.

But if i delete the volumes i get the same error message:

Andreass-MBP:dashboard andreas$ docker-compose up
Recreating identityserver
Attaching to identityserver
identityserver exited with code 0

thanks for your help

@eld1887 - it is really hard for me to help much more without seeing the source. If you want to share it with me I would be willing to take a look (msimons is my microsoft.com alias). Alternatively I would suggest setting up an empty aspnetcore project and Dockerize that. You could follow the example here

Hi Michael,
i can only repeat me: Thanks for your help.
i tried the example and i get the same error. Its builds correctly, but at starting up i get an error:

Andreass-MBP:emtpyproject andreas$ docker-compose up
Creating emtpyproject
Attaching to emtpyproject
emtpyproject exited with code 0

My procedure:
created a project with JetBrains Rider
add docker-composer.yml
and add a docker file.
thats it.

How can i send you my code? via email? which code you want? is my empty project enough (its the same error as above)?
greetings

can be closed. I done it myself.
Thanks for your help

Great news. Care to elaborate on what the problem/solution was? Someone else may benefit for your learning.

i restructured my project and clone the project folder with volumes at the docker-compose.yml to the container. At the dockerfile i use a shellscript and in this script i work with dotnet commands and the exact locatioin of my .csproj

example: dotnet restore /app/project.csproj

if you do a RUN LS in the build you will see there is a obj directory created.

I fixed this by adding
/obj
/bin
to the .dockerignore file

  • node_modules
    npm-debug.log
    Dockerfile*
    docker-compose*
    .dockerignore
    .git
    .gitignore
    .env
    */bin
    */obj
    /obj
    /bin
    README.md
    LICENSE
    .vscode
Was this page helpful?
0 / 5 - 0 ratings

Related issues

agr picture agr  路  3Comments

MichaelSimons picture MichaelSimons  路  5Comments

girishgouda picture girishgouda  路  7Comments

TheYorkshireDev picture TheYorkshireDev  路  5Comments

natemcmaster picture natemcmaster  路  5Comments