Skip to content

Error NETSDK1005 “Assets file 'C: \Users\v-minlon\source\repos\RRR02\RRR02\obj\project.assets.json' doesn't have a target for 'net5.0'.” occurs when building solution after enabling “RestoreLockedMode” #10462

Closed

Description

@v-longmin

VS Version: Main\30917.09
NuGet Version : Dev\5.9.0.7050
OS Version: Windows-10-Enterprise-19H2.

Installation

  1. Install VS Main\30917.09: https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=4380664&view=ms.vss-build-web.run-extensions-tab
  2. Install NuGet Dev\5.9.0.7050: \\ddfiles\drops\NuGet\Drops\CI\NuGet.Client\Dev\5.9.0.7050\artifacts\VS15\NuGet.Tools.vsix

Repro steps

  1. Create a C# Console Application (.Net Core) project.
  2. Install a few ‘PackageReference’ packages into the projects.
  3. Set MSBuild property “RestorePackagesWithLockFile” to true in csproj file.
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
  4. Do a restore.
  5. Check it should have generated ‘packages.lock.json’ file alongside *.csproj file.
  6. Set msbuild property “RestoreLockedMode” to “true”.
    <RestoreLockedMode>true</RestoreLockedMode>
  7. Install another package.
  8. It should still work fine and update ‘packages.lock.json’ file.
  9. Manually add a new PackageReference item into csproj file.
    <PackageReference Include="NUnit" Version="3.12.0" />
  10. Perform restore.
  11. Build the solution.

Expected

Only expected error NU1004 shows on error list when building the solution.

Actual

Error NETSDK1005 “Assets file 'C:\Users\v-minlon\source\repos\RRR02\RRR02\obj\project.assets.json' doesn't have a target for 'net5.0'” occurs when building the solution as below screenshot.
image

Notes

  1. The issue also reproes on C# Class Library (.Net Framework) project, the error message as below screenshot.
    image
  2. The issue starts from Dev\5.9.0.7024.

Activity

  1. aortiz-msft commented on Jan 25, 2021

    @aortiz-msft
    Contributor

    Seems like a regression introduced by NuGet/NuGet.Client#3810. We should probably revert the commit associated with this Pull Request and reach out to the contributor to iterate on the proposed code changes.

  2. ericstj commented on Jan 25, 2021

    @ericstj

    How did you happen to identify NuGet/NuGet.Client#3810 as the root cause here? It didn't look to me like that PR would impact restore since it's only modifying targets that run during Pack... cc @nkolev92

  3. ericstj commented on Jan 25, 2021

    @ericstj

    I see @nkolev92 made the same observation here: NuGet/NuGet.Client#3868 (comment)

  4. nkolev92 commented on Jan 26, 2021

    @nkolev92
    Member

    I think the regression was technically introduced in NuGet/NuGet.Client@7ea82b6, however I'd like to argue that we shouldn't revert that commit, because the experience prior to this change was broken anyways.

    I'll add another comment with more details.

  5. nkolev92 commented on Jan 26, 2021

    @nkolev92
    Member

    What was original problem we're trying to fix

    • NU1004 is an error that gets raised when a restore is run in locked mode and the lock file is out of date.
    • Note that NU1004 is an error that requires an action, either by not being in locked mode, or updating the lock file explicitly. The text of the error asks for that.
    • In SDK(CPS) based projects, NuGet restore doesn't write the warning and errors to the error list, NuGet writes it to the assets file and then a different task parses that and adds it to the error list.
    • This has evolved into a design principle, where the NuGet errors and warnings are written in the assets file.

    What happened before the change?

    Before the change, the NU1004 error was never added to the assets file. This means that the error would eventually disappear from the error list after the first build.

    When this would happen the assets file was never updated.

    In the scenario in question, there's no design time build running because the assets file is not changed. You'll only see the warning icon in the solution explorer, because the Solution Explorer knows of a change, but the assets file is not reflecting it.

    What happens after this change?

    In NuGet/NuGet.Client@7ea82b6, we started writing the assets file. This leads to the correct error being displayed in the error list.
    Now this unearths another problem, the one raised in this issue. When a dummy assets file is created, the next build will lead to the generic SDK error.

    While before, the problem was that the assets file is not updated, now the problem is that the assets file is updated, but it has empty targets, so the DT build can't find the right target.

    Why shouldn't we revert the change?

    Simply because it's not a common scenario, and the alternative is worse, because it's not as actionable.
    Ideally the user would observe NU1004 and follow the actions suggested there.
    Before this change, the user would just get a build failure, but nothing in the error list.

  6. ericstj commented on Jan 26, 2021

    @ericstj

    Shouldn't something be done to ensure that the error from the assets file is raised rather than the missing target section error?

  7. nkolev92 commented on Jan 26, 2021

    @nkolev92
    Member

    Shouldn't something be done to ensure that the error from the assets file is raised rather than the missing target section error?

    I thought both errors are being raised but the NU1004 doesn't seem to remain :(

    So I think the net effect(before/after change) is similar for this particular scenario.

  8. nkolev92 commented on Jan 26, 2021

    @nkolev92
    Member

    I did some analysis + updated the above comment.
    The experience is still lacking, but for a different reason. The fix might be on NuGet, but it might on SDK or project-system too. We need to investigate.

    I think the current experience is comparably bad.
    Looking at the data, not too many use lock files with locked mode enabled in VS.

  9. aortiz-msft commented on Jan 26, 2021

    @aortiz-msft
    Contributor

    @nkolev92 - Would you please create a new issue to improve the error reporting?

    @v-luzh - We looked at the repro steps, and adding the dependency directly by hand-editing the file is not supported. Would you please update the test steps to use VS or the CLI to add the package reference?

  10. added
    Resolution:ByDesign
    on Jan 26, 2021
  11. v-luzh commented on Jan 27, 2021

    @v-luzh

    Hi @aortiz-msft, the purpose of this test case is to test if adding the dependency by hand-editing the file would make the error NU1004 show. And if we use VS or the CLI to add the package reference in step9, the expected error would not show.

  12. nkolev92 commented on Jan 27, 2021

    @nkolev92
    Member

    @v-luzh

    Please follow #10486 for that scenario.

    There is an issue in the nuget/project-system coordination.
    NU1004 should stay in the error list as long as there's no build.

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

    Found:ManualTestsResolution:ByDesign

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions