Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

catch-22 regarding running dotnet restore vs. dotnet workload restore first #45447

Open
AArnott opened this issue Dec 13, 2024 · 5 comments
Open

Comments

@AArnott
Copy link
Contributor

AArnott commented Dec 13, 2024

Describe the bug

My CI build is broken on some agents because there seems to be a catch-22 regarding whether to run dotnet restore or dotnet workload restore first.

If I run dotnet restore first, it errors out saying "error NETSDK1147: To install these workloads, run the following command: dotnet workload restore".

If I run dotnet workload restore first, it errors out saying "The SDK 'Microsoft.Build.Traversal' specified could not be found."

Yes, I have traversal projects. And in fact the root of my restore operation is a dirs.proj.

To Reproduce

I suspect all you need is a dirs.proj that points to a project that requires android, iOS or anything else requiring a workload.
Then, on a computer that does not already have a nuget cache with Microsoft.Build.Traversal or the required workload installed, try restoring.

Further technical details

SDK Version: 9.0.100

This happens on mac, windows and linux agents. These are custom agents, BTW, so they don't have a bunch of workloads pre-installed as the Azure Pipelines Hosted agents may have.

@baronfel
Copy link
Member

More reason to get traversal and notargets SDKs into the MSBuild core @rainersigwald :-/

@AArnott I think as a workaround if you know the workloads you require you can explicitly call 'dotnet workload install ' to get around this. All workload restore does is call a target to try and determine this list on your behalf, so calling install yourself will be strictly faster not to mention not requiring the 'dotnet restore' to have completed.

@AArnott
Copy link
Contributor Author

AArnott commented Dec 13, 2024

Thanks for the suggestion.

I'm working around this by running dotnet workload restore some.sln and reserving use of the traversal project for the subsequence dotnet restore command.

AArnott added a commit to nerdcash/Nerdbank.Cryptocurrencies that referenced this issue Dec 13, 2024
When the MSBuild traversal SDK is not already installed, `dotnet workload restore` fails.
When I run `dotnet restore` first (to place the SDK) it fails saying I must first run `dotnet workload restore`.

By running `dotnet workload restore` _first_, targeting the sln file instead of the traversal project, I avoid the traversal SDK dependency, allowing workload restore to succeed, which then allows a subsequent traversal project-based `dotnet restore` to succeed.

See also dotnet/sdk#45447
@marcpopMSFT marcpopMSFT added this to the Backlog milestone Dec 17, 2024
@marcpopMSFT marcpopMSFT removed the untriaged Request triage from a team member label Dec 17, 2024
@marcpopMSFT
Copy link
Member

Moving to the backlog for now pending the traversal sdk work. We could also consider a way of hardcoding the workloads you wanted for restore or changing how workload restore gets the list but holding off on that investment for now.

@AArnott
Copy link
Contributor Author

AArnott commented Dec 18, 2024

That's fine. I have a workaround.

But IMO it's bigger than the traversal SDK. In general, a project that uses any MSBuild SDK and requires a dotnet workload is SOL.

I can workaround it because these two requirements for me are in different projects, so I can focus my dotnet workload restore command on projects that need it, and dotnet restore can then run on all the projects. But if these projects are the same or intermingled by project references going both directions, you're sunk.

Alternatively, a workaround as @baronfel mentioned is to manually install with dotnet workload install, which avoids the dotnet workload restore command altogether.

@baronfel
Copy link
Member

Linking #45216 because it's probably my preferred approach to the problem.

dotnet workload restore is trying to be smart and figure out what workloads to install, but if there were a specific list (either user specified via dotnet workload install X Y Z or in a place like global.json as #45216 requests) then dotnet workload restore could consult that and skip the build. The gesture's intent would remain, but it would become more reproducible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants