-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PublishAOT property causes build failure when used with earlier TFMS in TargetFrameworks
property
#30814
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
Comments
@jtschuster Could you investigate and figure out the details of exactly why this is failing? My suspicion is that |
For the first repro: Restore depends on _GenerateRestoreGraph The naïve solution would be to add a condition to avoid running _GenerateRestoreGraphAllFrameworks if TargetFramework != '', but I’m not sure if that would break other things. |
It sounds like restore is designed to restore for all TFMs in the project. Since we are restoring parts of ILComplier as a packagereference, maybe the fix is to add a TFM condition on the packagereference here? sdk/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs Lines 694 to 696 in 37d204c
|
I would be OK with this, but it does feel like |
Are we sure that build doesn't have the same behavior (restore for all TFMs, even if only one TFM is requested to build)? |
Don't build and publish just depend on restore? And the same behavior should happen for restore regardless of whether you're building or publishing? Restore will still error for 'dotnet build' in this repro at least |
Right, I'm sure they do -- but why doesn't build run for every TFM when |
Ah, now I see what you're asking. I am assuming that restore-for-all-TFMs is by design (perhaps it helps with restore, followed by offline development+build). I would check with SDK owners before trying to change that. @dsplaisted maybe you know - is it by design that restoring as part of build/publish for a particular TFM restores for all TFMs? And what's the reason for this behavior? |
The behavior is by design. The idea is that you could have multiple TargetFrameworks in the project file indicating all the possible frameworks you could target, but during build or publish you might want to only select one (indeed, for publish I believe you have to specify a target framework for multi-targeted projects). If restore were to use the specified TargetFramework, then a full restore would have to run each time you built or published for a different target framework. To avoid that, the implicit restore ignores the This does not always lead to desirable behavior, so we might think about changing the design. I believe this is related to #21877. Also, I couldn't find the issue right now, but it prevents you from specifying a TargetFramework via the |
OK, well I guess in the intermediate we can work around the problem by checking if the TFM < 7 as @sbomer suggested. |
FWIW, the workaround is also to set |
It looks like this is by-design in the SDK right now. I'm going to close this issue, as it will not be fixed unless something in the SDK changes. |
Repro:
Now publish with
~/tmp/dn/dotnet.exe publish -r win-x64 -p:PublishAot=true -f net8.0
This should work because PublishAot is valid for
net8.0
and we're passing-f net8.0
to only target that TFM. But it appears at least some logic is being executed fornet6.0
regardless.This will also fail if you place
PublishAot
in the project file unconditionally and then runpublish --sc -r win-x64 -f net8.0
.In both of these cases, we should somehow guard against the PublishAot flag being propagated through in unsupported TFMs, or fix framework targeting to run no logic for alternate TFMs when specified with
-f
.The text was updated successfully, but these errors were encountered: