Nancy support for .NETCoreApp - asp.net-core

Trying to add the Nancy package to a new project. In project.json (dependencies segment) red squigly under "Nancy": "1.4.3". Mouseover displays an error relating to support for .NETCoreApp

The master branch of Nancy on github already runs on .net core.We are moving from Rake to Cake for the build script , hoping to wrap that up this week so .netcore support can be pushed to Nuget.So yes wait just a bit.

This example was original written on Stack Overflow Documentation:
Setup Nancyfx with Dotnet core v1.1, Kestrel, and Visual Studio Code on *nix systems
Prerequiste steps:
Get dotnet core for your platform:
Dotnet Core
Follow instructions and make sure dotnet core is working
Get Visual Studio Code for your platform:
VS Code
Launch Visual Studio Code (VS code) and install the C# extension then reload
Create self hosted NancyFx project:
Setup a project with a correct project directory structure.
Open Bash Terminal and type:
mkdir nancydotnetcore
cd nancydotnetcore
mkdir src
mkdir test
touch global.json
Open global.json and enter the following code:
{
"projects":["src", "test"]
}
In Bash terminal:
cd src
mkdir NancyProject1
dotnet new
Open folder NancyProject1 in VS code
You will get a warning: "Required assets to build and debug are missing from 'nancyproject1'."
Click "Yes"
Also you will see: There are unresolved dependencies from 'project.json'. Please execute the restore command to continue.
Click "Close" we will get to this soon.
Add the dependencies, open "project.json" and overwrite it with the following:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.1": {
"dependencies": {
"Microsoft.AspNetCore.Hosting": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.AspNetCore.Owin": "1.1.0",
"Nancy": "2.0.0-barneyrubble",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0"
}
}
}
}
}
VS code will ask to restore click "Restore"
Create folder "Modules" in VSCode project
In the Modules folder add a file named "IndexModule.cs" then copy and save the following:
namespace NancyProject1
{
using Nancy;
public class IndexModule : NancyModule
{
public IndexModule()
{
Get("/", _ => "Hello dotnet core world!");
}
}
}
In the root directory of the project create a file called "Startup.cs" and copy and paste the following:
namespace NancyProject1
{
using Microsoft.AspNetCore.Builder;
using Nancy.Owin;
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.UseOwin(x => x.UseNancy());
}
}
}
Open file "Program.cs" and overwrite the content with the following and save:
namespace NancyProject1
{
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseKestrel()
.UseStartup()
.Build();
host.Run();
}
}
}
Done! Now lets run this and see the output.
Click the debug symbol in VS Code, and Click the run button. It should compile and start the project.
Open the browser # http://localhost:5000
Pat yourself on the back and enjoy!
still pre release version but works with .net core as the time of this writing, view engines are very limited on core.

Install-Package Nancy -Version 2.0.0-barneyrubble -Pre

Related

Nunit.framework dll from the package doesnt get copied to bin folder

I'm currently running .net framework 4.6 and added the NUnit, NUnit3TestAdapter nuget package to the test project that i am working on and I see that the test's are not being discovered.
Upon some investigtion, I see that nunit.framework.dll is not being copied to the bin folder. Did some more research and I see the following in the assets.json file, and Nunit's build/NUnit.props file which is supposed to have the MSBuild settings is empty and does not have any.
"NUnit/3.13.3": {
"type": "package",
"compile": {
"lib/net45/nunit.framework.dll": {}
},
"runtime": {
"lib/net45/nunit.framework.dll": {}
},
"build": {
"build/NUnit.props": {}
}
},
However Nbuild/Unit3TestAdapter.props file which is installed from the official Nunit has the MSBuild settings. Is there a reason why build/NUnit.props does not have the build setting where as build/Unit3TestAdapter.props has these?
Also, Is there a work-around to get these copied to local or should I add the reference's manually than getting these from the package?

AspNetCore namespace doesnt exist

I'm following this course to learn ASP.NET Core.
I did exactly as they did, I can type dotnet new and dotnet restore.
I also installed the dotnetcore 1.0.1 SDK preview.
All seems fine, and I should be able to type
using Microsoft.AspNetCore.Http;
But the only things recognized after Microsoft are cSharp, visualbasic and win32?
Here is my project.json file:
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true
},
"dependencies": {},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.AspNet.WebApi": "5.2.3",
"Microsoft." **<< i cannt type AspNetCore here**
},
"imports": "dnxcore50"
}
}
There is no Microsoft."AspNetCore". The only things I do have starting with Asp are:
AspNet.Identity.Owin
AspNet.Mvc
AspNet.Providers.Core
AspNet.Razor
AspNet.SignalR
AspNet.Web.Optimization
AspNet.WebApi
AspNet.WebApi.Clients
AspNet.WebApi.Core
AspNet.WebApi.Cors
AspNet.WebPages
The code completion doesn't always work when editing the project.json file, especially if you're using a lighter editor like VS Code. (Sometimes it doesn't work even in full-blown Visual Studio).
If this happens, don't worry! You can still install any packages you need. Find packages by searching on NuGet and then edit the dependencies section like this:
"PackageName": "1.0.0" # Version from package details on NuGet
Then, use the dotnet restore command within the project directory to pull down all the packages in project.json.

ASP .NET 5 Empty Project returns 500 Internal Server Error

I've created a new Web Application, using the empty ASP .NET 5 preview template. The project builds after I run dnu restore.
When I run it, I get an empty response (i.e. blank page). Refreshing the page, I get a "HTTP Error 500.0 - Internal Server Error" typical page with no useful info (see screenshot below).
I'm using the standard boilerplate code from the project template:
public class Startup
{
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}
public void Configure(IApplicationBuilder app)
{
app.Run(async (context) =>
{
await context.Response.WriteAsync("Hello World!");
});
}
}
I noticed that if I set a breakpoint, it tells me the breakpoint won't be hit.
What am I doing wrong, and how can I get this simplest of scenarios working?
Edit: project.json is the default one that comes with the project template (uses beta 5, which I know is not the latest):
{
"webroot": "wwwroot",
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta5"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
]
}
It's just crazy what I had to go through to make this work. Summary:
Go to %userprofile%, delete everything in .dnx\packages (just to make sure there aren't conflicts between different beta runtime versions)
Make sure latest runtime is being used
dnu restore
Replace dependencies in project.json as per this answer
As per comment below that answer, replace "Microsoft.AspNet.Hosting --config hosting.ini" with "Microsoft.AspNet.Server.Kestrel"
In Startup.cs, replace using Microsoft.Framework.DependencyInjection; with using Microsoft.Extensions.DependencyInjection;
Run project with command line invoking dnx web, NOT from Visual Studio
Moral of the story: the "preview template" that comes with Visual Studio is WAY out of date, and you're better off starting a fresh project.
Note: at the time of writing, the latest runtime is 1.0.0-rc1-update1.

System.InvalidOperationException : Migration failed

My solution have 3 projects :
Web (i added the connection string in the appsetting file)
Business (contains models class)
Infrastructure (contains DbContext)
I tried to make a migration :
dnx ef migration add firstMigration -s Web
I had this error :
System.InvalidOperationException: The current runtime target framework is not compatible with 'Infrastructure'.
Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)'
Version: 1.0.0-rc1-16202
Type: Clr
Architecture: x86
OS Name: Windows
OS Version: 10.0
Runtime Id: win10-x86
Please make sure the runtime matches a framework specified in project.json
When i put dnvm list, i have 1.0.0-rc1-final like a default runtime and i don't find 1.0.0*rc1-16202 in the list ?
The projet.json file of Infrastuture project is :
"frameworks": {
"dotnet5.4": {
},
"net451": {
"EntityFramework.Commands": "7.0.0-rc1-final",
"frameworkAssemblies": { "System.Runtime": "4.0.10.0" }
}
}
I had the same problem and I solved it by changing "net451" to "dnx451" in the project.json file under the "frameworks" object.
It's ok now, it was my mistake : i executed the command (dnx ef migrations add) in Infrasturtucre folder instead of web folder.

How do I add a reference to a mono assembly in asp.net vNext

So I've installed Asp.net vNext onto my Linux box and have been playing around with it. I have everything set up and can build and run mvc applications. I'm building a console application and need to reference an assembly that doesn't exist in NuGet. I want to add a reference to Mono.Data.SqliteClient to my project.json. I know the path to the assembly /usr/local/lib/mono/4.5/Mono.Data.Sqlite.dll.
How do I add the reference to the dll? My project.json file currently looks like this:
{
"dependencies": {
"System.Console": "4.0.0.0",
"Dapper":"1.27",
"Mono.Data.Sqlite":""
},
"configurations": {
"net45": {},
"k10": {}
}
}
I found the answer on a forum...
In a nutshell, you can only reference your dlls if they are inside a nuget package... ( I hope this will be improved. It is a hassle IMO. )
The long story :
Ok, after a lot of fannying about, it seems that the way to do this is to create a nuget package using the DLL (i'll use Quartz version 2.2.4.400 as an example).
use http://docs.nuget.org/docs/creating-packages/using-a-gui-to-build-packages to build it. Drag and drop Quartz.dll into the right hand side (nb. it does need to be placed in the lib directory). File -> save as... save it in the following location:
projectRoot\packages\Quartz.2.2.4.400\Quartz.2.2.4.400.nupkg
With the dll in the following:
projectRoot\packages\Quartz.2.2.4.400\lib\Quartz.dll
nb. placing the DLL outside of the lib directory will compile alright, but won't work with intellisense. If you are compiling with a specific version, then i'd put it in a net45, net451 or k10 folder; as i'm not, I didn't bother. my project.json then looks like:
{
"dependencies": {
"Quartz" : "2.2.4.400"
},
"configurations" : {
"k10" : {
"dependencies": {
"System.Console": "4.0.0.0"
}
}
}
}