Do not import project extensions during restore#9748
Conversation
|
FYI @KirillOsenkov |
Co-authored-by: Rainer Sigwald <raines@microsoft.com>
100% agree on we should add mechanism flagging that issue. |
|
I wonder if in this case we could get away with adding a high-importance message right to |
I support that! It wouldn't catch the case of restore run requested via dependencies definition - but I'd hope it's rather esoteric. And even if it wouldn't be esoteric - check in XMake is cheap and we can have it quickly... - do you want to shoot a PR? :-) |
|
Wait, I don't think I understand what the message is for? Is it "you're running Restore and something else in the same invocation"? |
|
Yes, it would basically warn against |
|
I fear that's the same kind of "breaking change" we've had to back out before. I think the analyzer-related "have a way to opt into new warnings" would have to be in place first. |
|
Question for everyone: Should this pull request also set |
|
I'd leave that definition in the SDK I think. |
|
Hi @jeffkl, These changes backfired in an unusual way for the tests in sdk (e.g. dotnet/sdk#39093) In the test, publish and restore are run on the same project separately, and on restore execution PublishTrimmed switch is passed in a special way Since restore happens after publish, project is considered as up to date and this stage is skipped: As a possible strategies we can suggest:
Please share you opinion on that! |
|
also adding @Forgind for his insights |
|
If my understanding is correct, we should update the tests to account for the new behavior. I've filed an issue here and added some details: |
|
jeffkl and I investigated this yesterday in the SDK insertion PR and found the same root cause as YuliiaKovalova. We also decided it's probably best to just update the tests. We're still talking a bit (with dsplaisted) about how big of a breaking change it likely is and what we should do about it. Thanks for the parallel investigation! |
Even switching to inline argument will help! But I though it was intentionally passed this way for checking some specific scenario which I am not aware of. |
|
I was trying to understand how I'm related to this since I don't even know what this is. Took me a second as I looked at the blame on the file, and I'm not in the blame. However, I'm in the commit history for the file because I moved every test in the repo in this PR. So, I'd just recommend looking at the blame history over the commit history since it usually gives you a more accurate gauge of the people involved. |



Fixes #9512
Context
During restore, MSBuild needs to evaluate the entry project and during this evaluation if any of the project extension files that NuGet generates (
project.nuget.g.propsandproject.nuget.g.targets) they are used during the next restore. Another side effect is the files that exist on disk at the beginning of restore are embedded in the binary log and not the ones that are generated by NuGet.Changes Made
Introduced a new property
MSBuildIsRestoringwhich is set during an implicit restore (/restore) or an explicit restore (/Target:restore) so that we don't need to take a dependency onMSBuildRestoreSessionId. This is now a property users can key off of to detect if a command-line based restore is running.Default
ImportProjectExtensionPropsandImportProjectExtensionTargetstofalseifMSBuildIsRestoringistrueunless a users has explicitly setImportProjectExtensionPropsorImportProjectExtensionTargetstotrue. This allows users to bring back the old behavior if desired.I also added
MSBuildRestoreSessionIdandMSBuildIsRestoringtoMSBuildConstantsso their names can be defined in a single place.Testing
Added to existing unit tests to verify
ImportProjectExtensionPropsandImportProjectExtensionTargetsdefault tofalseifMSBuildIsRestoringistrueImportProjectExtensionPropsandImportProjectExtensionTargetsare set totrue, their values are not set even ifMSBuildIsRestoringistrueNotes