Skip to content

Avoid configuring PreserveCompilationContext=true in 6.0 apps #16656

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

Merged
merged 3 commits into from
Apr 7, 2021

Conversation

pranavkm
Copy link
Contributor

@pranavkm pranavkm commented Mar 31, 2021

The goal is to avoid producing the side-effects of setting PreserveCompilationContext=true
(additional content in deps file and ref assemblies) unless the app expects it.

Previously the option was configured as part of Razor's SDK.props. This was done as a hack around
target evaluation ordering - GenerateDependencyFile and PreserveCompilationReferences are defined
in M.NET.Sdk's targets and use PreserveCompilationContext during their initialization. Unfortunately
configuring it there makes it difficult to make any tfm specific decisions or de-activate it if
the user did not explicitly configure it.

This change adds a hook to initialize PreserveCompilationContext early on during .NET SDK that allows
configuring defaults for 5.0 and earlier apps.

Fixes dotnet/aspnetcore#5068

@ghost
Copy link

ghost commented Mar 31, 2021

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@pranavkm pranavkm force-pushed the prkrishn/preservecompilationcontext branch 3 times, most recently from 09bd4cb to 0341547 Compare April 1, 2021 00:09
@pranavkm pranavkm marked this pull request as ready for review April 1, 2021 15:45
@pranavkm pranavkm requested review from dsplaisted and sfoslund April 1, 2021 15:46
@@ -106,5 +108,43 @@ public virtual void Publish_IncludesRefAssemblies_WhenCopyRefAssembliesToPublish

new FileInfo(Path.Combine(outputPath, "refs", "System.Threading.Tasks.Extensions.dll")).Should().Exist();
}

[CoreMSBuildOnlyFact]
public void Build_ProducesDepsFileWithCompilationContext_ButNoReferences()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests run on .NET Core 2.1, 3.1 and 5.0. So we know we haven't regressed this scenario there. We don't have a netframework app in our test matrix, but I manually verified that the behavior there is also unchanged.

Optional targets used to initialize PreserveCompilationContext.
This property is configured by the RazorSDK if it is referenced by the app.
-->
<Import Project="$(_NETSdkInitializePreserveCompilationTargets)" Condition="'$(_NETSdkInitializePreserveCompilationTargets)' != ''" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make this a proper ImportBeforeMicrosoftNetSdkPreserveCompilationContext property if we that's more appropriate. I used a "private" property since I don't really expect user projects to ever want to configure this

@pranavkm
Copy link
Contributor Author

pranavkm commented Apr 5, 2021

@dsplaisted any chance you could have a look at this PR this week?

@dsplaisted
Copy link
Member

These properties don't need to be set exactly before Microsoft.NET.PreserveCompilationContext.targets, right?

I would suggest importing next to this:

<!-- Import workload targets -->
<Import Project="Microsoft.NET.Sdk.ImportWorkloads.targets" Condition="'$(MSBuildEnableWorkloadResolver)' == 'true'" />

That way it's importing in a more generic location, and if Razor ends up shipping in a workload then it's a simple switch.

I'd suggest naming the new file something like Microsoft.NET.Sdk.Razor.BeforeCommon.targets, and setting a Boolean property (such as UsingRazorSdk) in the Razor .props which will cause it to be imported from that location in Microsoft.NET.Sdk.BeforeCommon.targets.

The goal is to avoid producing the side-effects of setting PreserveCompilationContext=true
(additional content in deps file and ref assemblies) unless the app expects it.

Previously the option was configured as part of Razor's SDK.props. This was done as a hack around
target evaluation ordering - GenerateDependencyFile and PreserveCompilationReferences are defined
in M.NET.Sdk's targets and use PreserveCompilationContext during their initialization. Unfortunately
configuring it there makes it difficult to make any tfm specific decisions or de-activate it if
the user did not explicitly configure it.

This change adds a hook to initialize PreserveCompilationContext early on during .NET SDK that allows
configuring defaults for 5.0 and earlier apps.
@pranavkm pranavkm force-pushed the prkrishn/preservecompilationcontext branch 2 times, most recently from 8072c3f to 071a308 Compare April 7, 2021 18:56
@pranavkm pranavkm force-pushed the prkrishn/preservecompilationcontext branch from 071a308 to 2112f3c Compare April 7, 2021 18:58
@pranavkm
Copy link
Contributor Author

pranavkm commented Apr 7, 2021

Updated the PR based on your feed. It looks a lot cleaner now!



<!-- Import targets from RazorSDK if referenced -->
<Import Project="$(MSBuildThisFileDirectory)Microsoft.NET.Sdk.Razor.BeforeCommon.targets" Condition="'$(UsingMicrosoftNETSdkRazor)' == 'true'" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put this file under the Microsoft.NET.Sdk.Razor folder? It should be fine to use a relative import path for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@pranavkm pranavkm added auto-merge Automatically merge PR once CI passes. Auto-Merge If Tests Pass labels Apr 7, 2021
@ghost
Copy link

ghost commented Apr 7, 2021

Hello @pranavkm!

Because this pull request has the Auto-Merge If Tests Pass label, I will be glad to assist with helping to merge this pull request once all check-in policies pass.

p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (@msftbot) and give me an instruction to get started! Learn more here.

@ghost
Copy link

ghost commented Apr 7, 2021

Apologies, while this PR appears ready to be merged, I've been configured to only merge when all checks have explicitly passed. The following integrations have not reported any progress on their checks and are blocking auto-merge:

  1. DotNet Maestro - Int
  2. Codecov
  3. DotNet Maestro
  4. Dependabot

These integrations are possibly never going to report a check, and unblocking auto-merge likely requires a human being to update my configuration to exempt these integrations from requiring a passing check.

Give feedback on this
From the bot dev team

We've tried to tune the bot such that it posts a comment like this only when auto-merge is blocked for exceptional, non-intuitive reasons. When the bot's auto-merge capability is properly configured, auto-merge should operate as you would intuitively expect and you should not see any spurious comments.

Please reach out to us at [email protected] to provide feedback if you believe you're seeing this comment appear spuriously. Please note that we usually are unable to update your bot configuration on your team's behalf, but we're happy to help you identify your bot admin.

@pranavkm pranavkm merged commit fc4dcb6 into main Apr 7, 2021
@pranavkm pranavkm deleted the prkrishn/preservecompilationcontext branch April 7, 2021 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Merge If Tests Pass auto-merge Automatically merge PR once CI passes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider not setting PreserveCompilationContext in the RazorSDK when targeting 6.0 or later
2 participants