Skip to content
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

New project file format + Net Standard 2.0 build #139

Merged
merged 48 commits into from
Aug 9, 2021

Conversation

sergey-tihon
Copy link
Member

@sergey-tihon sergey-tihon commented Apr 22, 2018

Statusnet45

Unit tests for ResX type provider temporary ignored because provided code failed to load actual value in runtime

[23:17:19 ERR] ResX Provider tests/Can return an image from the resource file errored in 00:00:00.0100000 <Expecto>
System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "Resource1.resources" was correctly embedded or linked into assembly "FSharp.Configuration.Tests" at compile time, or that allthe satellite assemblies required are loadable and fully signed.
  at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing (System.String fileName) [0x000bf] in <e22c1963d07746cd9708456620d50e1a>:0
  at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet (System.Globalization.CultureInfo culture, System.Collections.Generic.Dictionary`2[TKey,TValue] localResourceSets, System.Boolean tryParents, System.Boolean createIfNotExists, System.Threading.StackCrawlMark& stackMark) [0x000d9] in <e22c1963d07746cd9708456620d50e1a>:0
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo requestedCulture, System.Boolean createIfNotExists, System.Boolean tryParents, System.Threading.StackCrawlMark& stackMark) [0x00099] in <e22c1963d07746cd9708456620d50e1a>:0
  at System.Resources.ResourceManager.InternalGetResourceSet (System.Globalization.CultureInfo culture, System.Boolean createIfNotExists, System.Boolean tryParents) [0x00002] in <e22c1963d07746cd9708456620d50e1a>:0
  at System.Resources.ResourceManager.GetObject (System.String name, System.Globalization.CultureInfo culture, System.Boolean wrapUnmanagedMemStream) [0x00071] in <e22c1963d07746cd9708456620d50e1a>:0
  at System.Resources.ResourceManager.GetObject (System.String name) [0x00000] in <e22c1963d07746cd9708456620d50e1a>:0
  at FSharp.Configuration.ResXProvider.readValue[a] (System.String resourceName, System.Reflection.Assembly assembly, System.String key) [0x00024] in <5adcedc545d3202aa7450383c5eddc5a>:0
  at FSharp.Configuration.Tests.ResXTests+tests@15-256.Invoke (Microsoft.FSharp.Core.Unit _arg2) [0x0000b] in <5adcedcdb7adfc68a7450383cdeddc5a>:0
  at Expecto.Impl+execTestAsync@888-1.Invoke (Microsoft.FSharp.Core.Unit unitVar) [0x00027] in <5ac8c052822f8511a745038352c0c85a>:0
  at Microsoft.FSharp.Control.AsyncBuilderImpl+callA@522[b,a].Invoke (Microsoft.FSharp.Control.AsyncParams`1[T] args) [0x00051] in <5a7d678a904cf4daa74503838a677d5a>:0

Here should be some magic that fixes it when we build for full frameworks...

As of today .net core has the very limited support for resource files - dotnet/msbuild#2221

Statusnetstandard2.0

TPs migrated to netstandard2.0:

  • YamlConfigTypeProvider
  • IniFileProvider
  • ResXProvider (more)
  • AppSettingsTypeProvider
  • Access to current web.config for web apps (???)

Tip for YamlDotNet serializer customization - https://www.cyotek.com/blog/using-custom-type-converters-with-csharp-and-yamldotnet-part-1

@baronfel
Copy link
Collaborator

It looks like things worked once you set the paths to fsc.exe, but I was under the impression that this was no longer required, per the fsproj files in FSharp.Data: https://github.com/fsharp/FSharp.Data/blob/master/src/FSharp.Data/FSharp.Data.fsproj#L6

I'm not quite sure what's going on with that, but we should be able to build for net45 using the dotnet sdk only, right?

@sergey-tihon
Copy link
Member Author

I do still have ignored tests for ResX provider (the issue looks not related to TP).

I'm not quite sure what's going on with that, but we should be able to build for net45 using the dotnet sdk only, right?

Yes, you are right, I also did not use fsc.props in TP projects. It is needed to build projects (projects that use TP) because otherwise dotnet build report the issue that is cannot find the class with TypeProvided attributed in assembly marked by TypeProviderAssembly attribute.

@sergey-tihon sergey-tihon changed the title Migration to new project file format New project file format + Net Standard 2.0 build Apr 27, 2018
@sergey-tihon
Copy link
Member Author

sergey-tihon commented Apr 27, 2018

at least it works for Linux and macOS =)

on windows, MSBuild cannot find assembly because of version mismatch of SharpYaml dependency ...

X:\FSharp.Configuration\tests\FSharp.Configuration.Tests\YamlProvider.Tests.fs(8,17): error FS3033: The type provider 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error: Could not load file or assembly 'System.Reflection.TypeExtensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. [X:\FSharp.Configuration\tests\FSharp.Configuration.Tests\FSharp.Configuration.Tests.fsproj]

I am not sure how to pass binding redirect in this case ...

Update:
I think is possible to create SharpYaml version that work without binding redirects xoofx/SharpYaml#54

@sergey-tihon
Copy link
Member Author

@baronfel Why Fsharp.Data NuGet package does not contain net standard facade assemblies? https://github.com/fsprojects/FSharp.TypeProviders.SDK#making-a-net-standard-20-tpdtc

@baronfel
Copy link
Collaborator

That's a good question. To be honest I'm still very shaky on it, and we may want to get clarification from @dsyme, but I believe it's because on .net 45+ FSharp.Data provides a net45 TP Design-Time Component. I think the netstandard facade dll would be required if the TP only shipped a netstandard2.0 version of the Design-Time component, and then only in order to make the netstandard2.0 component run on .net461 and greater.


nuget SharpYaml
nuget FSharp.Core ~> 4.0.0
nuget YamlDotNet
Copy link
Member Author

Choose a reason for hiding this comment

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

@vasily-kirichenko @object Do you any reason why we should not use YamlDotNet and should keep SharpYaml?

YamlDotNet.dll is easier for net standard TP world, because it does not have external dependencies and should not resolve\redirect them...

Copy link
Contributor

Choose a reason for hiding this comment

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

if the tests pass, I’m ok with yamldotnet.

@sergey-tihon
Copy link
Member Author

First alpha with 2 TPs for netstandard2.0 (Yaml & Ini) and all TPs for net45 is released on NuGet - https://www.nuget.org/packages/FSharp.Configuration/2.0.0-alpha1

@vasily-kirichenko
Copy link
Contributor

I tried YamlConfig on Mac, the repo is https://github.com/vasily-kirichenko/ConsoleApp4

It work properly in Rider:

image

but compilation fails:

$ dotnet build
Microsoft (R) Build Engine version 15.6.82.30579 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restoring packages for /Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj...
  Generating MSBuild file /Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/obj/ConsoleApp4.fsproj.nuget.g.props.
  Restore completed in 192.34 ms for /Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj.
error FS3053 : The type provider 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error : The type provider constructor has thrown an exception: Exception has been thrown by the target of an invocation. [/Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj]
FSC : warning FS3005: Referenced assembly '/Users/vaskir/.nuget/packages/fsharp.configuration/2.0.0-alpha1/lib/netstandard2.0/FSharp.Configuration.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found [/Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj]

Build FAILED.

FSC : warning FS3005: Referenced assembly '/Users/vaskir/.nuget/packages/fsharp.configuration/2.0.0-alpha1/lib/netstandard2.0/FSharp.Configuration.dll' has assembly level attribute 'Microsoft.FSharp.Core.CompilerServices.TypeProviderAssemblyAttribute' but no public type provider classes were found [/Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj]
error FS3053 : The type provider 'FSharp.Configuration.ConfigTypeProvider+FSharpConfigurationProvider' reported an error : The type provider constructor has thrown an exception: Exception has been thrown by the target of an invocation. [/Users/vaskir/RiderProjects/ConsoleApp4/ConsoleApp4/ConsoleApp4.fsproj]
    1 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.95

@sergey-tihon
Copy link
Member Author

@vasily-kirichenko Yes.... one manual change required in fsproj file

<Project Sdk="Microsoft.NET.Sdk">
   <Import Project="../../fsc.props" />

and fsc.props file - https://github.com/fsprojects/FSharp.TypeProviders.SDK/blob/master/fsc.props that specify FscToolPath & FscToolExe

Type providers currently can't run inside the .NET Core 2.0 hosted compiler, see dotnet/fsharp#3658 (comment)

@vasily-kirichenko
Copy link
Contributor

vasily-kirichenko commented Apr 28, 2018

@sergey-tihon thanks, it works, but... Is it possible to add the props file into the nuget package and auto modify project file when it's installed? I know this is done by FSharp.Compiler.Tools, for example.

@sergey-tihon
Copy link
Member Author

@vasily-kirichenko hm... interesting idea. as I know other TPs do not do it yet...

But what if you use several TPs NuGet packages and each import such fsc.props file...
They may become out of sync. For example Fsharp.Configuration for Windows uses path

<FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\10.1\Framework\v4.0</FscToolPath>

but SDK file is still pointing to

<FscToolPath>C:\Program Files (x86)\Microsoft SDKs\F#\4.1\Framework\v4.0</FscToolPath>

This probably means that path depends on VS version installed on the end-user machine... and there is no one file that covers all cases at the moment.

We could try to invert one and release as a separate NuGet package and add the dependency from all type provider project, but I am not sure how long we need it.

I want to believe that that very soon TPs will be able to run inside the .NET Core 2.0 hosted compiler...

@object
Copy link

object commented May 17, 2018

Finally had some time to test the new package (https://www.nuget.org/packages/FSharp.Configuration/2.0.0-alpha1). Built a project successfully both on Windows and Mac using either Visual Studio or Rider. Will have to run some runtime tests, but looks very promising so far. Great work guys!

@sergey-tihon
Copy link
Member Author

@baronfel Do you have an idea how Win build could be fixed?

@baronfel
Copy link
Collaborator

No, I was poking around locally this weekend a bit and didn't really get anywhere :(

sergey-tihon and others added 13 commits December 9, 2019 07:22
# Conflicts:
#	src/FSharp.Configuration/TypeProviders.Helper.fs
When the list field is empty when updateList is called, the list is
incorrectly inferred as sortable, as Seq.forall is vacuously true.

To fix that, we check itemType using reflection instead.
- ":? Uri" is done using Type.IsSubclass
- ":? IComparable" uses Type.IsAssignable as IComparable is an interface
@Slesa
Copy link

Slesa commented Aug 3, 2021

Any news here? I would like to use it in .NET core...

@sergey-tihon
Copy link
Member Author

@Slesa let's move our conversation from twitter here.

it requires .NET4 / Mono

Yes, it is because it still build design time component for net46
https://github.com/sergey-tihon/FSharp.Configuration/blob/dotnet/src/FSharp.Configuration.DesignTime/FSharp.Configuration.DesignTime.fsproj#L6

Does 2.0.0-alpha3 works for you on .net core?

@Slesa
Copy link

Slesa commented Aug 6, 2021

Yes, works. Thanks a lot.

# Conflicts:
#	.config/dotnet-tools.json
#	.github/workflows/dotnetcore.yml
#	build.fsx.lock
#	global.json
#	paket.lock
#	src/FSharp.Configuration.Runtime/paket.template
@sergey-tihon sergey-tihon merged commit 2ac7103 into fsprojects:master Aug 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.