Skip to content

dotnet restore on 2.1 preview1 throws error instead of warning when project files are "missing" #6651

Closed

Description

@livarcocc

From @christiansparre on March 8, 2018 17:22

I was playing around with 2.1 preview 1 and trying to get a simple ASP.NET Core 2.1 preview1 app up and running on docker using the VS docker tools. But my docker-compose build failed because dotnet restore on 2.1 throws error MSB3202: The project file "/src/SomeApp.SomeLib/SomeApp.SomeLib.csproj" was not found.

But it is not isolated to docker, see the repo below where there is also a repro for 2.0 and 2.1 outside docker. And they behave very differently. Yes this is not really "normal" restore behavior, but all dotnet docker examples and the VS tooling does it this way with multistage builds and they explicitly suppress MSB3202 using -nowarn:msb3202,nu1503

I have not been able to find any known issues by searching the different dotnet repos. Is dotnet restore throwing errors, instead of warnings, a new expected behavior?

Also this is the most correct place I could find to post the issue, please redirect me elsewhere if there is a better place for it :)

Steps to reproduce

Code to reproduce can be found here: https://github.com/christiansparre/DotNet2.1RestoreBehavior

  • Create ASP.NET Core 2.1 web site
    • with Docker support (I used Linux)
  • Add another project, and reference in web app (does not really matter)
  • Change the Dockerfile to use the correct image versions (defaults to 2.1 that does not exist yet)
  • Run docker-compose build

Expected behavior

Expected dotnet restore to complete with out errors or warnings because of -nowarn:msb3202,nu1503 arguments

Actual behavior

Restore failed with

/usr/share/dotnet/sdk/2.1.300-preview1-008174/NuGet.targets(239,5): error MSB3202: The project file "/src/SomeApp.SomeLib/SomeApp.SomeLib.csproj" was not found. [/src/SomeApp.sln] /usr/share/dotnet/sdk/2.1.300-preview1-008174/NuGet.targets(239,5): error MSB3202: The project file "/src/docker-compose.dcproj" was not found. [/src/SomeApp.sln] ERROR: Service 'someapp' failed to build: The command '/bin/sh -c dotnet restore -nowarn:msb3202,nu1503' returned a non-zero code: 1

Environment data

dotnet --info output:
Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.300-preview1-008174\

Microsoft .NET Core Shared Framework Host

Version : 2.1.0-preview1-26216-03
Build : f2c3216183d20416568a4bbf5bb7d153e826f153

Copied from original issue: dotnet/cli#8747

Activity

  1. livarcocc commented on Mar 8, 2018

    @livarcocc
    Author

    I am not sure if this has changed from warning to error. Moving it to NuGet for them to confirm.

  2. daerhiel commented on Mar 14, 2018

    @daerhiel

    I have fixed that by changing Docker file from

    COPY *.sln ./
    COPY Solution/Project.csproj Solution/
    RUN dotnet restore
    COPY . .
    

    to

    COPY *.sln ./
    COPY Solution/Project.csproj Solution/
    COPY . .
    RUN dotnet restore Solution/Project.csproj
    
  3. christiansparre commented on Mar 14, 2018

    @christiansparre

    Yeah I thought that too, but then you are faced with the following when using the Docker Tools for VS stuff.

    /src/docker-compose.dcproj : error MSB4236: The SDK 'Microsoft.Docker.Sdk' specified could not be found. ERROR: Service 'someapp' failed to build: The command '/bin/sh -c dotnet restore SomeApp.sln -nowarn:msb3202,nu1503' returned a non-zero code: 1

    You could then try to exclude the docker-compose.dcproj file, but then you are back with the MSB3202 failure.

    Only other alternative I can see is to roll a docker image for the build that includes Microsoft.Docker.Sdk and I have not taken the time to do that just yet.

    I still wonder if the change from MSB3202 being a warning to an error is intentional. If it is, I hope the Docker Tools for VS guys are on top of it. Otherwise we won't be able to use the tooling with 2.1 out of the box.

  4. martore commented on Mar 14, 2018

    @martore
    .NET Command Line Tools (2.1.101)
    
    Product Information:
     Version:            2.1.101
     Commit SHA-1 hash:  6c22303bf0
    
    Runtime Environment:
     OS Name:     Windows
     OS Version:  10.0.17120
     OS Platform: Windows
     RID:         win10-x64
     Base Path:   C:\Program Files\dotnet\sdk\2.1.101\
    
    Microsoft .NET Core Shared Framework Host
    
      Version  : 2.0.6
      Build    : 74b1c703813c8910df5b96f304b0f2b78cdf194d
    

    Dockerfile

    FROM microsoft/dotnet:2.0-runtime AS base
    WORKDIR /app
    
    FROM microsoft/dotnet:2.0-sdk AS build
    WORKDIR /src
    COPY MySolution.sln ./
    COPY MyProject/MyProject.csproj MyProject/
    RUN dotnet restore -nowarn:msb3202,nu1503
    COPY . .
    WORKDIR /src/MyProject
    RUN dotnet build -c Release -o /app
    
    FROM build AS publish
    RUN dotnet publish -c Release -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "MyProject.dll"]
    

    Output [docker-compose up]

    /usr/share/dotnet/sdk/2.1.101/NuGet.targets(229,5): error MSB3202: The project file "/src/Project2/Project2.csproj" was not found. [/src/MySolution.sln]
    /usr/share/dotnet/sdk/2.1.101/NuGet.targets(229,5): error MSB3202: The project file "/src/docker-compose.dcproj" was not found. [/src/MySolution.sln]
    ERROR: Service 'myproject' failed to build: The command '/bin/sh -c dotnet restore -nowarn:msb3202,nu1503' returned a non-zero code: 1

  5. christiansparre commented on Mar 14, 2018

    @christiansparre

    As @martore shows above it is not only an issue on 2.1 preview 1. The just released 2.1.101 sdk seems to be breaking the builds :(

  6. nkolev92 commented on Mar 15, 2018

    @nkolev92
    Member

    The issue arises due to the fact that not all targets can be loaded during the CLI restore, and that breaks an MSBuild optimization that's supposed to help us detect projects that are restore incompatible.

    As a temporary workaround you can try running restore with

    /p:RestoreUseSkipNonexistentTargets="false"

  7. christiansparre commented on Mar 15, 2018

    @christiansparre

    Thanks @nkolev92, it works! I can get on with trying out 2.1 :)

  8. lakario commented on Mar 15, 2018

    @lakario

    Throwing in a me too on this issue as we ran into a hard stop with it last night after pulling the updated 2.0 tag for aspnetcore-build. The above switch from @nkolev92 added to the dotnet restore command in the generated Dockerfile fixes the issue.

    Additionally, the latest version of Visual Studio 17 (15.6.x) changed the ASP.NET Core 2 Dockerfile template to be defined with dotnet restore -nowarn:msb3202,nu1503. Adding this will clean up the output when combined with the above switch.

  9. added this to the Backlog milestone on Mar 15, 2018
  10. nkolev92 commented on Mar 15, 2018

    @nkolev92
    Member

    We're actively working with the ASP.NET docker folks to get a fix soon.

    @natemcmaster

    Can you please follow up here when that's ready?

  11. natemcmaster commented on Mar 15, 2018

    @natemcmaster

    See aspnet/aspnet-docker#389. Once this is merged, it typically takes about an hour for these changes to make it up to Docker Hub.

  12. added a commit that references this issue on Mar 16, 2018
  13. AceHack commented on Jun 2, 2018

    @AceHack

    This issue is happening to me using dotnet:2.1-sdk. It's my understanding that this is the replacement for aspnet-build, can the same fix be made?

  14. martore commented on Jun 2, 2018

    @martore

    @AceHack

    FROM microsoft/dotnet:2.1-runtime AS base
    WORKDIR /app
    
    FROM microsoft/dotnet:2.1-sdk AS build
    WORKDIR /src
    COPY MyApp/MyApp.csproj MyApp/
    COPY MyReferencedApp/MyReferencedApp.csproj MyReferencedApp/
    RUN dotnet restore MyApp/MyApp.csproj
    COPY . .
    WORKDIR /src/MyApp
    RUN dotnet build MyApp.csproj -c Release -o /app
    
    FROM build AS publish
    RUN dotnet publish MyApp.csproj -c Release -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "MyApp.dll"]
    
  15. AceHack commented on Jun 2, 2018

    @AceHack

    @martore I have several projects that need restoring, it would be nice if I could just copy everything into docker including the dcproj and when inside docker it would know to ignore this project type.

  16. AceHack commented on Jun 2, 2018

    @AceHack

    I've thought of creating different build configurations to do just this, so the outside build configuration build just the dcproj and the inside build configuration builds everything else. Don't know if that works for restore as well.

  17. Eilyyyy commented on Jun 4, 2018

    @Eilyyyy

    i meet the same issue with the dockerfile:

    FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
    WORKDIR /app
    EXPOSE 80
    
    FROM microsoft/dotnet:2.1-sdk AS build
    WORKDIR /src
    COPY DataServer.sln ./
    COPY src/Idsrv/Idsrv.csproj src/Idsrv/
    RUN dotnet restore -nowarn:msb3202,nu1503
    
    COPY . .
    WORKDIR /src/src/Idsrv
    RUN dotnet build -c Release -o /app
    
    FROM build AS publish
    RUN dotnet publish --no-restore -c Release -o /app
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app .
    ENTRYPOINT ["dotnet", "Idsrv.dll"]
    

    fllow the output:

    /usr/share/dotnet/sdk/2.1.300/NuGet.targets(239,5): error MSB3202: The project file "/src/src/DataServer/DataServer.csproj" was not found. [/src/DataServer.sln]
    /usr/share/dotnet/sdk/2.1.300/NuGet.targets(239,5): error MSB3202: The project file "/src/src/InfraredData/InfraredData.csproj" was not found. [/src/DataServer.sln]
    /usr/share/dotnet/sdk/2.1.300/NuGet.targets(239,5): error MSB3202: The project file "/src/test/DataServerTest/DataServerTest.csproj" was not found. [/src/DataServer.sln]
    /usr/share/dotnet/sdk/2.1.300/NuGet.targets(239,5): error MSB3202: The project file "/src/docker-compose.dcproj" was not found. [/src/DataServer.sln]
    
    
  18. natemcmaster commented on Jun 4, 2018

    @natemcmaster

    @Eilyyyy It appears your Dockerfile is using a bad pattern generated for you by Visual Studio tooling. The VS tooling has been updated, but your code needs to change manually. I recommmend either:

    1. Remove -nowarn:msb3202,nu1503 and resolving the warnings/errors. This will require updating your Dockefile to include more files in the COPY, such as the .dcproj or any extra .csproj files you've added to your .sln.
    2. Follow the new pattern that Visual Studio tooling would use. This calls restore on the .csproj instead of the .sln file.
    - COPY DataServer.sln ./
     COPY src/Idsrv/Idsrv.csproj src/Idsrv/
    - RUN dotnet restore -nowarn:msb3202,nu1503
    + RUN dotnet restore src/Idsrv/Idsrv.csproj

    @nkolev92 I recommend closing. I don't think there is any action item here for the NuGet team.

  19. AceHack commented on Jun 5, 2018

    @AceHack

    @natemcmaster I would be best if all the dotnet command could just target the sln inside the container and everything just work, like no-op dcproj sdk inside the container.

  20. nkolev92 commented on Jun 6, 2018

    @nkolev92
    Member

    Thanks @natemcmaster. This specific issue slipped through my fingers.
    Closing this as duplicate of #6665.
    There is no NuGet actionable.

    Please refer to #6665 (comment) for a detailed explanation.

  21. modified the milestones: Backlog, 4.8 on Jun 6, 2018
  22. added
    Resolution:Duplicate
    on Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Functionality:RestoreProduct:dotnet.exeResolution:DuplicateTenet:Performance

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions