-
Notifications
You must be signed in to change notification settings - Fork 790
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
Consider supporting #r: "frameworkreference:" #9417
Comments
Agreed, I wonder what it would look like. |
Perhaps:
? |
It looks like this in the project file: https://github.com/SaturnFramework/Saturn/blob/master/src/Saturn/Saturn.fsproj#L28 So maybe edited: kcr, adding snippet
|
FWIW @Krzysztof-Cieslak, you only need that framework reference because the SDK in the project file isn't set to the SDK for aspnetcore: |
Similarly for the Windows Desktop stuff, if you use the matching SDK some set of the framework references are handled for you (based on those msbuild properties mentioned), so I wonder how much of this request is around framework references specifically, vs importing and using SDKs? |
@baronfel , so it could also look like?
So #r "nuget: sdk=Microsoft.AspNetCore.App" I think I like @Krzysztof-Cieslak 's suggestion it's a bit crisper, and @cartermp has suggested there may be several, frameworkreference is a bit easier to read in the project file. |
<Project Sdk="Microsoft.NET.Sdk.Web">
</Project> Of course it would be too clear if the names matched up. |
@baronfel , never underestimate our ability to evade clarity :-) |
Yeah, having the names match up with the SDK names would be ideal. Is that something we'd considering keeping track of in the dependency manager? I highly doubt these names will change over time, since that would also mean that all visual studio tooling and SDK stuff would have to change as well. |
@cartermp |
@cartermp Just putting this out here: https://twitter.com/mmwaikar/status/1388773735520292868 |
would this also allow aspnetcore from fsx for example? :) would be awesome |
is there any workarounds atm to run aspnet from .fsx from net7/net8? @cartermp @vzarytovskii i think in here F# could possibly "shine" against compiled C# minimal api for it's simplicity ? resembling much python simplicity (or suave) but aspnet comes with many nice built-ins.. (e.g. ability to use Giraffe in fsx) |
I'm not aware of any. Wondering if notebooks include it implicitly and can be used to run it @jonsequitur @colombod |
I ended up with this as a workaround. This generates a set of scripts you can use with the With this I was able to get Giraffe running in FSI session. #load "runtime-scripts/Microsoft.AspNetCore.App-7.0.3.fsx"
#r "nuget: Giraffe"
open System
open Microsoft.AspNetCore.Builder
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open Giraffe
let webApp =
choose [
route "/ping" >=> text "pong"
route "/" >=> htmlFile "/pages/index.html" ]
type Startup() =
member __.ConfigureServices (services : IServiceCollection) =
// Register default Giraffe dependencies
services.AddGiraffe() |> ignore
member __.Configure (app : IApplicationBuilder)
(env : IHostEnvironment)
(loggerFactory : ILoggerFactory) =
// Add Giraffe to the ASP.NET Core pipeline
app.UseGiraffe webApp
let main _ =
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(
fun webHostBuilder ->
webHostBuilder
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
main () |
@TheAngryByrd i tried your workaround generating the scripts folder as you suggested, it works! if you have the below error the import is not correct (the error is misleading, maybe somethign to change in general for fsharp fsi when loading scripts.... i had this when i had and i didnt figure the error
here is the working one! do not prepend ./ or / . cheers! #load "runtime-scripts/Microsoft.AspNetCore.App-6.0.15.fsx"
open System
open Microsoft.AspNetCore.Builder
let builder = WebApplication.CreateBuilder()
let app = builder.Build()
let helloWorldHandler = System.Func<_>(fun () -> "Hello World!")
app.MapGet("/", helloWorldHandler)
app.Run()
|
Also the script is a bit misleading, as i clearly have less than 25 lines of code, it points in the wrong portion of code (maybe due to load?) |
|
loading with
this version works, thanks a lot @TheAngryByrd !!!!
|
I have a more refined version in IcedTasks where it also creates a load script per major version so it's a bit more "stable" when referencing and updating your runtimes. |
Hello, it seems in dotnet script they use this for framework reference, maybe it could be a great idea to reuse that same syntax if possible?
https://github.com/dotnet-script/dotnet-script#specifying-an-sdk |
Hello, news on this topic, is it on roadmap for F#9 ? have a great day! |
It is not |
@cartermp @TheAngryByrd any news/suggestions on this topic, what would it take potentially to add a new |
reporting this for context if anyone else want to try (add this to
|
In F# 5, we'll have `#r "nuget:...". However, there are some first-party frameworks where this won't work:
ASP.NET Core 2.x used is just a few NuGet packages, so it's possible to write an F# script that uses that to do some webby stuff. But if you want you use the latest ASP.NET Core, you need to magically know the closure of every assembly in the ASP.NET Core framework reference, reference those, and then use it. Horrible experience.
Also, the old school F# scripts that used to launch WinForms currently can't do this with .NET Core (on Windows). This is because WinForms and WPF both use the Windows Desktop framework reference, and an additional MSBuild property to tell the build system which additional references to pull in (
UseWinForms
andUseWPF
). Both can be specified at the same time. We may want to have a think about what it would mean to support these.tagging his majest, @KevinRansom
The text was updated successfully, but these errors were encountered: