简体   繁体   中英

Running dotnet watch run in docker container breaks Nuget package references

I have a docker-compose file where I start the database and the asp.net server with dotnet watch run like this:

backend:
   image: mcr.microsoft.com/dotnet/sdk:6.0

   depends_on:
     - db
   environment:
     DB_HOST: db
     DB_NAME: db
     DB_USERNAME: ${DB_USER}
     DB_PASSWORD: ${DB_PW}
     ASPNETCORE_ENVIRONMENT: Development
   ports:
     - 7293:7293
   volumes:
     - ./:/app
   working_dir: /app
   command: 'dotnet watch run --urls "http://0.0.0.0:7293"'

As you can see I mount the entire project directory in the container.

Now this runs fine and reloads on changes.

But as soon as the container starts in Visual Studio all the references to Nuget packages get marked red and can't be resolved anymore.

There is a .dockerignore file but I don't think anything in here is really relevant. But here is it anyways:

.dockerignore :

**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md

I know this has something to do with project restore but nothing I tried helped. --no-restore made it just not run at all with an exception that it couldn't find the reference to one of the packages.

Any ideas how to avoid this?

Ok I figured it out. Mounting Apperently doesn't care about .dockerignore . I have to exclude the obj directory in the mount. So I just mount a empty directory like this.

backend:
    ...
    volumes:
      - ./:/app
      - /app/obj # <- directory won't be mounted
    working_dir: /app
    command: 'dotnet watch run --urls "http://0.0.0.0:7293"'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM