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

PublishTrimmed with --no-restore silently skips trimming if not previously restored #37049

Open
sbomer opened this issue Nov 20, 2023 · 2 comments
Labels
Area-ILLink untriaged Request triage from a team member

Comments

@sbomer
Copy link
Member

sbomer commented Nov 20, 2023

From @LXGaming in dotnet/linker#3168 (comment):

Documenting an issue I encountered with GitHub Actions Runner ubuntu22/20231115.7 (includes .NET 8) when building a .NET 7 project.

I use GitHub Actions for publishing trimmed .NET binaries, my workflow consists of a restore step and all subsequent steps use --no-restore, I found that builds were no longer being trimmed due to ILLink having disappeared. I eventually stumbled upon this issue and its linked PRs which noted that a restore would be required for ILLink to be downloaded, because I use /p:PublishTrimmed=true and --no-restore on the publish command ILLink is never downloaded.

The solution is to add /p:PublishTrimmed=true to the restore command or alternatively avoid using --no-restore to ensure that ILLink is present.

I believe there should be a warning or error when PublishTrimmed is specified but ILLink isn't present.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-ILLink untriaged Request triage from a team member labels Nov 20, 2023
@ghost
Copy link

ghost commented Nov 20, 2023

@dotnet/illink-contrib a new issue has been filed in the ILLink area, please triage

@sbomer
Copy link
Member Author

sbomer commented Nov 20, 2023

PublishAot has the same issue. Putting PublishTrimmed or PublishAot in the project file solves the problem. Note that we recommend putting these settings in the project file anyway, because they also influence dotnet build - they enable analyzer warnings and set some runtimeconfig settings.

I agree this should be a warning during publish. The issue is the use of implicit package references. PublishTrimmed pretty much just tells the SDK to add a PackageReference to the ILLink package, and all of the downstream logic is handled by NuGet. But if PublishTrimmed is specified on the command-line during publish only, there will be a PackageReference that does nothing during publish because NuGet never got a chance to restore it.

We should add logic to the SDK to detect this during publish and warn if the package hasn't already been restored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-ILLink untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

1 participant