Skip to content
This repository has been archived by the owner on Oct 31, 2021. It is now read-only.

upgrade to rc2, add embedded resources, fix test/dnx run/dnx web #24

Merged
merged 9 commits into from
Dec 17, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions FSharp.Dnx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "HelloFSharp", "sample\Hello
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "HelloMvc", "sample\HelloMvc\HelloMvc.xproj", "{F1623F56-EA17-429D-989A-99CB6F2E8EEA}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "HelloMvc.Views", "sample\HelloMvc.Views\HelloMvc.Views.xproj", "{4437BEFB-4824-406C-9B43-745F90C748D2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C8628CB9-DE7A-44B7-8097-874690D0B030}"
ProjectSection(SolutionItems) = preProject
global.json = global.json
NuGet.Config = NuGet.Config
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FSharp.Dnx.UnitTests", "test\FSharp.Dnx.UnitTests\FSharp.Dnx.UnitTests.xproj", "{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -47,10 +47,10 @@ Global
{F1623F56-EA17-429D-989A-99CB6F2E8EEA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F1623F56-EA17-429D-989A-99CB6F2E8EEA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F1623F56-EA17-429D-989A-99CB6F2E8EEA}.Release|Any CPU.Build.0 = Release|Any CPU
{4437BEFB-4824-406C-9B43-745F90C748D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4437BEFB-4824-406C-9B43-745F90C748D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4437BEFB-4824-406C-9B43-745F90C748D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4437BEFB-4824-406C-9B43-745F90C748D2}.Release|Any CPU.Build.0 = Release|Any CPU
{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -60,6 +60,6 @@ Global
{BF35EB0A-4C51-4685-BFD8-8B5EB3DEA5CA} = {48B5D8BF-426D-4221-BB16-0C76E9792999}
{4DC29E60-1C63-477F-AA34-67B5E65775FB} = {4BC77B28-AC2E-416A-8D2F-491819D5FFD5}
{F1623F56-EA17-429D-989A-99CB6F2E8EEA} = {4BC77B28-AC2E-416A-8D2F-491819D5FFD5}
{4437BEFB-4824-406C-9B43-745F90C748D2} = {4BC77B28-AC2E-416A-8D2F-491819D5FFD5}
{92972DE0-CAE0-42F8-A78B-4C77CAF1DF66} = {48B5D8BF-426D-4221-BB16-0C76E9792999}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<add key="Roslyn" value="https://www.myget.org/F/roslyn-nightly/api/v3/index.json" />
<add key="Asp.NET vNext" value="https://www.myget.org/F/aspnetvnext/api/v3/index.json" />
<add key="Nuget Central" value="https://api.nuget.org/v3/index.json" />
<add key="xunit" value="https://www.myget.org/F/xunit/api/v3/index.json" />
</packageSources>
</configuration>
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
FSharp.Dnx
===

This project depends on [aspnet/dnx](github.com/aspnet/dnx)

| branch | aspnet/dnx version |
|---------|---------------------|
| master | latest development version ( now 1.0.0-rc2-* ) |
| release | 1.0.0-rc1-final |

# Usage

Examples app:

- command line, see `sample/HelloFSharp`
- asp.net mvc, see `sample/HelloMvc`

# Development

more info in `docs/development.md`

prepare the environment

```
dnvm upgrade -u
dnu restore
```

After that, you can:

- use the `FSharp.Dnx.sln` solution
- execute commands from a shell

NOTE: the `dnvm upgrade -u` install latest unstable version and change
the `default` alias ( it's a global config per user, used by ides like Visual Studio )
To revert to latest stable, do `dnvm upgrade`

## From shell

### run a sample command line app

from `sample/HelloFSharp` directory

```
dnx run
```

expected

```
Hello from F#, running on DNX v4.5.1
```

### run a sample asp.net mvc app

from `sample/HelloMvc` directory

```
dnx web
```

expected

```
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
```

open a brower in [http://localhost:5000](http://localhost:5000)


### execute tests

from `test/FSharp.Dnx.Test` directory

```
dnx test
```
56 changes: 56 additions & 0 deletions docs/development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
The flow is

1. upgrade dnvm to latest unstable ( or install latest unstable and use that )
2. restore dependencies with `dnu restore`
3. run samples with `dnx run`/`dnx web` or tests with `dnx test`

NOTE:

Upgrading dnvm change the `default` alias and the dnvm version in `PATH`.

It's a global config per user, and `default` alias is used by ide like Visual Studio if sdk property
in global.json file is not specified.

dnvm doesnt [care about global.json](https://github.com/aspnet/dnvm/issues/271)

## How to revert to latest stable version of dnvm

To revert to latest stable version of dnvm do

```
dnvm upgrade
```

### 1- Upgrade to latest unstable dnvm

Open a shell inside this repository directory

```
dnvm upgrade -u
```

### 2- Restore dependencies

You can use the command

```
dnu restore
```

# Useful tips for dnvm/dnu/dnx

## enable trace info for debugging

set `DNX_TRACE` environment variable to `1`


for example

```
set DNX_TRACE=1
dnu build
```

should print lots of logging info


6 changes: 6 additions & 0 deletions sample/HelloFSharp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
"dependencies": {
"FSharp.Dnx": { "type": "build", "version": "" }
},
"compilationOptions": {
"emitEntryPoint": true
},
"commands": {
"HelloFSharp": "HelloFSharp"
},
"frameworks": {
"dnx451": { }
},
Expand Down
2 changes: 0 additions & 2 deletions sample/HelloMvc.Views/Views/Home/Index.cshtml

This file was deleted.

21 changes: 0 additions & 21 deletions sample/HelloMvc.Views/compiler/preprocess/RazorPreCompilation.cs

This file was deleted.

11 changes: 0 additions & 11 deletions sample/HelloMvc.Views/project.json

This file was deleted.

4 changes: 4 additions & 0 deletions sample/HelloMvc/EmbeddedResources/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<h1>Hello from F#</h1>
<h2>(by Razor)</h2>

Page generated: @Html.Encode(string.Format("{0}", System.DateTime.Now))
9 changes: 7 additions & 2 deletions sample/HelloMvc/project.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"version": "1.0.0-beta-*",
"resource": "EmbeddedResources/**",
"dependencies": {
"FSharp.Dnx": { "type": "build", "version": "" },
"HelloMvc.Views": "",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.Extensions.Logging.Console": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*",
"Microsoft.AspNet.Diagnostics": "1.0.0-*"
"Microsoft.AspNet.Tooling.Razor": "1.0.0-*",
"Microsoft.AspNet.FileProviders.Embedded": "1.0.0-*"
},
"frameworks": {
"dnx451": { }
Expand Down
34 changes: 17 additions & 17 deletions sample/HelloMvc/startup.fs
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
namespace HelloMvc

open System
open System.Reflection
open Microsoft.AspNet.Builder
open Microsoft.AspNet.FileProviders
open Microsoft.AspNet.Mvc.Razor
open Microsoft.Extensions.DependencyInjection
open Microsoft.Extensions.Logging
open Microsoft.AspNet.Hosting

type Startup(env: IHostingEnvironment) =
type Startup() =

// Set up application services
member public x.ConfigureServices (services: IServiceCollection) =
let mvcBuilder = services.AddMvc ()

let viewAssemblies =
[ "HelloMvc.Views" ]
|> List.map Reflection.Assembly.Load
|> Array.ofList

mvcBuilder.AddPrecompiledRazorViews viewAssemblies |> ignore
//Microsoft.Extensions.DependencyInjection.MvcRazorMvcBuilderExtensions.AddPrecompiledRazorViews (mvcBuilder, System.Reflection.Assembly.Load "HelloMvc.Views") |> ignore
services.AddMvc () |> ignore

services.Configure(fun (options: RazorViewEngineOptions) ->
// Base namespace matches the resources added to the assembly from the EmbeddedResources folder.
options.FileProvider <- new EmbeddedFileProvider(
(x.GetType().GetTypeInfo().Assembly),
"HelloMvc.EmbeddedResources")
) |> ignore

()

// Configure pipeline
member public x.Configure (app: IApplicationBuilder, loggerFactory: ILoggerFactory) =
member public x.Configure (app: IApplicationBuilder) =
//loggerFactory.AddConsole (fun (name, logLevel) -> true)
app.UseDeveloperExceptionPage () |> ignore

app.UseStaticFiles () |> ignore

app.UseMvc (fun routes ->
routes.MapRoute (name = "default", template = "{controller=Home}/{action=Index}/{id?}") |> ignore

()) |> ignore
routes.MapRoute (name = "default", template = "{controller=Home}/{action=Index}/{id?}")
|> ignore )
|> ignore
2 changes: 1 addition & 1 deletion src/FSharp.Dnx/CompilationContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Dnx.Compilation;
using Microsoft.Extensions.CompilationAbstractions;

namespace FSharp.Dnx
{
Expand Down
3 changes: 1 addition & 2 deletions src/FSharp.Dnx/FSharpCompilationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.Dnx.Compilation;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.CompilationAbstractions;

namespace FSharp.Dnx
{
Expand Down
3 changes: 1 addition & 2 deletions src/FSharp.Dnx/FSharpCompilationFailure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using Microsoft.Dnx;
using Microsoft.Dnx.Compilation;
using Microsoft.Extensions.CompilationAbstractions;

namespace FSharp.Dnx
{
Expand Down
21 changes: 18 additions & 3 deletions src/FSharp.Dnx/FSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Microsoft.Dnx.Compilation;
using Microsoft.Dnx.Compilation.Caching;
using Microsoft.Extensions.CompilationAbstractions.Caching;
using Microsoft.Extensions.CompilationAbstractions;
using Microsoft.Dnx.Runtime;
using Microsoft.FSharp.Compiler.SimpleSourceCodeServices;
using YoloDev.Dnx.Json;
Expand Down Expand Up @@ -82,6 +82,18 @@ public CompilationContext CompileProject(
args.Add($"--doc:{Path.ChangeExtension(outFile, ".xml")}");
args.AddRange(projectInfo.Files);

var resourcesDir = files.CreateDir();
foreach (var r in resourcesResolver())
{
Logger.TraceInformation("[{0}]: Resource: '{1}' ( filename: '{2}' )", GetType().Name, r.Name, r.FileName);
string resourcePath = Path.Combine(resourcesDir, r.FileName);
using (var fs = File.Create(resourcePath))
{
r.StreamFactory().CopyTo(fs);
}
args.Add($"--resource:{resourcePath},{r.Name}");
}

// These are the metadata references being used by your project.
// Everything in your project.json is resolved and normailzed here:
// - Project references
Expand All @@ -107,7 +119,10 @@ public CompilationContext CompileProject(
args.Add($"-r:{fileName}");
}

//Console.WriteLine(string.Join(Environment.NewLine, args));
#if DEBUG
Logger.TraceInformation("[{0}]: Arguments '{1}'", GetType().Name, string.Join(Environment.NewLine, args));
#endif

var scs = new SimpleSourceCodeServices();
var result = scs.Compile(args.ToArray());
var errors = result.Item1.Select(FSharpDiagnosticMessage.CompilationMessage);
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Dnx/FSharpDiagnosticMessage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.CompilationAbstractions;
using Microsoft.FSharp.Compiler;

namespace FSharp.Dnx
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Dnx/FSharpDiagnosticResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Immutable;
using System.Linq;
using Microsoft.FSharp.Compiler;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.Extensions.CompilationAbstractions;

namespace FSharp.Dnx
{
Expand Down
Loading