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

Initial checkin of some samples and a readme #1

Merged
merged 2 commits into from
Apr 7, 2014
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
19 changes: 19 additions & 0 deletions GetRuntime.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@echo off
cd %~dp0

SETLOCAL
SET CACHED_NUGET=%LocalAppData%\NuGet\NuGet.exe

IF EXIST %CACHED_NUGET% goto copynuget
echo Downloading latest version of NuGet.exe...
IF NOT EXIST %LocalAppData%\NuGet md %LocalAppData%\NuGet
@powershell -NoProfile -ExecutionPolicy unrestricted -Command "$ProgressPreference = 'SilentlyContinue'; Invoke-WebRequest 'https://www.nuget.org/nuget.exe' -OutFile '%CACHED_NUGET%'"

:copynuget
IF EXIST .nuget\nuget.exe goto restore
md .nuget
copy %CACHED_NUGET% .nuget\nuget.exe > nul

:restore
IF EXIST packages\KoreBuild goto run
.nuget\NuGet.exe install ProjectK -o packages -nocache -pre
30 changes: 30 additions & 0 deletions K.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET CURRDIR=%CD%
SET PARENTDIR=!CURRDIR!

:START
IF EXIST !CURRDIR!\packages\ProjectK* FOR /F %%I IN ('DIR !CURRDIR!\packages\ProjectK* /B /O:-D') DO (SET ProjectKDir=%%I& GOTO :ENDFOR)
:ENDFOR

SET LocalKCmd=!CURRDIR!\packages\!ProjectKDir!\tools\k.cmd

IF NOT EXIST !LocalKCmd! (
CALL :RESOLVE "!CURRDIR!\.." PARENTDIR
IF !CURRDIR!==!PARENTDIR! (
ECHO Unable to locate the ProjectK runtime
ENDLOCAL & EXIT /b 1
) ELSE (
SET CURRDIR=!PARENTDIR!
GOTO :START
)
)

CALL "!LocalKCmd!" %*
ENDLOCAL & EXIT /b %ERRORLEVEL%

:RESOLVE
SET %2=%~f1
GOTO :EOF
13 changes: 13 additions & 0 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="AspNetVNext" value="https://www.myget.org/F/aspnetvnext/" />
<add key="NuGet.org" value="https://nuget.org/api/v2/" />
</packageSources>
<packageSourceCredentials>
<AspNetVNext>
<add key="Username" value="aspnetreadonly" />
<add key="ClearTextPassword" value="4d8a2d9c-7b80-4162-9978-47e918c9658c" />
</AspNetVNext>
</packageSourceCredentials>
</configuration>
61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#What is this?

The Preview repository is a place for the ASP.NET Insiders to log issues and discuss ASP.NET vNext with the product team.

The samples provided are designed to show some of the features of the new framework as well as setting up a sandbox for you to try out new drops of functionality as they come out. The NuGet.config file in the repo points to a private MyGet feed that has all the packages being developed. The feed is updated every time a full build succeeds.

**The K.cmd file in the root of this repo is designed to be able to be put in your path. It will probe various locations relative to your current directory to find the KRuntime that it should use. All the steps after this will assume you've done this, so that you can just type ```K Run``` from anywhere. If you choose not to then add the appropriate number of folder traversals (..\\) before each K command.**

#Samples

##Sandbox Samples

These samples, in this repo, are just basic starting points for you to experiment with features. Since there is no File->New Project we thought some simple samples to take the place of scaffolding would be convenient.

+ HelloConsole. This is just basic console app if you want to use it as a starting point. Use it the same as the console app from our earlier samples
+ HelloWeb. This is a minimal startup class that shows welcome page and static file middleware. This is mostly for you to run through the steps in the readme and make sure you have everything setup and working correctly.
+ HelloWebFx. This sample is a basic MVC app. It is not designed to show all the functionality of the new web stack, but to give you a starting point to play with features.

##Feature Samples
The Entropy repo contains samples of specific features in isolation. Each directory contains just enough code to show an aspect of a feature.

##Application Samples
MVC Music Store and BugTracker application are both being ported. Each of these have their own repository that you can look at as they are working.

#Running the samples

##Bootstrapping the runtime
Before you can use the runtime commands to launch your application, you need to have the runtime commands. To do this there is a GetRuntime.cmd file in the root of the repository.

1. Run ```GetRuntime.cmd```
2. This should use NuGet.exe to get the runtime from MyGet and put it in a packages folder. One of the things currently containined in the runtime is a modified version of NuGet.exe that you should use for everything other than getting the runtime itself.

##Running HelloWeb

1. Clone the repository
2. Change directory to Preview\Samples\HelloWeb
3. Run ```K restore```
4. You should see a bunch of output as all the dependencies of the app are downloaded from MyGet. The K commands all operate on the app that is in the current directory.
5. Run ```K web```
6. You should see build output and a message to show the site is now started
7. Navigate to "http://localhost:5001"
8. You should see the welcome page
9. Navigate to "http://localhost:5001/image.jpg"
10. You should see an image served with the static file middleware

If you can do all of the above then everything should be working. You can try out the WebFx sample now to see some more of the new stack. You should run ```K restore``` before using any sample for the first time.

#Switching to Core CLR

By default when running the applications you are running against Desktop CLR (4.5), you can change that by setting the TARGET_FRAMEWORK variable:

1. Run ```set TARGET_FRAMEWORK=k10```
2. Run ```K web```
3. The first line of your output should say "Loaded Module: klr.core45.dll" instead of "Loaded Module: klr.net45.dll"
4. The HelloWeb app should work the same as when running on Desktop CLR.

**NOTE: There are going to be parts of the stack that work on Desktop but do not work on Core CLR. This set should get smaller and smaller as time goes on, but it is entirely likely as you use Core CLR you will hit errors that can't be worked around as the Core CLR surface area just does not exist yet. An example of this type of problem is using Entity Framework with a database. There are not currently any real database providers that work on Core CLR, so you will be restricted to in-memory EF on Core CLR.**

#Core CLR Packages

Currently the BCL is split into some fairly fine grained packages, which was one of the goals of this effort. However, the packages that exist today do not necessarily represent the list of packages that we will end up with. We are still experimenting with what makes sense to be a package and what the experience should be.
9 changes: 9 additions & 0 deletions samples/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

public class Program
{
public static void Main()
{
Console.WriteLine("Hello World");
}
}
13 changes: 13 additions & 0 deletions samples/ConsoleApp/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"dependencies" : {
},
"configurations": {
"net45" : {},
"k10": {
"dependencies": {
"System.Runtime": "4.0.20.0",
"System.Console": "4.0.0.0"
}
}
}
}
14 changes: 14 additions & 0 deletions samples/HelloWeb/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet;

namespace KWebStartup
{
public class Startup
{
public void Configuration(IBuilder app)
{
app.UseStaticFiles();
app.UseWelcomePage();
}
}
}
Binary file added samples/HelloWeb/image.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions samples/HelloWeb/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
"Microsoft.AspNet.Diagnostics":"0.1-alpha-*",
"Microsoft.AspNet.StaticFiles":"0.1-alpha-*"
},
"commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
"configurations": {
"net45": {
},
"k10": {
"dependencies": {
"System.Console": "4.0.0.0",
"System.Collections": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.IO": "4.0.0.0",
"System.IO.FileSystem": "4.0.0.0",
"System.IO.FileSystem.Primitives": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
"System.Runtime.InteropServices": "4.0.10.0",
"System.Text.Encoding": "4.0.10.0",
"System.Threading.Tasks": "4.0.0.0"
}
}
}
}
24 changes: 24 additions & 0 deletions samples/HelloWebFx/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.AspNet.Mvc;
using MvcSample.Web.Models;

namespace MvcSample.Web
{
public class HomeController : Controller
{
public IActionResult Index()
{
return View(User());
}

public User User()
{
User user = new User()
{
Name = "My name",
Address = "My address"
};

return user;
}
}
}
13 changes: 13 additions & 0 deletions samples/HelloWebFx/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.ComponentModel.DataAnnotations;

namespace MvcSample.Web.Models
{
public class User
{
[Required]
[MinLength(4)]
public string Name { get; set; }
public string Address { get; set; }
public int Age { get; set; }
}
}
33 changes: 33 additions & 0 deletions samples/HelloWebFx/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Microsoft.AspNet.Abstractions;
using Microsoft.AspNet.DependencyInjection;
using Microsoft.AspNet.DependencyInjection.Fallback;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.RequestContainer;
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Diagnostics;
using Microsoft.AspNet;

namespace KWebStartup
{
public class Startup
{
public void Configuration(IBuilder app)
{
var services = new ServiceCollection();
services.Add(MvcServices.GetDefaultServices());
var serviceProvider = services.BuildServiceProvider(app.ServiceProvider);

var routes = new RouteCollection
{
DefaultHandler = new MvcApplication(serviceProvider)
};

routes.MapRoute("{controller}/{action}", new { controller = "Home", action = "Index" });

app.UseErrorPage();
app.UseContainer(serviceProvider);
app.UseRouter(routes);
app.UseWelcomePage();
}
}
}
16 changes: 16 additions & 0 deletions samples/HelloWebFx/Views/Home/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@using MvcSample.Web.Models
@model User
@{
Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Home Page";
string nullValue = null;
}

<div class="jumbotron">
<h1>ASP.NET</h1>
<p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p>
<p><a href="http://asp.net" class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>
<div class="row">
<h3 title="@Model.Name" class="@nullValue">Hello @Model.Name!</h3>
</div>
40 changes: 40 additions & 0 deletions samples/HelloWebFx/Views/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" />
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/">Home</a></li>
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<address>
@if (@Model != null)
{
@Model.Address
}
</address>
<footer>
<p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
</footer>
</div>
</body>
</html>
49 changes: 49 additions & 0 deletions samples/HelloWebFx/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"version": "0.1-alpha-*",
"dependencies": {
"Microsoft.AspNet.Abstractions": "0.1-alpha-*",
"Microsoft.AspNet.Hosting": "0.1-alpha-*",
"Microsoft.AspNet.Server.WebListener": "0.1-alpha-*",
"Microsoft.AspNet.DependencyInjection": "0.1-alpha-*",
"Microsoft.AspNet.RequestContainer": "0.1-alpha-*",
"Microsoft.AspNet.Routing": "0.1-alpha-*",
"Microsoft.ComponentModel.DataAnnotations": "4.0.10.0",
"Microsoft.AspNet.Mvc.ModelBinding": "0.1-alpha-*",
"Microsoft.AspNet.Mvc.Core": "0.1-alpha-*",
"Microsoft.AspNet.Mvc": "0.1-alpha-*",
"Microsoft.AspNet.Mvc.Razor": "0.1-alpha-*",
"Microsoft.AspNet.Mvc.Rendering": "0.1-alpha-*",
"Microsoft.AspNet.ConfigurationModel": "0.1-alpha-*",
"Microsoft.AspNet.Diagnostics":"0.1-alpha-*"
},
"commands": { "web": "Microsoft.AspNet.Hosting server.name=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001" },
"configurations": {
"net45": {
"dependencies": {
"System.ComponentModel.DataAnnotations": ""
}
},
"k10": {
"dependencies": {
"System.Console": "4.0.0.0",
"System.Collections": "4.0.0.0",
"System.Diagnostics.Debug": "4.0.10.0",
"System.Diagnostics.Tools": "4.0.0.0",
"System.Globalization": "4.0.10.0",
"System.IO": "4.0.0.0",
"System.IO.FileSystem": "4.0.0.0",
"System.IO.FileSystem.Primitives": "4.0.0.0",
"System.Linq": "4.0.0.0",
"System.Reflection": "4.0.10.0",
"System.Resources.ResourceManager": "4.0.0.0",
"System.Runtime": "4.0.20.0",
"System.Runtime.Extensions": "4.0.10.0",
"System.Runtime.InteropServices": "4.0.10.0",
"System.Text.Encoding": "4.0.10.0",
"System.Threading.Tasks": "4.0.0.0",
"System.ComponentModel": "4.0.0.0",
"System.Dynamic.Runtime": "4.0.0.0"
}
}
}
}