Trying out "dotnet new" template updates and csproj with VS2017
I updated my Visual Studio 2017 RC installation today. Here's the release notes. You just run "Visual Studio Installer" if you've already got a version installed and it updates. The updating processes reminds me a little of how Office 365 updates itself. It's not as scary as VS updates of the past. You can download the VS2017 RC at https://www.visualstudio.com and it works side by side with your existing installs. I haven't had any issues yet.
It also added/updated a new .NET Core SDK. I am a fan of the command line "dotnet.exe" tooling and I've been pushing for improvements in that experience. A bunch of stuff landed in this update that I've been waiting for. Here's dotnet new:
C:\Users\scott\Desktop\poop> dotnet new
Template Instantiation Commands for .NET Core CLI.
Usage: dotnet new [arguments] [options]
Arguments:
template The template to instantiate.
Options:
-l|--list List templates containing the specified name.
-lang|--language Specifies the language of the template to create
-n|--name The name for the output being created. If no name is specified, the name of the current directory is used.
-o|--output Location to place the generated output.
-h|--help Displays help for this command.
-all|--show-all Shows all templates
Templates Short Name Language Tags
--------------------------------------------------------------------------------------
Console Application console [C#], F# Common/Console
Class library classlib [C#], F# Common/Library
Unit Test Project mstest [C#], F# Test/MSTest
xUnit Test Project xunit [C#], F# Test/xUnit
Empty ASP.NET Core Web Application web [C#] Web/Empty
MVC ASP.NET Core Web Application mvc [C#], F# Web/MVC
Web API ASP.NET Core Web Application webapi [C#] Web/WebAPI
Solution File sln Solution
Examples:
dotnet new mvc --auth None --framework netcoreapp1.0
dotnet new console --framework netcoreapp1.0
dotnet new --help
There is a whole new templating engine now. The code is here https://github.com/dotnet/templating and you can read about how to make your own templates or on the wiki.
I did a "dotnet new xunit" and it made the csproj file and a Unit Test. Here's what's inside the csproj:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.0</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0-preview-20170123-02" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0-beta5-build1225" /> </ItemGroup> </Project>
That's not too bad. Here's a a library with no references:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netstandard1.4</TargetFramework> </PropertyGroup> </Project>
Note there's no GUIDs in the csproj. Sweet.
Remember also that there was talk that you wouldn't have to edit your csproj manually? Check this out:
C:\Users\scott\Desktop\poop\lib> dotnet add package Newtonsoft.Json
Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.
Writing C:\Users\scott\AppData\Local\Temp\tmpBA1D.tmp
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.
log : Restoring packages for C:\Users\scott\Desktop\poop\lib\lib.csproj...
info : GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json
info : OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/index.json 1209ms
info : GET https://api.nuget.org/v3-flatcontainer/newtonsoft.json/9.0.1/newtonsoft.json.9.0.1.nupkg
info : OK https://api.nuget.org/v3-flatcontainer/newtonsoft.json/9.0.1/newtonsoft.json.9.0.1.nupkg 181ms
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.
info : PackageReference for package 'Newtonsoft.Json' version '9.0.1' added to file 'C:\Users\scott\Desktop\poop\lib\lib.csproj'.
Doing "dotnet add package foo.bar" automatically gets the package from NuGet and adds it to your csproj. Just like doing "Add NuGet Package" (or add reference) in Visual Studio. You don't even have to open or look at your csproj.
I'm going to keep digging into this. We're getting into a nice place where someone could easily make a custom template then "nuget in" that templates then "File | New | Your Company's Template" without needed yeoman, etc.
Please shared your feedback:
- For general feedback, please contact us at dotnet@microsoft.com or at @dotnet.
- For template users and authors, feel free to contact Sayed directly at sayedha@microsoft.com at @SayedIHashimi
Also, be sure to check out the new and growing Docs site at https://docs.microsoft.com/en-us/dotnet.
Sponsor: Track every change to your database. See who made changes, what they did, & why, with SQL Source Control. Get a full version history in your source control system. See how with Red Gate's SQL Source Control.
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
Is any one writing the code of their application at the command line? So what does being able to create a new project at the command line really get you? After all you'll have VS open in order to write the code so his remembering a ton of args really worth it for something that in all likelihood you'll do a lot less often than right code. If you are creating tutorials and things like that may be you'll use it a lot but if you are working on an app or product for your employer not so much.
Can't wait for 2017 to be finished :)
@Peter 'dotnet new' is not just the CLI, it's a whole new templating engine which will be used by Visual Studio, VS Code, 'dotnet new', etc. to create new projects. It adds support for optional features in a template which you can turn on or off! In general, the command line is great for CI build machines or for doing something very quickly or repeatedly. 'dotnet new' will make it easy for someone to copy the way you created a project from a template if you were writing a blog post for example.
The line below shows how optional features work and is the coolest feature of 'dotnet new' in my opinion. For anyone intrerested, I'm working on MVC templates, you can read more here.
dotnet new mvc --auth None --framework netcoreapp1.0
On a side note, it'd be nice if the dotnet command didn't have major changes in every release candidate. Release candidates usually mean major changes no longer happen.
Why there aren any "Go To View" or "Create View" when you right click on action method in brand new VS2015 and VS2017? Do we have to create or find the view from Solution Explorer all the time?
This sounds great, many times I have had to create a new project that was based off a style and structure set out by the company. Sometimes we would just copy and paste then refactor to rename things. With these new templates we could just script the whole thing passing in parameters. Great stuff, thanks Scott.
I have one question and/or concern; you created new xnunit project with CLI tools, and it added some "visualstudio" runner package also. Why its adding anything IDE specific in this brave new cross platform world, with other IDEs like Code and Rider? I would vote against that ...
Cheers
Thanks for a nice post as usual.
Did you try to deploy a project created by a new tooling to the azure appservice? When I am trying to do a usual git deploy approach I just receive an error that named csproj file is not deployable project and that is it.
Any idea how to fix this?
C:\Users\scott\Desktop\poop> dotnet new
LOL I do the same thing when trying things out ;-)
/gettingOldRant
How exactly do I upgrade my installed version? I don't see a Visual Studio Installer on my system. What gives?
Thank you, Scott.
dotnet new sln -n mysolution
dotnet new classlib -n mylib
dotnet sln add mylib/mylib.csproj
Try dotnet sln --help for more information.
Tested with version 1.0.0-rc4-004771
Truth is that the first 3 RC's from the visual studio department are not really RC. These are beta.
Stop using it! Save time. Wait until the release + next update. Safe your self a headache.
@Abel: Complete reinstall.
@Sayed: Kudos! but its just a matter of time MS going to drop it. Just like Dynamic Data etc etc.
Still on VS2015 which is not bad !
2. If the [arguments] for dotnet new is always the template name, why not call it [template name] instead?
3. For xunit the target framework is netcoreapp1.0, but for a library it's netstandard1.4... what?! I probably need to educate myself on the difference, but as a first impression, it raises eyebrows.
Otherwise it looks good. I would have liked something more descriptive than ItemGroup/PropertyGroup, but if I suppose we'll have to hold our noses. Being able to modify the file from the command line helps.
Does VS2017 RC co-exists nicely with VS2015, or should I continue to running it in a VM?
What's wrong with GUIDs as well?
"I look forward to the new template system if its easier to create templates. I have been playing with the original vstemplate system for the last month or so and find there are some gotchas, and not so good docs."
Yes, creating templates with the Template Engine is very easy. Much easier than using .vstemplate.
"I think I may have seen some talk about the new templates under the ligershark github org, when searching for old template stuff."
Yes. I'm the owner of SideWaffle (existing popular template pack in LigerShark repo). We (SideWaffle) will be migrating to this new template engine for new templates. I'm working with my team (at Microsoft) on enabling invoking the Template Engine from Visual Studio. When we do that you can author a template and light it up in the command line with dotnet new and VS with a custom wizard in a .vstemplate.
Comments are closed.