Open uglycoyote opened 5 years ago
Nancy VS WebApi Performance
Not sure about Mono, but I've had Nancy working fine using .NET Core - is that an option for you?
Regarding the global.json
error, it's saying that Nancy is pinned to .NET Core SDK 2.1.4, so you need to install that or change global.json
to match a .NET Core SDK that you have installed.
** Disclaimer: Not a member of the Nancy team, just an end user
@cocowalla Thanks for the tip about global.json
, it seems to have built (On Ubuntu in WSL) when I changed the version there to my installed version of 2.2.401
. The tests failed
Nancy.ViewEngines.DotLiquid.Tests.csproj only supports net452 and cannot be built on *nix. Skipping.
Nancy.ViewEngines.Markdown.Tests.csproj only supports net452 and cannot be built on *nix. Skipping.
Nancy.ViewEngines.Razor.Tests.csproj only supports net452 and cannot be built on *nix. Skipping.
Nancy.ViewEngines.Razor.Tests.Models.csproj only supports net452 and cannot be built on *nix. Skipping.
Nancy.ViewEngines.Spark.Tests.csproj only supports net452 and cannot be built on *nix. Skipping.
and contrary to what the how_to_build.txt
file says, nothing ended up in the build
directory, though there are lots of DLL's scattered through the src
directory which were just created by the build process.
I'm not quite sure where to go next with setting up an introductory project in this environment, since again the introductory instructions assume use of Visual Studio, and I'm new to the .NET Core / Linux C# development environment.
I tried the following:
dotnet new console -o Test
to make a test applicationdotnet add package Nancy
to install Nancy as a dependency of my Test applicationProgram.cs
in my test application to look like the very attractive sample code on the front page of the Nancy website:public class SampleModule : Nancy.NancyModule
{
public SampleModule()
{
Get["/"] = _ => "Hello World!";
}
}
This resulted in an error Cannot apply indexing with [] to an expression of type 'method group' (CS0021) [Test]
which further stack overflow searching led me to understand that that's not the syntax that Nancy uses anymore and that the front page and most of the samples are out of date.
The following works, but the compiler still complains that I need a Main
or suitable entry point
public class SampleModule : Nancy.NancyModule
{
public SampleModule()
{
Get("/", _ => "Hello Mike");
}
}
It is not clear to me based on the Getting Started instructions where the program entry point is supposed to come from, or what it should contain, it feels like there's something that I am missing entirely here!
Still not on the super-duper-happy path and any pointers would be appreciated.
I've never actually built Nancy from sources; I just used the NuGet packages :smile:
Regarding the entrypoint, you are still going to need a Program.cs with a Main method, which needs to initialise Nancy. Nancy Modules are the equivalent of MVC's Controllers, so these are in addition to your Program.cs.
What's shown on the Nancy website is very outdated - the wiki on the GitHub page is a much more authorative source, so I'd recommend starting there. The sample projects in the GitHub repo are also a great way to get started.
TBH, I think Nancy's super-duper-happy-path is no more. You should consider ASP.NET MVC Core instead - it's vastly improved over it's predecessors, and so much more extensible than it used to be. I guess this is the main reason why Nancy is so inactive now.
I recently migrated a project away from Nancy to ASP.NET MVC Core, and I'm really happy with it. If you particularly like the Nancy routing style, you should check out the Carter GitHub repo - it's a popular library that adds Nancy style routing to ASP.NET Core.
@cocowalla Thanks for your super-duper-honest reply! Yes after banging my head against this in a few separate sessions, it might be best to take a step back and re-evaluate. My end goal is to create a back-end REST server for a Unity game.
I have written such things in Python before using Flask which has a similarly super-duper-happy looking 10 line sample program to make a server which returns "Hello World", with the difference that I can do pip install Flask
and get this sample running in about a minute.
The main reason I'm looking towards C# for the server side of this rather than sticking with what I know is that in Unity the game code is written in C#, and I want to be able to run some of the same game-update code on the server side that I currently run on the "client" (user's game) side.
I was attracted to Nancy because:
Ironically, although I assumed ASP.NET was much more complex, I sort of accidentally got some ASP.NET samples working while I was in the process of installing dotnet
, while I still haven't figured out how to get a Hello World sample running with Nancy.
Perhaps I'll follow your suggestion and check out ASP.NET a bit more deeply. Thanks!
Your front page is very appealing with the 1-line installation and 5-line code sample and the word GO! The emphasis on the "super duper happy path" is also appealing.
Unfortunately I'm finding that my onboarding experience is failing to live up to these lofty expectations.
I am looking at the "Creating your first Nancy application" section on the Introduction page. Firstly I have Visual Studio 2017 installed. The instructions say "If using Visual Studio 2012 or greater, install the SideWaffle Template Pack for Visual Studio."
Unfortunately, when going to the sidewaffle page I see a big banner that says "Templates for Visual Studio 2012/2013/2015". I assumed that it must still work in VS2017, so I tried downloading their installer. The installer actually only offered to install on VS 2015, and VS 2017 was not an option. I thought I would try from the other angle and install using the Extension search from inside VS 2017. This was another time-consuming sidetrack, I made the mistake of accidentally thinking that "sidewaffle.create" was the sidewaffle package for creating things that sidewaffle creates, when it fact it is a package for creating new templates for other people to create things using sidewaffle. Once past that confusion I found that there was an issue on their tracker about VS 2017 support. It looks to be going nowhere. About a year ago someone put together this hack to allow sidewaffle to install in VS2017 but it has yet to have been officially updated.
Since my end goal is to get Nancy working under linux, and since the Nancy introduction says that it "works equally as well on Mono and Monodevelop" I thought I would try that route under Ubuntu in WSL. This was also a rocky road.
The introduction is not really clear about what "works equally well on Mono" mean, since the steps below that all assume you have Visual Studio, and I assume that Sidewaffle is not a thing for Mono. Since the instructions here were not giving any more hints I thought I would follow the short introductory statement on the Nancy project's front page:
I have been attempting to run
build.sh
under Ubuntu on WSL. Since the instructions above had the word "simply" and did not mention any prerequisites, I took this to mean that any prerequisites I did not already have would be installed for me.Initially it failed due not having Mono yet installed.
I installed mono using the instructions on the mono download page, and tested some mono samples to make sure mono was working.
After installing Mono, I was stuck on the
Restore-NuGet-Packages
step of thebuild.sh
script for a long time. The output contained/mnt/d/Mike/Dev/Nancy/Nancy/.dotnet/dotnet: No such file or directory
, which I took to mean that I should also installdotnet
.I then followed Dotnet SDK instructions found here
After doing so and re-running
build.sh
I get the following outputI'm not really sure where to go from here. It seems to be acting as though I did not install
dotnet
, trying to install it, failing, and then erroring out about dotnet not being present. In fact I can rundotnet
on the command line without troubles.Updated instructions on the most super duper happy way to get started either in VS2017 or in Ubuntu would be fantastic.