You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
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
Create a C# Console Application (.Net Core) project.
Install a few ‘PackageReference’ packages into the projects.
Set MSBuild property “RestorePackagesWithLockFile” to true in csproj file. <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
Do a restore.
Check it should have generated ‘packages.lock.json’ file alongside *.csproj file.
Set msbuild property “RestoreLockedMode” to “true”. <RestoreLockedMode>true</RestoreLockedMode>
Install another package.
It should still work fine and update ‘packages.lock.json’ file.
Manually add a new PackageReference item into csproj file. <PackageReference Include="NUnit" Version="3.12.0" />
Perform restore.
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.
Notes
The issue also reproes on C# Class Library (.Net Framework) project, the error message as below screenshot.
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.
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
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.
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.
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.
@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?
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.
Activity
aortiz-msft commentedon Jan 25, 2021
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.
ericstj commentedon Jan 25, 2021
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
ericstj commentedon Jan 25, 2021
I see @nkolev92 made the same observation here: NuGet/NuGet.Client#3868 (comment)
nkolev92 commentedon Jan 26, 2021
I think the regression was
technicallyintroduced in NuGet/NuGet.Client@7ea82b6, however I'd like to argue that we shouldn't revert that commit, because the experiencepriorto this change was broken anyways.I'll add another comment with more details.
nkolev92 commentedon Jan 26, 2021
What was original problem we're trying to fix
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.
ericstj commentedon Jan 26, 2021
Shouldn't something be done to ensure that the error from the assets file is raised rather than the missing target section error?
nkolev92 commentedon Jan 26, 2021
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.
nkolev92 commentedon Jan 26, 2021
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.
aortiz-msft commentedon Jan 26, 2021
@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?
v-luzh commentedon Jan 27, 2021
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.
nkolev92 commentedon Jan 27, 2021
@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.