Exploring dotnet new with .NET Core
I'm very enjoying the "dotnet" command line. Mostly I do "dotnet new" and then add to the default Hello World app with the Visual Studio Code editor. Recently, though, I realized that the -t "type" and -l "lang" options are there and I wasn't using them. I think they are a little awkward, in that you have to:
dotnet new -t Web
when I think it should be more like dotnet new [type] as in
dotnet new web
What do you think? I find the -t a little heavy. I like the idea of "web" being empty, and "web/mvc" or "web/webapi" having more fleshed out stuff. Even "web/angular," you get the idea. Sound off in the comments. Regardless, there's cool templating tooling coming, I hear, but for now there's more there than I realized.
Of course, there's the default "dotnet new" which is a Hello World console app with a program.cs and project.json. In the future I think it will just run the app, and you'll have to do something like -v verbosity to get the details that we don't usually need to see.
Project console (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
Compiling console for .NETCoreApp,Version=v1.0
Time elapsed 00:00:01.1591124
You can add -l (lang) to it and "dotnet new -l F#" and get an F# Console app rather than a C# one:
C:\Users\scott\Desktop\test\fsharp>dotnet run fabu!
Project fsharp (.NETCoreApp,Version=v1.0) was previously compiled. Skipping compilation.
// Learn more about F# at http://fsharp.org
let main argv =
printfn "Hello World!"
printfn "%A" argv
0 // return an integer exit code
There's also "dotnet new -t lib" which is super basic and gives you a quick new project with a Class1 and an Empty Method. Not so useful, but good to know.
You can also "dotnet new -t xunittest" to make a new test project. Nice that this is built-in! Now I just "dotnet test" after a "dotnet restore" and I get test results!
xUnit.net .NET CLI test runner (64-bit win10-x64)
=== TEST EXECUTION SUMMARY ===
testing Total: 1, Errors: 0, Failed: 0, Skipped: 0, Time: 0.146s
SUMMARY: Total: 1 targets, Passed: 1, Failed: 0.
Side Note: If the folder name of the project is the same as one of the dependencies, it can confuse the resolver. For example, I did my new test project in a folder creatively named "XUnit." This is also the name of a dependency. I got the error: Errors in C:\Users\scott\Desktop\test\xunit\project.json Cycle detected: xunit (>= 1.0.0) -> xunit (>= 2.1.0) -> xunit (>= 2.1.0). Note that 1.0.0 there. That's my project, which is 1.0.0. Solution? Rename my project's containing folder.
There's ASP.NET Core Hello World, which is "dotnet new -t Web." This will give you a nice simple ASP.NET Core app with some simple defaults that's setup for bower, gulp, and npm usage. I anticipate we'll see varying levels of what folks consider "complete."
yo aspnet: dotnet new -t web isn't the only way to make a new ASP.NET Core project from the command line (CLI). You can also use the Yeoman generator or "yo aspnet" to make very interesting projects, as well as create your own generators. In fact, Steve Sanderson has some impressive generators like his "aspnet-spa" generator for making Angular, React, and Knockout Single Page Apps (SPA) with ASP.NET Core.
All these generators work on Windows, Mac, and Linux, of course. I believe the intent is to reconcile them all such that Visual Studio proper and Visual Studio Code via the CLI will all get the same "File | New Project" results. Visual Studio will still be more "visual" but everything you can do in one world can and should be possible in another.
Sponsor: Big thanks to Redgate for sponsoring the feed this week. Have you got SQL fingers? Try SQL Prompt and you’ll be able to write, refactor, and reformat SQL effortlessly in SSMS and Visual Studio. Find out more!
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
So surprising to see the failings of DOS emerge from the very company that made Windows such a successful/great paradigm. Those who fail to learn from history... etc., etc. ...
I think that would be a much better flow than the current "dotnet new" which defaults to a specific project type. I do agree with you, Scott, about your gripe with the -t argument, it doesn't seem necessary.
So my ideal would be that you can do "dotnet new" and get a list of project types you can select, maybe some options (Add Unit tests?) but each one of those options can be picked directly, i.e. "dotnet new aspnet/spa/angular2" or something along those lines. I think that would make the project types a lot more discoverable for new users who probably won't even think about appending additional arguments to "dotnet new".
For instance, can I get a list of available types when I do:
dotnet new --types
If other templates are coming (and maybe the possibility to create your own?), this might be useful to know which templates are available and installed where?
For languages, there are not so many, so I believe they can just remain in the help text 'dotnet new'.
One thing I'd really like to see would be
dotnet newworking with .sln and .xproj/.csproj files. So:
dotnet new solution
would create a
.slnfile in the current directory, and
dotnet new web -n MyWebApp
would create an empty web application with a .xproj file (for now) in a directory called
MyWebAppand add it to the solution.
This would be a huge help to people working on different IDEs/editors/platforms, and especially people working with JetBrains Rider on Mac or Linux, which requires solution and project files and they're not going to change anything about that until the Tools RTM.
I would expect to see something like yeoman when I run "dotnet new" - that might compose a full commandline with all switches needed. I also expect this to be pluggable so others could provide new templates (as now in VS).
I think it would also make sense to allow the user to set a default language in a config file so that if they are primarily a F# or VB user, they don't have to type out the language everytime they are scaffolding a new project (this would be in the same spirit of choosing your default language in VS)
I think prioritization is pretty screwed up that this is where the focus is rather than on exposing this stuff through VS- the tool the majority of your customers use (and one they actually pay for). The tooling in VS always seems to be the last thing you guys update. If it wasn't for Mads Kristensen (a single man, who started Web Essentials on his own, without MS support) web tooling in VS would still suck. Unfortunately for many of us there's no Mads to fix the awful tooling everywhere else non-web in Visual Studio (like SSDT, T4 templates, Entity Framework).
The dotnet cli should be consistent across all commands IMO.
dotnet <command> <command arguments with dashes>
You may think it's intuitive to have the type as the next parameter, but if I were to look at that without knowning better I would have assumed that's what you wanted to name the project. And once you make type the first parameter of new, you can't really change to anything else later on.
Seems better to just not have positional arguments, and just have them all specified with their dash prefix to me.
My opinions anyway.
Why not have "dotnet new -t web" create an empty web application, instead of including everything except the kitchen sink :p An option for the user to set this would be nice as well.
That they would copy node is fine, but copying the mistakes, dropping what is known to work from their own experience is where MS always goes wrong. This happened with Silverlight, as MS copied Adobe verbatim until later version where common sense took over.
Same will happen here, as first they toss .Net developers under the bus, then realize that a better way is to copy what's best of both platforms.
BTW, still waiting for core to work on Ubuntu, and would love to be able to add assemblies directly as references without nuget...
When I see yet another command line, simple killing is not enough.
Typing commands isn't any cool in 2016. Like, what, am I going to develop an ASP.NET Core project via SSH while in mc running mcedit? No, I'm not.
I want .NET on Linux, but not Linux in .NET. God forbid.
Guys, guys, just take a survey why are people choosing .NET rather than some LAMP-junkyard.
+1 for the command line :)
@Shrikant N: I think this will be added in the future, it was mentioned on the .net core cli repo that it will be added in the future.
Who except a handful of vi enthusiasts will actually edit the created files in a command window without intellisense, sytnax highlight, inline error checking and other goodies?
You should rather spend the effort somewhere else.
Re "dotnet new -t lib ... Not so useful, but good to know."
You may not create libraries but in real world developers have a lot because they don't want all files in a single project so they split, even add some to NuGet.
It seems like we could have a middle ground where if '-t' isn't specified, it could be prompted or intelligently look at the number of arguments. For example, 'dotnet new web MyWebProject' which could interpret the number of commands.
Whatever the end goal ends up being, thanks for keeping the discussion alive, Scott!
-- add the nuget package that contains my preferred template to project.json (e.g. Angular 2)
>dotnet add-template angular2
I just created a new .NET core web application in VS 2015 update 3 and in the project.json file I see something like this
Just wondering about the preview2-final stuff. Is the ASP.NET release full and final or still in development? preview2-final seems like incomplete stuff.
+1 for mentioning Steve Sanderson's generators, they are awesome for starting a new AspNet Core application with Angular2 or React. I found them very handy, after some struggle to setup a new Angular2 and AspNet Core project with Angular-CLI.
I am developing a MVC application in Asp.Net core framework. Now I want to deploy this website over raspberry pi or Dragon board 410 C (Window 10 IOT). Is there any other way to deploy it? I don't want to go with DNX. If yes then could you Guide me on that?
Thanks in advance.
Comments are closed.
Scott, a small typo correction if I may: "I wasn't use them" -> "I wasn't using them"
I also agree that syntax such as without any switch or uppercase, is better. That's how things tend to work on the Linux world. Less verbosity; consider CLI as a first class citizen and make it accomplish the most with minimum switches.
I've noticed in RC1 of .NET Core that and Visual Studio's File->New Project... did not yield the same result, so it's good to see that the team works towards unifying them. All platforms need to produce the very same code, or else one might ask "which one is the best?"