Exploring the new .NET "dotnet" Command Line Interface (CLI)
I've never much liked the whole "dnvm" and "dnu" and "dnx" command line stuff in the new ASP.NET 5 beta bits. There's reasons for each to exist and they were and they have been important steps, both organizationally and as aids to the learning process.
My thinking has always been that when a new person sits down to learn node, python, ruby, golang, whatever, for the most part their experience is something like this. It should be just as easy - or easier - to use .NET.
This is just a psuedocode. Don't sweat it too much.
apt-get install mylang #where mylang is some language/runtime
#write or generate a foo.fb hello world program
mylang foo #compiles and runs foo
I think folks using and learning .NET should have the same experience as with Go or Ruby.
- Easy To Get - Getting .NET should be super easy on every platform.
- We are starting to do this with http://get.asp.net and we'll have the same for .NET Core alone, I'm sure.
- Easy Hello World - It should be easy to create a basic app and build from there.
- You can "dotnet new" and get hello world. Perhaps more someday?
- Easy Compile and Run
- Just "dotnet run" and it compiles AND executes
- Real .NET
- Fast, scalable, native speed when possible, reliable
I've been exploring the (very early but promising) work at https://github.com/dotnet/cli that will ship next year sometime.
IMPORTANT NOTE: This toolchain is [today] independent from the DNX-based .NET Core + ASP.NET 5 RC bits. If you are looking for .NET Core + ASP.NET 5 RC bits, you can find instructions on the http://get.asp.net/.
Once I installed the "dotnet" cli, I can do this:
>dotnet new
>dotnet restore
>dotnet run
Imagine with me, when you combine this with the free Visual Studio Code editor which runs on Mac, Windows, and Linux, you've got a pretty interesting story. Open Source .NET that runs everywhere, easily.
Here is a longer command line prompt that includes me just typing "dotnet" at the top to get a sense of what's available.
C:\Users\Scott\Desktop\fabulous>dotnet
.NET Command Line Interface
Usage: dotnet [common-options] [command] [arguments]
Arguments:
[command] The command to execute
[arguments] Arguments to pass to the command
Common Options (passed before the command):
-v|--verbose Enable verbose output
Common Commands:
new Initialize a basic .NET project
restore Restore dependencies specified in the .NET project
compile Compiles a .NET project
publish Publishes a .NET project for deployment (including the runtime)
run Compiles and immediately executes a .NET project
repl Launch an interactive session (read, eval, print, loop)
pack Creates a NuGet package
C:\Users\Scott\Desktop\fabulous>dotnet new
Created new project in C:\Users\Scott\Desktop\fabulous.
C:\Users\Scott\Desktop\fabulous>dotnet restore
Microsoft .NET Development Utility CoreClr-x64-1.0.0-rc1-16231
CACHE https://www.myget.org/F/dotnet-core/api/v3/index.json
CACHE https://api.nuget.org/v3/index.json
Restoring packages for C:\Users\Scott\Desktop\fabulous\project.json
Writing lock file C:\Users\Scott\Desktop\fabulous\project.lock.json
Restore complete, 947ms elapsed
NuGet Config files used:
C:\Users\Scott\AppData\Roaming\NuGet\nuget.config
C:\Users\Scott\Desktop\nuget.config
C:\Users\Scott\Desktop\fabulous\nuget.config
Feeds used:
https://www.myget.org/F/dotnet-core/api/v3/flatcontainer/
https://api.nuget.org/v3-flatcontainer/
C:\Users\Scott\Desktop\fabulous>dotnet run
Hello World!
Note that I ran dotnet restore once before on another projects so that output was not very noisy this time.
Native Compilation of .NET applications
This is cool, but things get REALLY compelling when we consider native compilation. That literally means our EXE becomes a native executable on a platform that doesn't require any external dependencies. No .NET. It just runs and it runs fast.
It's early days, and right now per the repro it's just hello world and a few samples but essentially when you do "dotnet compile" you get this, right, but it requires the .NET Core Runtime and all the supporting libraries. It JITs when it runs like the .NET you know and love.
But if you "dotnet compile --native" you run it through the .NET Native chain and a larger EXE pops out. But that EXE is singular and native and just runs.
Again, early days, but hugely exciting. Here's the high-level engineering plan on GitHub that you can explore.
Related Projects
There are many .NET related projects on GitHub.
- The .NET home repo links to 100s of .NET projects, from Microsoft and the community.
- The .NET Core repo links to .NET Core related projects from Microsoft.
- The ASP.NET home repo is the best place to start learning about ASP.NET 5.
- http://dotnet.github.io is a good place to discover .NET Foundation projects.
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 with a 28 day free trial!
About Scott
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.
About Newsletter
It might be for windows devs though ;) It's a bit about understanding what you're actually doing:
1) With an interpreted language like python you have to specify the interpreter and give it the file you want to run.
2) With a language that compiles to intermediate language that is interpreted (.NET/C#, Java) you have to compile first and then basically go the route of 1). On windows with a PE trick this isn't visible, but it's still done under the hood.
3) With a language that compiles to native, you simply run the compiler and you get an executable.
It's cool that for .NET on linux/mac there's a way to combine 1 and 2, like we've known for years on Windows. Perhaps it's my C/vi roots but I don't find it a big disadvantage to first compile and then run. I mean, in practice you either use an IDE or build environment anyway later on which builds and runs your stuff.
The .NET native initiative is interesting. From the filesize of a hello world app is it safe to conclude that the native compiled executable contains the IL and a CLR? It's otherwise a pretty complex task to accomplish without running the IL up front: only then the compiler knows which external libs are used and thus which calls it has to statically link into the executable. Which looks like a halting-problem (as the app might never end). Of course, without reflection (of any kind) it's simpler, and with a native compiled BCL (for e.g. linux or mac) it will be easier. Will be interesting to see where they end up though, and I mean: for windows. Windows is still a major desktop environment and it would be great if winforms/wpf apps can be compiled to native (not ngenned) so they run much faster.
New version of .NET is coming with a lot of changes/enhancements and more closed to Open source world.
Following ASP.NET 5 and see drastic changes in MVC project structure. Though it looks uncomfortable initially however later on I realized, it is for better.
Can you say whether or not the switch from dnx, etc. to dotnet will happen before ASP 5 is released?
Any chance it will happen by RC2, which I believe Damian said will likely be in February?
Thanks,
jeffa
Everything old is new again!
Thanks for posting, Scott.
Most people who mention the Halting Problem have no understanding of it, and this is an example.
The (not a) Halting Problem is posed thus: Write a program (called HALTS) that, given two inputs, the encoding of a program (P) and a specific input (I)for that program, can always determine whether P halts when given I as input. There's a simple proof by contradiction that no such program HALTS can exist.
That's the Halting Problem, and it has nothing to do with the issues here, or any other practical programming problem.
Looks like the plan is to switch to the dotnet cli in the February RC2 release.
Bonus points for a commercial software company quality and professionally supported managed language (c#) on non-windows platform. Much better than roll the dice and basing a $1 million+ new development project on the popular open source language of the year which is highly likely to be near dead and largely unsupported in 5 years. 4 to 5 paid maintainers, a few bug fixes each year, and a loose selection of random blog posts every few months is not a basis for making a sound long-term million dollar business decision.
Right now I've been fighting with trying to develop using the relatively latest bits and still haven't been able to successfully build against ARM so that I can deploy and app to the RaspPi.
Anyway, have a nice day! :)
So is http://dotnet.github.io/docs/ going to co-exist https://docs.asp.net ?
It's hard to know where to get up to speed with the new shiny .net these days
I have no idea what to use and when. I'm lost and I'm confused.
There's one node (well, yeah I know) and there's one npm. It's not only simple, it's easy. With .NET I've not only got all the ASP.NET 5 stuff to contend with, I've also got this new dotnet CLI. Combine that with different compilers, frameworks and Nuget and you've got yourself a rubix cube. I know they can be solved in seconds but you what? 30 years on this planet and I haven't solved one, ever.
Oh and types hidden in Nuget packages making core CLR use really hard. Kill me!
Please Scott bash whatever heads you need to bash to make this simpler. It also needs to be explained properly. Venturing into open multi platform tooling is fantastic. It rocks and you and the rest of the open MS people deserve great props, but let's do it in a way that doesn't scare the living daylights out of people!
Or it's just me! Haha. Rant complete!
Scott,
Good to see good information about .NET.
I've been using .NET to build a Web site I
hope will be successful. So, the site has
a Web server, a session state server, an
instance of SQL Server, and two more
servers with unique functionality. The
code appears to be read for deployment for
a Web site live on the Internet.
I wrote the code in Visual Basic .NET with
the .NET Framework 4.0.
The total code is 18,000 programming
language statements in 80,000 lines of
text. Yup, I typed it all into my
favorite general purpose text editor using
just my fingers.
The parts of the work unique to my Web
site were all fast, fun, and easy. By a
wide margin, the most difficult part of
the work was getting needed, standard,
common, basic information about .NET.
That difficulty nearly sank the project
and still may.
Here I can give some illustrations of such
difficulties from your post:
> I've never much liked the whole "dnvm"
and "dnu" and "dnx" command line stuff
Easy to understand why: I never heard of
"dnvm" "dnu" "dnx" either and, thus, have
no idea what they are about. Does "dn"
abbreviate "domain name", "down", "darn",
something else?
I saw
>dotnet new
>dotnet restore
>dotnet run
And then what? The "new" means
a "new" what?
Okay, below is some text from a command
line program dotnet with
> restore -- Restore dependencies
> specified in the .NET project
What constitutes a ".NET project"?
What are "dependencies"?
Here the definition for "restore" starts
with "restore".
"Restore" in what sense?
Where on my computer is the "project", and
where are the "dependencies".
> publish -- Publishes a .NET project for
> deployment (including the runtime)
Here used "publishes" to define "publish".
"Publish" in what sense, where, for what
reason?
> repl -- Launch an interactive session (read,
> eval, print, loop)
What does "repl" abbreviate? It's a
misspelling of "reptile"?
What does "launch" mean? We're playing
with paper airplanes here? Rockets?
"Eval" abbreviates what with what meaning?
> pack -- Creates a NuGet package
What is a "NuGet package" -- some candy in
a box?
To me, no exaggeration, by far the biggest
problem of the Microsoft company is
providing information needed, as in a
famous statement by Steve Ballmer, by
"Developers,
Developers,
Developers"
and the biggest problem there is the
quality of the technical writing, and the
biggest problem there is poorly defined,
undefined, and poorly explained
terminology and concepts.
No joke.
> Note that I ran dotnet restore once
before on another projects so that output
was not very noisy this time.
"Noisy"? You lost me. Typically a
computer has a way to lower the volume of
the sound coming out of the speakers.
> This is cool, but things get REALLY
compelling when we consider native
compilation.
What the heck do you mean by "native"? In
those 18,000 programming language
statements I wrote, I never encountered
"native".
> It's early days, and right now per the repro
What's a "repro"?
> .NET Core Runtime
I have 5000+ Web pages of documentation on
.NET, nearly all from the Microsoft Web
site MSDN, and on my computer have the
pages stored, indexed, and abstracted.
I've read all the pages.
Nowhere did I encounter anything called
the ".NET core".
What do you mean by "core"?
> the .NET Native chain
What the heck is that? Never heard of it
before. I can't even guess at the meaning
of either "native" or "chain".
> But that EXE is singular and native and
just runs.
In this context, what does "singular"
mean? I've never heard of this word in
computing before.
I hope that this post help Microsoft solve
one of the biggest problems for itself and
developers, e.g., me.
dotnet compile --nativeand then examine the resulting executable with
readelf -d ..filename..I get a long list of libraries needed, even with the sample Hello World code.
Is there an option to get a fully statically linked application?
The 'run' option it fact means C# can be used as a scripting language to perform tasks which you might have used python or ruby for in the past.
could not load file or assembly Microsoft.Extensions.FileSystemGlobbing or one of its dependencies.
I installed dotnet via the msi, and used dotnet new to create a project.
dotnet restore appeared to work correctly.
What might be causing this issue on a 64-bit Windows 10 computer, fully patched through and including Microsoft "January 2016 Patch Tuesday" ?
1. Can I build ASP.NET Core web application using Microsoft Dotnet CLI or only console?
2. Is Dotnet CLI replacement of DNVM, DNU & DNX or just an alternative ?
Comments are closed.
We currently operate on Win and Linux servers via mono using NFX (alternative .NET stack altogether). Cant wait to https://github.com/aumcode/nfx switch to Linux as our primary platform.