Skip to content

Further centralize shared Fx and TFM transition workarounds #27473

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 10 commits into from
Dec 3, 2020

Conversation

dougbu
Copy link
Member

@dougbu dougbu commented Nov 2, 2020

  • import generated Directory.Build.* files in regular build
    • add $(UpdateAspNetCoreKnownFramework) controlling Microsoft.AspNetCore.App KnownFrameworkReference update
    • warn if requested Microsoft.AspNetCore.App version does not exist in $(DOTNET_ROOT)
    • remove now-duplicate property and item settings outside generated Directory.Build.* files
    • remove central $(BuildingTestAppsIndependently) special case
      • not needed because compiler toolset version is always available
    • correct $(KnownAppHostPackOrFrameworkReferenceTfm) when not targeting the default TFM
  • mention errors with missing generated files and the new warning in BuildFromSource.md
    • address numerous Markdown lint warnings, typos, and spelling mistakes in this file
  • use generated Directory.Build.* files for local template tests
    • move Infrastructure/ files to TestInfrastructure/
      • Infrastructure/ sub-directories were functionally identical
    • move shared parts of template test project files to PrepareForTest.targets
  • use generated Directory.Build.* files for local Razor tests
    • set $(TargetLatestRuntimePatch) instead of $(RuntimeFrameworkVersion); simpler

@dougbu dougbu requested review from pranavkm and a team November 2, 2020 23:06
@dougbu dougbu requested review from SteveSandersonMS and a team as code owners November 2, 2020 23:06
@@ -15,13 +15,13 @@ This tutorial assumes that you are familiar with:

ASP.NET Core uses git submodules to include the source from a few other projects. In order to pull the sources of the these submodules when cloning the repo, be sure to pass the `--recursive` flag to the `git clone` command.

```ps1
```powershell
Copy link
Member Author

Choose a reason for hiding this comment

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

This file wasn't really incredibly broken; it just gave the VS Code Markdown extension plenty to complain about

@@ -154,26 +159,29 @@ to open the .sln file or one of the project specific .slnf files to work on the
> branch, we regularly update the versions of .NET Core SDK required to build the repo.
> You will need to restart Visual Studio every time we update the .NET Core SDK.

Typically, you want to focus on a single project within the monorepo. For example,
> :bulb: Rerunning the above command or, perhaps, the quicker `.\build.cmd -noBuildNative -noBuildManaged` may be
> necessary after switching branches, especially if the `$(DefaultNetCoreTargetFramework)` value changes.
Copy link
Member Author

Choose a reason for hiding this comment

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

new

### Use the result of your build
### Resx files

If you need to make changes to a .resx file, run `dotnet msbuild t:/Resgen <path to csproj>`. This will update the generated C#.
Copy link
Member Author

Choose a reason for hiding this comment

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

Slight reordering

@@ -1,7 +1,6 @@
<Project>
<PropertyGroup>
<DefaultNetCoreTargetFramework>${DefaultNetCoreTargetFramework}</DefaultNetCoreTargetFramework>
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have any projects lacking a $(TargetFramework) setting and this can cause problems where we use $(TargetFrameworks)

@dougbu dougbu requested a review from captainsafia November 2, 2020 23:49
@dougbu
Copy link
Member Author

dougbu commented Nov 2, 2020

@captainsafia I'd appreciate your thoughts on docs/BuildFromSource.md changes in particular

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

BuildFromSource.md changes look good. Left a few notes inline.

@dougbu dougbu added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Nov 3, 2020
@dougbu dougbu force-pushed the dougbu/more.build.in branch 3 times, most recently from 1788d8c to fd353d6 Compare November 8, 2020 03:36
@dougbu dougbu force-pushed the dougbu/more.build.in branch from fd353d6 to 8a939b9 Compare November 17, 2020 19:34
@dougbu dougbu force-pushed the dougbu/more.build.in branch 3 times, most recently from 8cdc40e to d558c0a Compare November 20, 2020 03:45
@dougbu dougbu force-pushed the dougbu/more.build.in branch from d558c0a to 70068f5 Compare November 20, 2020 04:11
@dougbu
Copy link
Member Author

dougbu commented Nov 20, 2020

@wtgodbe and @JunTaoLuo please review. Lots has changed since @captainsafia signed off.

<DefaultRuntimeFrameworkVersion Condition=" '$(IsServicingBuild)' != 'true' AND
'$(TargetLatestDotNetRuntime)' != 'false' ">${MicrosoftNETCoreAppRuntimeVersion}</DefaultRuntimeFrameworkVersion>
<TargetingPackVersion Condition=" '$(IsServicingBuild)' != 'true' AND
'$(TargetLatestDotNetRuntime)' != 'false' ">${MicrosoftNETCoreAppRefVersion}</TargetingPackVersion>
Copy link
Member Author

Choose a reason for hiding this comment

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

@jkotalik the AND '$(TargetLatestDotNetRuntime)' != 'false' additions here are what #27845 needs (in root Directory.Build.targets) until this gets in.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do I need to these changes specifically in this file as well? Sounds like no.

Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

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

Assuming this works, it seems reasonable, but I'm concerned that it seems to be adding complexity and might make our build even harder to understand than it already is - could you explain if/how the value it adds is large enough to overcome that (or if I'm overestimating the added complexity)?

@dougbu dougbu force-pushed the dougbu/more.build.in branch from 8c5173c to 15b0406 Compare November 21, 2020 04:08
@dougbu
Copy link
Member Author

dougbu commented Nov 21, 2020

could you explain if/how the value it adds is large enough to overcome that (or if I'm overestimating the added complexity)?

I started this branch to

  1. remove duplication of very similar workarounds sprinkled around the repo
  • this should make it easier to correct problems in an area we've had some churn and late-breaking concerns
  1. avoid problems such as Improve KnownFrameworkReference workarounds in templatetests.props.in #14895

The work also helped me remove duplication I was less aware of e.g. between src/ProjectTemplates/BlazorTemplates.Tests/ and src/ProjectTemplates/test/.

What specific added complexity are you concerned about❔ I suspect at least some if what you're seeing existed before but in code I'm deleting.

@dougbu dougbu force-pushed the dougbu/more.build.in branch from 15b0406 to 0e78d2d Compare November 22, 2020 23:37
@dougbu
Copy link
Member Author

dougbu commented Nov 23, 2020

@wtgodbe this is now green. Do you object to merging❔

@wtgodbe
Copy link
Member

wtgodbe commented Nov 30, 2020

What specific added complexity are you concerned about❔ I suspect at least some if what you're seeing existed before but in code I'm deleting.

Main concern is the use of the generated .props/.targets file everywhere now, it seems a bit unintuitive and may leave devs wondering where certain common properties "live" now

@wtgodbe
Copy link
Member

wtgodbe commented Nov 30, 2020

If I clean the repo then run dotnet build on an arbitrary project, will it work/create the generated file correctly pre-build? If so I think I'm ok with this.

@wtgodbe
Copy link
Member

wtgodbe commented Dec 1, 2020

Seems like that works, so I'm satisfied

@dougbu
Copy link
Member Author

dougbu commented Dec 1, 2020

If I clean the repo then run dotnet build on an arbitrary project, will it work/create the generated file correctly pre-build? If so I think I'm ok with this.

dotnet build after git clean -e .dotnet/ won't work for many projects in the repo today. In fact, it'll fail for every project if the .dotnet/ folder is not up-to-date. That's why docs/BuildFromSource.md recommends running ./restore.cmd before doing much else.

If the SDK is up-to-date, the new minimum requirement after cleaning for dotnet build (in projects that don't require native assets) is ./build.cmd -noBuildNative -noBuildManaged or ./build.sh --no-build-managed. That just builds the repo tasks and generated the artifacts/bin/GenerateFiles/* files and takes a few seconds. I documented that in this PR.

@dougbu
Copy link
Member Author

dougbu commented Dec 1, 2020

Seems like that works, so I'm satisfied

As I said, that isn't expected to work. I should have added that ./build.* -projects ... will always work because the command builds native assets (if on Windows), updates the SDK, ensures the needed runtimes are available, as well as generates the artifacts/bin/GenerateFiles/* files.

@dougbu
Copy link
Member Author

dougbu commented Dec 1, 2020

Do those caveats undo your approval❔

Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

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

If the SDK is up-to-date, the new minimum requirement after cleaning for dotnet build (in projects that don't require native assets) is ./build.cmd -noBuildNative -noBuildManaged or ./build.sh --no-build-managed

I did my normal workflow, which is clean, restore, build a project using the restored .dotnet folder. Given that this breaks folks who are running dotnet build with a globally installed SDK that matches the one in global.json (e.g. once we ship 6.0 RTM, or if anyone has a 6.0 preview installed globally), I'm more hesitant. My gut feeling is that that scenario should work. Maybe if every restore operation creates the generated file if it doesn't already exist? In any case I'd prefer to talk about this more before making that breaking change.

@dougbu
Copy link
Member Author

dougbu commented Dec 2, 2020

I did my normal workflow, which is clean, restore, build a project…

Ah, I thought you wanted to avoid ./restore.*. If you ./restore.* after cleaning, everything is just fine for any project that doesn't require native assets.

Given that this breaks folks who are running dotnet build with a globally installed SDK

This PR doesn't break using a globally-installed SDK. Globally-installed SDKs only work if they also include up-to-date runtimes from dotnet/runtime e.g. just after rebranding post-release. This restriction comes from the need to have the additional runtimes in the SDK folder. Nothing new here w.r.t. that restriction.

Did you request changes because you thought something about globally-installed SDKs had changed in this PR❔

@wtgodbe
Copy link
Member

wtgodbe commented Dec 2, 2020

So what causes the new requirement to run ./build.cmd -noBuildNative -noBuildManaged or ./build.sh --no-build-managed before building a single project?

@dougbu
Copy link
Member Author

dougbu commented Dec 2, 2020

So what causes the new requirement to run ./build.cmd -noBuildNative -noBuildManaged or ./build.sh --no-build-managed before building a single project?

I probably I confused you because I thought you wanted to avoid using ./restore.* and responded with the absolute minimal requirement to build a managed project. Those commands do less than ./restore.*.

@wtgodbe
Copy link
Member

wtgodbe commented Dec 2, 2020

I probably I confused you because I thought you wanted to avoid using ./restore.* and responded with the absolute minimal requirement to build a managed project. Those commands do less than ./restore.*.

I understand that part, I just want to understand what (if any) scenarios worked before this PR, that do not work after - that is, who has to change their workflow?

@dougbu
Copy link
Member Author

dougbu commented Dec 2, 2020

what (if any) scenarios worked before this PR, that do not work after

About the only things that change at all are scenarios involving switches between branches for which all needed runtimes are already in .dotnet/. In those cases, it's better to use ./build.* -projects {path} instead of or ./build.* -noBuildManaged -noBuildNative before dotnet build. But, the worst case would be using a different Microsoft.NETCore.App and that can only occur if the two branches began at different 'master' commits with dependency updates between.

Copy link
Member

@wtgodbe wtgodbe left a comment

Choose a reason for hiding this comment

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

Ok, then this works for me

@dougbu dougbu force-pushed the dougbu/more.build.in branch from 0e78d2d to ac6fbe3 Compare December 3, 2020 03:08
dougbu and others added 10 commits December 2, 2020 19:17
- make generated `Directory.Build.*` files more widely applicable
  - warn if requested Microsoft.AspNetCore.App version does not exist in `$(DOTNET_ROOT)`
  - add `$(UpdateAspNetCoreKnownFramework)` for Microsoft.AspNetCore.App `@(KnownFrameworkReference)` update
  - remove central `$(BuildingTestAppsIndependently)` special case
    - not needed because compiler toolset version is always available
  - correct `$(KnownAppHostPackOrFrameworkReferenceTfm)` when not targeting the default TFM
    - use MSBuild intrinsic functions for this and in framework projects; future-proofing
  - correct `@(KnownFrameworkReference)` metadata when in servicing
    - should not override default runtime and targeting pack versions
- use generated `Directory.Build.*` files in regular build
  - remove now-duplicate property and item settings outside generated `Directory.Build.*` files
- use generated `Directory.Build.*` files for local Razor tests
  - set `$(TargetLatestRuntimePatch)` instead of `$(RuntimeFrameworkVersion)`; simpler
  - do not restore Razor SDK test asset projects until just before tests run
  - depend on Microsoft.AspNetCore.App projects
  - disable `$(TreatWarningsAsErrors)` for a few Razor SDK tests
    - tests expect projects to build successfully despite a few warnings
- improve (widen) Microsoft.AspNetCore.App `Condition` in Blazor SDK tests

nit: do not pass `$(MicrosoftNetCompilersToolsetVersion)` into Razor test asset projects
  - not needed because generated files already contain the right information
  - even without that, the Directory.Build.props file imports eng/Versions.props
- move Infrastructure/ files to TestInfrastructure/
  - Infrastructure/ sub-directories were functionally identical
- move shared parts of template test project files to PrepareForTest.targets
…uildFromSource.md

- address numerous Markdown lint warnings, typos, and spelling mistakes in this file
- thanks @captainsafia

Co-authored-by: Safia Abdalla <safia@microsoft.com>
- some was already duplicated
- fix Markdown lint issues in BuildErrors.md too
- required for the new `msbuild` intrinsics
    - it is _not_ recommended to parse TFMs manually anymore
- revert this after Visual Studio 16.8 reaches the regular agents
- move `_InstallFrameworkIntoLocalDotNet` earlier because other builds depend on this part
  - this target sometimes executes after dependent projects continue
- add `DependsOnTargets` attributes to further constrain ordering

nit: `IncludeFrameworkListFile` should run before `_ResolveSharedFrameworkContent`
- let's see if 16.8.0 is new enough
- regular queues were updated today

This reverts commit e4ed1755ee74565b232bf0d08b7c631a6e775778.
@dougbu dougbu force-pushed the dougbu/more.build.in branch from ac6fbe3 to 1259f96 Compare December 3, 2020 03:19
@dougbu dougbu merged commit 5fd1db2 into master Dec 3, 2020
@dougbu dougbu deleted the dougbu/more.build.in branch December 3, 2020 06:50
jkotalik added a commit that referenced this pull request Dec 4, 2020
jkotalik added a commit that referenced this pull request Dec 4, 2020
dougbu added a commit to dougbu/razor-compiler that referenced this pull request Nov 17, 2021
…spnetcore#27473)

* Further centralize shared Fx and TFM transition workarounds
  - make generated `Directory.Build.*` files more widely applicable
    - warn if requested Microsoft.AspNetCore.App version does not exist in `$(DOTNET_ROOT)`
    - add `$(UpdateAspNetCoreKnownFramework)` for Microsoft.AspNetCore.App `@(KnownFrameworkReference)` update
    - remove central `$(BuildingTestAppsIndependently)` special case
      - not needed because compiler toolset version is always available
    - correct `$(KnownAppHostPackOrFrameworkReferenceTfm)` when not targeting the default TFM
      - use MSBuild intrinsic functions for this and in framework projects; future-proofing
    - correct `@(KnownFrameworkReference)` metadata when in servicing
       - should not override default runtime and targeting pack versions
  - use generated `Directory.Build.*` files in regular build
    - remove now-duplicate property and item settings outside generated `Directory.Build.*` files
  - use generated `Directory.Build.*` files for local Razor tests
    - set `$(TargetLatestRuntimePatch)` instead of `$(RuntimeFrameworkVersion)`; simpler
    - do not restore Razor SDK test asset projects until just before tests run
    - depend on Microsoft.AspNetCore.App projects
    - disable `$(TreatWarningsAsErrors)` for a few Razor SDK tests
      - tests expect projects to build successfully despite a few warnings
  - improve (widen) Microsoft.AspNetCore.App `Condition` in Blazor SDK tests

nit: do not pass `$(MicrosoftNetCompilersToolsetVersion)` into Razor test asset projects
  - not needed because generated files already contain the right information
  - even without that, the Directory.Build.props file imports eng/Versions.props

* Use generated `Directory.Build.*` files for local template tests
  - move Infrastructure/ files to TestInfrastructure/
    - Infrastructure/ sub-directories were functionally identical
  - move shared parts of template test project files to PrepareForTest.targets

* Describe errors with missing generated files and the new warning in BuildFromSource.md
  - address numerous Markdown lint warnings, typos, and spelling mistakes in this file

* Apply suggestions from code review
  - thanks @captainsafia

* Move all troubleshooting information into BuildErrors.md
  - some was already duplicated
  - fix Markdown lint issues in BuildErrors.md too

* Reorder App.Runtime build slightly
  - move `_InstallFrameworkIntoLocalDotNet` earlier because other builds depend on this part
    - this target sometimes executes after dependent projects continue
  - add `DependsOnTargets` attributes to further constrain ordering

nit: `IncludeFrameworkListFile` should run before `_ResolveSharedFrameworkContent`

* Add temporary workaround for `[AssemblyVersion]` changes

* Address @wtgodbe's nit from dotnet/aspnetcore#27653
  - dotnet/aspnetcore#27653 (review)

Co-authored-by: Safia Abdalla <safia@microsoft.com>

Commit migrated from dotnet/aspnetcore@5fd1db26257c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants