Skip to content

[tests] fix for FSharp targets on Windows - #1064

Merged
jonpryor merged 1 commit into
dotnet:masterfrom
jonathanpeppers:fsharp-targets
Dec 5, 2017
Merged

jonpryor merged 1 commit into
dotnet:masterfrom
jonathanpeppers:fsharp-targets

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Context: https://devdiv.visualstudio.com/DevDiv/Default/_build/index?buildId=1188880&_a=summary&tab=ms.vss-test-web.test-result-details

Our FSharp tests are failing on Windows due to the way we are having to
import Microsoft.FSharp.targets:

<Import
    Condition="'$(Language)' != 'F#' And Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')"
    Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets"
/>

Since xabuild.exe is modifying $(MSBuildExtensionsPath) to a path in
XA's build tree, the Condition always evaluates to False--even though
the search path fallbacks would have located it. Since we are having to
use Condition and check for multiple paths for F#, MSBuild's search path
fallback logic will not be able to work in this file.

Two changes to improve this, which should fix the tests on Windows:

  • Added F# 4.1 directory searching, as this was missing
  • Added a lookup of the FSHARPINSTALLDIR environment variable. This
    was installed system-wide on my machine from Visual Studio 2017 15.4. It
    is also already set on our VSTS build agents.

Context: https://devdiv.visualstudio.com/DevDiv/Default/_build/index?buildId=1188880&_a=summary&tab=ms.vss-test-web.test-result-details

Our FSharp tests are failing on Windows due to the way we are having to
import `Microsoft.FSharp.targets`:

```
<Import
    Condition="'$(Language)' != 'F#' And Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')"
    Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets"
/>
```

Since `xabuild.exe` is modifying `$(MSBuildExtensionsPath)` to a path in
XA's build tree, the `Condition` always evaluates to `False`--even though
the search path fallbacks would have located it. Since we are having to
use `Condition` and check for multiple paths for F#, MSBuild's search path
fallback logic will not be able to work in this file.

Two changes to improve this, which should fix the tests on Windows:
- Added F# 4.1 directory searching, as this was missing
- Added a lookup of the `FSHARPINSTALLDIR` environment variable. This
was installed system-wide on my machine from Visual Studio 2017 15.4. It
is also already set on our VSTS build agents.
@dnfclas

dnfclas commented Dec 4, 2017

Copy link
Copy Markdown

@jonathanpeppers,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

<Import
Condition="'$(Language)' != 'F#' And Exists('$(FSharpInstallDir)Microsoft.FSharp.Targets')"
Project="$(FSharpInstallDir)Microsoft.FSharp.Targets" />
<Import

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the order important for these imports? Which should be preferred? I assume if both exist the last one will be used (as it will overwrite all the bits from the other.. maybe)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dellis1972 I think $(Language) gets set to F# as soon as one is imported, so it should pick the first one that loads.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the order important for these imports?

Yes.

As @jonathanpeppers notes, the '$(Language)' != 'F#' check ensures that the first "existing" <Import/> "wins." As soon as a file is found an imported, the expectation is that file will set <Language>F#</Language>, which will prevent subsequent imports from actually importing.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That said, I have no idea what the order should be here. :-(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@jonpryor @dellis1972

I tested what it's doing here a little bit.

If you are inside VS, it loads this one because $(VisualStudioVersion) is set: $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets

If you are MSBuild command line, it picks the newest F# you have installed, such as: $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\4.1\Framework\v4.0\Microsoft.FSharp.Targets

My FSHARPINSTALLDIR is set to C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0\.

So perhaps the order should be:

  • Try the VS one
  • Try the environment variable
  • Try 4.1
  • Try 4.0
  • Try 3.1

I happened to have code in this PR like in this order already. Thinking it through a little more, what do you guys think?

@jonpryor
jonpryor merged commit 7acd0d5 into dotnet:master Dec 5, 2017
@jonathanpeppers
jonathanpeppers deleted the fsharp-targets branch December 5, 2017 15:26
jonpryor pushed a commit that referenced this pull request Jan 21, 2020
Changes: https://github.com/xamarin/monodroid/compare/2c9ce23d...dab75e88

Fixes: https://work.azdo.io/1041849
Fixes: https://developercommunity.visualstudio.com/content/problem/858509/adb0030-monoandroidtoolsrequiresuninstallexception-2.html

  * xamarin/monodroid@dab75e880: Bump to xamarin/android-sdk-installer/d16-5@5adcbfa (#1066)
  * xamarin/monodroid@3293f67a9: Bump to xamarin/android-sdk-installer/d16-5@dd6e2c0 (#1063)
  * xamarin/monodroid@8ecaa9d30: [tools/msbuild] prevent InstallPackageAssemblies from reporting two errors (#1058) (#1064)
  * xamarin/monodroid@284b81933: Bump to xamarin/androidtools/d16-5@62844ab (#1062)
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants