Skip to content

Fixes problems in WindowsDesktop SDK due to _TargetFrameworkVersionWithoutV being undefined sometimes #1707

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 6 commits into from
Aug 25, 2019

Conversation

vatsan-madhavan
Copy link
Member

@vatsan-madhavan vatsan-madhavan commented Aug 23, 2019

Addresses #1651 - Invalid comparison in MSBuild's ignore-conditions mode in outer build of multitargeted project

This change ensures that the WindowsDesktop SDK never deals with undefined numeric values related to TFM.

This solution leverages the fact that Items are evaluated after Properties by MSBuild. See Comparing properties and items

_TargetFrameworkVersionValue - a new Property which is defined for exclusive use within the WindowsDesktop SDK, and which is intended to act as a proxy for _TargetFrameworkVersionWithoutV - is defined in Microsoft.NET.Sdk.WindowsDesktop.targets after TargetFrameworkVersionWithoutV is guaranteed to be defined by Microsoft.NET.Sdk.targets.

Even here, we ensure that a fallback default (0.0) is provided - guaranteeing that _TargetFrameworkVersionValue will always be numeric.

When the Conditions in the various Items in Microsoft.NET.WindowsDesktop.props are evaluated (which will happen strictly after all Properties are evaluated - whether they appear in .props or .targets), _TargetFrameworkVersionValue would have been (a) well-defined and (b) guaranteed to be a numeric value. This would in turn guarantee that errors of the kind "A numeric comparison was attempted on "$(_TargetFrameworkVersionValue)" that evaluates to "" instead of a number," will no longer appear in outer-builds or in any other context.

PS: This is a fix for a regression introduced by #1027 (which shipped in Preview 6) as part of a set of fixes for improving multi-targeting experience, improved warnings and error messages during build, and improvements to project-system integration.

@ghost ghost requested review from rladuca, ryalanms and stevenbrix August 23, 2019 01:31
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Aug 23, 2019
@ghost ghost requested a review from SamBent August 23, 2019 01:31
@vatsan-madhavan vatsan-madhavan force-pushed the dev/vatsan/tfmwithoutvforwpf-m branch from 12c6916 to 27ad4f5 Compare August 23, 2019 18:50
… to Pbt.targets (used for dotnet/wpf builds only)
@vatsan-madhavan vatsan-madhavan added this to the 3.0 milestone Aug 23, 2019
@vatsan-madhavan vatsan-madhavan marked this pull request as ready for review August 23, 2019 19:00
@vatsan-madhavan vatsan-madhavan self-assigned this Aug 23, 2019
@dsplaisted
Copy link
Member

Why doesn't the existing '$(_TargetFrameworkVersionWithoutV)' != '' check short-circuit the subsequent clauses and avoid this problem?

@rainersigwald
Copy link
Member

@dsplaisted It does, but only in the cases where it's in the same condition. It doesn't apply when the is-defined check is applied at the ItemGroup level.

@vatsan-madhavan
Copy link
Member Author

Why doesn't the existing '$(_TargetFrameworkVersionWithoutV)' != '' check short-circuit the subsequent clauses and avoid this problem?

I'm not the expert - @rainersigwald should confirm; it does, but in this way I think:

 <ItemGroup Condition="$(A) != '' And $(A) >= 3.0> <!-- works ok --->
  <!-- You'd think that A != '' is  a given, but it needs to be repeated here - and everywhere else involving an expression containing 'A' - otherwise it doesn't count --> 
   <Foo Condition="$(A) >= 4.0" Include="Bar" /> 
</ItemGroup>

@dsplaisted
Copy link
Member

@vatsan-madhavan Assuming that's correct, would it not be simpler to just repeat the nonempty check in all the conditions that need to do comparisons on the version?

@vatsan-madhavan
Copy link
Member Author

Assuming that's correct, would it not be simpler to just repeat the nonempty check in all the conditions that need to do comparisons on the version?

That's not an approach particularly suited to maintainability IMO. It's simple to explain - yes, but it makes for worse readability, and sets up a system where small changes could incur complex and redundant conditions that should otherwise have been guaranteed by an enclosing scope already.

It's somewhat arguable that such a change would even be even simpler. The proposed change effectively leaves all the conditional constructs intact (modulo small well defined transformations from $(A) != '' to$(Y) != '0.0'; $(A) -> $(Y)). Changing conditions all over the place also changes the semantics of how everything is evaluated - only just a bit - but enough to require more testing, more careful reviews etc. At this point in 3.0, lower the entropy of changes, the better it seems to me.

@vatsan-madhavan vatsan-madhavan modified the milestones: 3.0, 5.0 Aug 24, 2019
@vatsan-madhavan vatsan-madhavan merged commit 0a627fb into master Aug 25, 2019
@vatsan-madhavan vatsan-madhavan deleted the dev/vatsan/tfmwithoutvforwpf-m branch August 25, 2019 09:15
@ghost ghost locked as resolved and limited conversation to collaborators Apr 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
PR metadata: Label to tag PRs, to facilitate with triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants